Creating a new unit - UberWaffe/OpenRA GitHub Wiki

This guide was created 2013-09-06 and works for the 2013-0902 release.

This guide will be a in depth guide on how to create a new unit. It will be in two parts, the first part (the simple part) will explain how to clone a unit, this is good in the way that you do not have to modify the sequences files at all. The second part (the not so simple way) will explain how to create a new unit from scratch. The guide was done for mods based on Red Alert, but should work well with both c&c and d2k.

Cloning a unit (The simple way)

First we need to decide to clone a unit, for this example we will create a missile submarine for the allies based on real life OHIO-class Ballistic Submarine. First of all lets take a look at the code in parts. Lets open the rules/ships.yaml file now, and search for MSUB. Copy the whole code text and post it at the bottom of the ships.yaml file. Scroll up to the start of your new code and lets get to editing it.

	MSUB:
		Inherits: ^Ship
		Buildable:
			Queue: Ship
			BuildPaletteOrder: 60
			Prerequisites: spen,stek
			Owner: soviet
			Hotkey: m
		Valued:
			Cost: 2400
		Tooltip:
			Name: Missile Submarine
			Description: Submerged anti-ground unit armed with \nlong-range ballistic missiles.\n  Strong vs Buildings\n  Weak vs Everything\n  Special Ability: Submerge

There we go, Now to edit the code. This is what it everything does

  • MSUB = Code name for unit
  • Inherits = what am i? (i.ex ^Ship. Do not change this when we clone units)
  • Buildable = the unit is buildable.
  • Queue = What tab is this unit in? (i.ex. the ship/boat tab)
  • BuildPaletteOrder = Where is the icon in the gridview? Lower number = Top-Left, Higher number = Bottom Right. (If unsure, do not change)
  • Prerequisites = What building do i need to build this unit? (check buildings.yaml for code name.)
  • Owner = What faction do i belong to?
  • Hotkey = What hotkey is used to build me?
  • Valued = How much do i cost?
  • Tooltip / Name = Name of unit.
  • Tooltip / Description = Detailed information about the unit.

Our code should be changed to this

	OHIOSUB:
		Inherits: ^Ship
		Buildable:
			Queue: Ship
			BuildPaletteOrder: 60
			Prerequisites: syrd,atek
			Owner: allies
			Hotkey: m
		Valued:
			Cost: 2400
		Tooltip:
			Name: 'Ohio'-Class Ballistic Sub
			Description: Submerged anti-ground unit armed with \nlong-range ballistic missiles.\n  Strong vs Buildings\n  Weak vs Everything\n  Special Ability: Submerge

What did we do? We changed the codename for the unit, made the prerequisites so instead of the soviet tech center and subpen, we need the allied tech center and the naval yard. The unit now belongs to the allies. And we changed the in-game name to a very detailed one.

Lets head on to the next step, shall we.

		Health:
			HP: 400
		Armor:
			Type: Light
		Mobile:
			ROT: 3
			Speed: 3
		RevealsShroud:
			Range: 6
		RenderUnit:
  • Health / HP = How much health do I have?
  • Armor / Type = What type of armor do I have? (None, Wood, Light, Heavy, Concrete)
  • Mobile / ROT = How fast do I rotate?
  • Mobile / Speed = How fast am I?
  • RevealsShroud = How far can I see?

We aren't going to change anything here, but now you got some basic understanding of what every parameter does.

		-TargetableUnit:
		TargetableSubmarine:
			TargetTypes: Ground, Water
			CloakedTargetTypes: Underwater
		Cloak:
			InitialDelay: 0
			CloakDelay: 100
			CloakSound: subshow1.aud
			UncloakSound: subshow1.aud
		Armament:
			Weapon: SubMissile
			LocalOffset: 0,-171,0, 0,171,0
			FireDelay: 2
		AttackFrontal:
  • -TargetableUnit: = I am not targetable (the - before trait stands for trait removal)
  • TargetableSubmarine / TargetTypes: = What can i attack?
  • CloakedTargetTypes = This is a property of the TargetableSubmarine trait.
  • Cloak / Initial Delay = How fast do i cloak when i'm built/get claok in a crate? (In ticks) (0 = Comes out of factory cloaked)
  • Cloak / CloakDelay = How fast do i cloak? (In ticks)
  • CloakSound = Sound to use when i cloak (put custom files in bits folder)
  • UncloakSound = Sound to use when i uncloak (put custom files in bits folder)
  • Armament = I am armed.
  • Weapon = What weapon do i use?
  • LocalOffset = Where do i fire from?
  • FireDelay = How long i take before i fire again.
  • AttackFrontal = I do not have a turret so i attack from the front (point to target)

