Overview: Gamerules

The intent of this article is to describe both how gamerules used to work in the Homeworld 2 paradigm and how they currently work in Homeworld Remastered. If you spot any inaccuracies, omissions, typos, or out of date info feel free to contact me, Siber/EatThePath, about it, or as this is on a wiki edit it yourself to correct it. Letting me know is still preferred so I can verify and also learn myself, but the option is there.

## How it used to work

.lua files in the data/leveldata/multiplayer folder were executed as gamerules. The following contents were expected...

* Directories: Table, paths to load levels from
	+ Directories.Levels: String, the path for core directory for levels bundled in the mod
	+ Directories.ProfileLevels: String, the user profile directory to load more levels from

* GameRulesName: String, the name to display for the gametype

* Description: String, mouseover description of gametype

* GameSetupOptions: Table, options for user to configure, details omitted in favor of example

```
GameSetupOptions = {
	{	name = "resources",
		locName = "$3240",
		tooltip = "$3239",
		default = 1,
		visible = 1,
		choices = { "$3241", "0.5", "$3242", "1.0", "$3243", "2.0", },
	},
	{	name = "unitcaps",
		locName = "$3214",
		tooltip = "$3234",
		default = 1,
		visible = 1,
		choices = { "$3215", "Small", "$3216", "Normal", "$3217", "Large", },
	},
	{ 	name = "resstart",
		locName = "$3205",
		tooltip = "$3232",
		default = 0,
		visible = 1,
		choices = { "$3206", "1000", "$3207", "3000", "$3208", "10000", "$3209", "0", },
	},
}

```

* OnInit(): Function, executed at game start to kick off the actual logic of the rule.

* Events: Table, typically handles at least some espect of the game ending. Example:

```
Events = {
	endGame = {
		{
			{"wID = Wait_Start(5)", "Wait_End(wID)",},
		},
	},
}

```

Any other lua would be executed as normal as well, allowing dofilepath to bring in other logic and so forth. Rule\_Add, Rule\_AddInterval, and Rule\_Exists are typically used in OnInit to start the periodic evaluation of other functions listed in the file or in other files referenced through dofile or one of it's variants.

https://hwmod.fandom.com/wiki/HWR\_Function\_Reference is a good place to look for information when this wiki is lacking

## How it works now

Gamerule scripts are now located in data/scripts/rules/. name.lua files are executed as the initial information, with some additional information provided in files in data/scripts/rules/name/. Rules are similar in structure to how they used to be, with some notable changes listed below.

* GUID: Table of integers, I have no idea what this does.
* SaveGameVersion: Float, I'm guessing this is to allow backwards-compatability checks for save files, but that's only a guess.
* SingePlayer: Int, guessing this is a boolean value in disguise to flag rules that are only meant to back singleplayer levels so they won't be loaded and displayed in the multiplayer dropdown.
* ExtFilter: String, the filtering tags for the gamemode. Some day there should be an Overview: Filtering article, but for now see http://forums.gearboxsoftware.com/t/mod-filtering-just-say-no-to-hacked-files/539459 for information and discussion
* Race\_Paths: String, the path for overides stored in race directories. I am uncertain on this point, would appreciate confirmation.
* Level\_Pass\_Tags: String, the tags that will cause a level to be available for play, see ExtFilter line for information about filtering.
* Level\_Fail\_Tags: String, the tags that will cause a level to not be available for play, see ExtFilter line for information about filtering.
* Race\_Pass\_Tags: String, the tags that will cause a faction to be available for play, see ExtFilter line for information about filtering.
* Race\_Fail\_Tags: String, the tags that will cause a faction to not be available for play, see ExtFilter line for information about filtering.

Otherwise it appears things function as they did before, with the exception of unitcaps. Include unitcaps files in data/scripts/rules/name/unitcaps/. At present, that seems to be the whole deal.