Homeworld 2 continues the epic struggle of the Hiigarans and their leader Karan S'jet. Many thought their hardships would end when they returned to Hiigara, yet fate has not been so kind to the Exiles. Now the Hiigarans face a new and bitter enemy, a renegade clan from the eastern fringes of the galaxy, who wield the power of the ancients. Homeworld 2 chronicles the valiant journey of the Mothership and its crew into the oldest regions of the galaxy to confront their new foe and discover the truth behind their exile.

Report article Enable AI to Build New Ships

Okay, so you have a new race, or you've added a new ship into Homeworld 2. That's great and all, but your computer, no matter how good, doesn't know what to do with it. I will show you how to make your computer make sense of you new ship(s)

Posted by Mr.Grim on Jul 26th, 2006 digg this super bookmark
Intermediate Client Side Coding.


[page=Introduction]
Okay, so you have a new race, or you've added a new ship into Homeworld 2. That's great and all, but your computer, no matter how good, doesn't know what to do with it. I will show you how to make your computer make sense of you new ship(s).
[page=The ClassDef.lua File]
Before you can tell the AI to build the ship, you have to tell it what kind of ship it is. But this tutorial, I will show you two examples, a new race from my mod, the Progenitor, and to add a new ship, the "Bishop" Crew Transport (from the single-player mission). This is so you know how to add a new race to the listing.

Now, in you Data folder, add a new folder, name it "AI". This will contain all the AI needed files (but I'm sure you already knew that). Now, make sure to use the file given in the RND pack, this is because LuaDC does not properly de-compile the AI files (I have no idea why). Now, if you see, that is more-or-less a list of all the games ships. Now to add those ships. First, add the new Mothership for the Progenitor, Sajuuk. This is how it originally looked:

  1. code:
  1. squadclass[eMotherShip] = {
  2.   HGN_MOTHERSHIP,
  3.  
  4.   VGR_MOTHERSHIP,
  5.   VGR_MOTHERSHIP_MAKAAN,
  6. }
  7.  

I'm not sure of this, but you have to add the new ships in a specific order, and way (correct me if I am wrong). Now, under VGR_MOTHERSHIP_MAKAAN, we'll add Sajuuk. It should now be:

  1. code:
  1. squadclass[eMotherShip] = {
  2.   HGN_MOTHERSHIP,
  3.  
  4.   VGR_MOTHERSHIP,
  5.   VGR_MOTHERSHIP_MAKAAN,
  6.  
  7.   KPR_SAJUUK,
  8. }
  9.  

Hopefully you understand what need to be done. Now each "table" has a purpose, this first one was to define the Mothership. Now to add the Crew Transport. We'll define it as a Capital class ship.

  1. code:
  1. squadclass[eCapital] = {
  2.   HGN_TANKER,
  3.   HGN_CARRIER,
  4.   HGN_MOTHERSHIP,
  5.   HGN_SHIPYARD,
  6.   HGN_DESTROYER,
  7.   HGN_BATTLECRUISER,
  8.   HGN_DREADNAUGHT,
  9.  
  10.   VGR_CARRIER,
  11.   VGR_MOTHERSHIP,
  12.   VGR_MOTHERSHIP_MAKAAN,
  13.   VGR_SHIPYARD,
  14.   VGR_DESTROYER,
  15.   VGR_BATTLECRUISER,
  16. }
  17.  

Now remember, it does matter whether or not you use uppercase and lowercase letters.

Now add all of your new ships to their appropriate place.
[page=The CPUBuild.lua File]
Okay, so the AI knows what?s what, but yet it doesn't know...what?s what? Well, it know what it's good for, it doesn't know whether or not it's something it needs to build, or something like that. It's time to go to the CPUBuild.lua file. It's fairly easy. If you?re just adding a new ship and isn't replacing and existing ship listed here (such as a replacement carrier, destroyer, etc.). If you?re adding a new race, everything changes. This is what my CPUBuild.lua file looks like, with the Progenitor added in (not the whole file, just the top section)

  1. code:
  1. function CreateBuildDefinitions()
  2.   if (s_race == Race_Hiigaran) then
  3.  
  4.     kCollector = HGN_RESOURCECOLLECTOR
  5.     kRefinery  = HGN_RESOURCECONTROLLER
  6.     kScout = HGN_SCOUT
  7.     kInterceptor = HGN_INTERCEPTOR
  8.     kBomber = HGN_ATTACKBOMBER
  9.     kCarrier = HGN_CARRIER
  10.     kShipYard = HGN_SHIPYARD
  11.     kDestroyer = HGN_DESTROYER
  12.     kBattleCruiser = HGN_BATTLECRUISER
  13.    
  14.   elseif (s_race == Race_Vaygr) then
  15.  
  16.     kCollector = VGR_RESOURCECOLLECTOR
  17.     kRefinery  = VGR_RESOURCECONTROLLER
  18.     kScout = VGR_SCOUT
  19.     kInterceptor = VGR_INTERCEPTOR
  20.     kBomber = VGR_BOMBER
  21.     kCarrier = VGR_CARRIER
  22.     kShipYard = VGR_SHIPYARD
  23.     kDestroyer = VGR_DESTROYER
  24.     kBattleCruiser = VGR_BATTLECRUISER
  25.  
  26.   else
  27.  
  28.     kCollector = KPR_MOVER
  29.     kRefinery  = KPR_KEEPER
  30.     kScout = KPR_ATTACKDROID
  31.     kInterceptor = KPR_ATTACKDROID
  32.     kBomber = KPR_MOVER
  33.     kCarrier = KPR_KEEPER
  34.     kShipYard = KPR_SAJUUK
  35.     kDestroyer = KPR_KEEPER
  36.     kBattleCruiser = KPR_DREADNAUGHT
  37.    
  38.   end
  39.  
  40. end
  41.  

If you just look it over, I think you can understand what needs to be done. Just replace all the Progenitor ships, with your own, just make sure what you add in makes sense for what it's defined as (unless you don't have a ship that fits in, just add anything.)
[page=Hints and Tips]
Okay, that's all I know of AI scripting, I am trying to get the research enabled for the AI, but I've still to learn and debug the files. Instead, here are some things you should keep in mind.