Again, lets not change anything here.

		Selectable:
			Bounds: 44,44
		Chronoshiftable:
		IronCurtainable:
		RepairableNear:
		-DetectCloaked:
		AutoTarget:
			InitialStance: HoldFire
		AttackMove:
  • Selectable = I am selectable
  • Bounds = How big is my selection box?
  • Chronoshiftable = Allies can chronoshift me.
  • IronCurtainable = Soviet can Ironcurtain me.
  • RepairableNear = I am repairable.
  • -DetectCloaked = I can't detect cloaked/submerged units (the - before trait stands for trait removal)
  • AutoTarget = Do i auto pick targets?
  • InitialStance = What is my standard stance (Hold Fire)
  • AttackMove = Can i attack move

That's it for our code. The final code should look like this:

	OHIOSUB:
		Inherits: ^Ship
		Buildable:
			Queue: Ship
			BuildPaletteOrder: 60
			Prerequisites: syrd,atek
			Owner: allies
			Hotkey: m
		Valued:
			Cost: 2400
		Tooltip:
			Name: 'Ohio'-Class Ballistic Sub
			Description: Submerged anti-ground unit armed with \nlong-range ballistic missiles.\n  Strong vs Buildings\n  Weak vs Everything\n  Special Ability: Submerge
		Health:
			HP: 400
		Armor:
			Type: Light
		Mobile:
			ROT: 3
			Speed: 3
		RevealsShroud:
			Range: 6
		RenderUnit:
			Image: MSUB
		-TargetableUnit:
		TargetableSubmarine:
			TargetTypes: Ground, Water
			CloakedTargetTypes: Underwater
		Cloak:
			InitialDelay: 0
			CloakDelay: 100
			CloakSound: subshow1.aud
			UncloakSound: subshow1.aud
		Armament:
			Weapon: SubMissile
			LocalOffset: 0,-171,0, 0,171,0
			FireDelay: 2
		AttackFrontal:
		Selectable:
			Bounds: 44,44
		Chronoshiftable:
		IronCurtainable:
		RepairableNear:
		-DetectCloaked:
		AutoTarget:
			InitialStance: HoldFire
		AttackMove:

Do note, that I've added this line in the above code:

		RenderUnit:
			Image: MSUB

Because we do not want to edit the sequence file we use this line of code to mimic (clone) the Missile Sub. The above code will work and add a ballistic submarine for allies, now there are alot of code that the sub does not use (and cannot use) but there are some codes we can use. For example.

If we remove the -DetectCloaked: and replace it with this:

		DetectCloaked:
			Range: 4
		RenderDetectionCircle:

The unit will be able to detect cloaked/submerge units and you will also see a circle ingame (Detection Circle). Or why not add this to the bottom of our code.

		RenderRangeCircle:

This will add a range circle around your unit so you know exactly how far your unit can fire. A nice little function.

There are a lot of code that the Missile Sub is not using, some might work, some might not. But i will post it here anyways.

Turret code example:

		Turreted:
			ROT: 7
			Offset: 341,0,128
		Armament@PRIMARY:
			Weapon: Stinger
			LocalOffset: 0,-100,0, 0,100,0
			LocalYaw: 64, -64
		Armament@SECONDARY:
			Weapon: DepthCharge
			LocalOffset: 0,-100,0, 0,100,0
			LocalYaw: 80, -80
		AttackTurreted:

In this example I've taken the code from the Allied Destroyer. It has a turret, Turret Rotation is 7, and the turret is located at 341,0,128 of this unit. Its Primary weapon is a stinger and the secondary weapon is depth charges for sub. Now you could give your sub 2 weapons to if you just took that code and put it instead of the weapon code.

Now you can get most code from units that uses it and add it to your unit, if you want a unit that acts in a specific way try to think of a unit that already exist and mimic that. It's ALWAYS easier to copy something that already works then to make something from scratch.

You can also replace the original SHP (in this case the MSUB) by adding a SHP to the bits folder with the same name as your codename. You will however have the same icon as the MSUB if you do not follow the guide below.

Either way your done. Save the file and close it down, test your new unit! :)

Creating a new unit from scratch

The not so simple way to do it. If you want to do this use the above example code of the Ohio Ballistic Sub. But do not add this code:

		RenderUnit:
			Image: MSUB

Remember if you want to create a unit from scratch you will need a SHP of the unit and a unit ICON. Put these in the bits folder and make sure they have the same name as your unit name code (In this example OHIOSUB.shp and OHIOSUBICON.shp)

Go into your sequence folder and open the right yaml file (in this case ships.yaml)

Search for the unit you cloned. In this case I searched for msub and found this, copy and paste it at the bottom. (MSUB was at the bottom but we still need a new entry), Make the last code look like this.

		msub:
			idle:
				Start: 0
				Facings: 16
			icon: msubicon
				Start: 0
	
		ohiosub:
			idle:
				Start: 0
				Facings: 16
			icon: ohiosubicon
				Start: 0

What now?

Well, we gone through two ways to add a new unit. Now it's time for you to save all the edit files and test the game!

In depth guide by HSFOutcast.