Look for existing patterns
When adding in a new ship, try to add it in a way similar to that of what is already their. It will help ensure that it works.

Check for typos
This is the most important thing to remember, a single extra or missing letter, comma, or bracket can make the whole file useless. It has caused me so much trouble at times. It can save you allot of trouble to do it right the first time, even if it takes a little extra time or work.

If you?re stuck, ask for help
It's as simple as that, their are plenty of forums out their who can help. A great place to ask is at Relicnews Forums, a great community of Relic games and their mods.

Other Homeworld tutorials by me
Make sure to check out my Setting up a New Race tutorial. Their are more to come. :)

Comments
Sigma
Sigma Jul 27 2006, 8:21am says:

never modded HW2 (dont even have it) but it looks like a good reference for newbies :)

+2 votes     reply to comment
Mr.Grim
Mr.Grim Jul 27 2006, 2:07pm says:

Yep, that what I'm going to try to do, make an ultimate newb guide to HW2. (Not one tutorial, a whole collection of them ;) )

+1 vote     reply to comment
Post a Comment

Only registered members can share their thoughts. So come on! Join the community today (totally free) and do things you never thought possible.

Icon
Homeworld 2
Platforms
PC, Mac
Engine
Custom Built
Contact
Send Message
Official Page
Homeworld2.sierra.com
Release Date
Released Sep 16, 2003
Game Watch
Track this game
Bookmark
Digg Super bookmark
Tutorial
Browse
Tutorials
Report Abuse
Report article
Bookmark
Digg Super bookmark
Related Games
Homeworld 2
Homeworld 2
Single & Multiplayer Real Time Strategy