OpenRA modding tutorials
How to: import units from Red Alert 2 / TS to OpenRA

OpenRA uses the .SHP format from C&C and Red Alert. But there probably exist more fan-made .SHP files in Red Alert 2’s fan communities than for the original, even though only their infantry still use this format (vehicles use a voxel format). So that leaves a lot of potentially untapped art for us to dip in to! But there are technical hurdles to using them: the color palettes are different from those SHPs and they are not compatible with OpenRA. Units are also larger than C&C / Red Alert’s. Neither is the infantry’s animation frames in the same order. So what to do? Let me give you this quick guide to moving units from Tiberian Sun / Red Alert 2 / Yuri’s Revenge into a format readable from OpenRA! 

Step 1. Pick a unit to import.

There are many resources on the web. One place with a lot of user-generated SHPs is YR Argentina. You can also download the original Tiberian Sun data files. You can also try ModDB, Project Perfect Mod, and Sleipnir’s Stuff; I’m sure there are far more sites out there. 

Step 2. Extract frames from the .SHP into images

The method I use to extract the images I want from the .SHP is Open Source Ship Builder. By going to File Menu, Export, SHP->Images you can extract each frame from the .SHP file and into many .PNG images. The command-line program OpenRA.Utility also lets you extract the frames from .SHPs, but it can only output them to a single image containing all the frames, which can be a hinderance in steps 3.5 and 4 (color replacements and scaling).

The .SHPs in Tiberian Sun / RA 2 frequently have a night-time/daytime version of the same unit. For infantry, typically the first half, 292 frames, are day and the second set of 292 are night, giving a total of 484. Since there is no night-time in OpenRA we can remove the second half of frames. 

Step 3. Convert “team colors” into the ones you want. 

This post has instructions on converting team colors quickly from one game into another, as well as scripts to automate the process. 

Color palettes on units have 16 colors set aside to be your “team colors”. They vary from game to game. I have made some scripts that allow you to convert those team colors quickly so that you can import units from one game to another with minimum of hassle. 

In C&C and Red Alert, team colors are yellowish, are are then converted into whatever team color you choose for a multiplayer game. 

The “team colors” indicators for Tiberian Sun / Red Alert 2 are red, requiring conversion:

Step 3.5 - fixing up minor blemishes (optional)

A problem with infantry from RA 2/TS is that they use two of the team color reds for muzzle flashes and blood. For this reason, the brightest color of the team colors palette is not changed by my script by default (the line for that color is commented out). If you want to be careful to not alter those colors, move the shooting/blood frames to another folder while you use the script to convert the bright red color in the rest of the frames (uncomment the top line of the script). (Blood and shooting animations for RA2 infantry are usually found between frames 134 and 259). If you do this, when you run the team color conversion script for the shooting / blood frames, you can also comment out the lines for color #a89854 from the script. Any remaining red dots of those two colors in the shooting or blood frames can be edited by hand. 

If you’re lazy, the blemishes from the commented-out bright red will be barely visible, if at all, after you scale down your unit. Changing the darker red color found in muzzleflash to a team color is generally hardly noticeable, and it’s usually fine if you just convert it to a team color for all the frames. The Jump Jet Infantry is an exception to this rule, where the dark red is a bit more prominent in the muzzle flash. 

To see what I’m talking about, behold the colors that are conflicted. 

Notice also that the gun for this Ghost Stalker unit is the same dark red, even thought it is supposed to appear as the team’s color. For this reason I chose to be lazy and convert all the dark reds to team colors, even though a few pixels from the muzzle flash were also changed. 

4. Resizing / scaling your unit.

Read this post for instructions on resizing / scaling your unit for OpenRA. 

5. Re-package back into a .SHP file

OpenRA.Utility can convert your images into a .SHP for you, but it requires that your images be in one file, with each frame all on one horizontal line. You can combine all your images like this by using ImageMagick’s “convert” utility from the command line. Enter this command to combine all images in the folder into one:
> convert *.png +append output.png
Next you will need to import the color palette from your game. This converts the colors in the image to ones readable by the game. Open output.png in an image editor. In photoshop, go to image -> mode -> indexed color and load the appropriate palette. In Irfanview, go to image -> palette -> import palette. If the image already has a palette loaded for some reason, you will need to convert it to RGB color mode first (in Irfanview select image-> increase color depth).
You can download the palettes for RA/C&C/D2K here
Before your save the image as a .PNG, check to make sure the background is still black (appears transparent in-game) and not off-black. If it’s off-black, use the paint bucket to turn it black (with anti-aliasing and tolerance off!).
To convert your image into a .SHP, enter this command (## should be the width of each frame.)
> OpenRA.Utility —shp output.png ##
It is also possible to use XCC Editor to make SHP files.
At this point you should have a working SHP file that you can put in the bits/ folder of your mod.
I hope this guide helps you import units from Red Alert 2 / Tiberian Sun! If you have questions or feedback, email me at psydev at live dot com. 
Resizing units from other games to OpenRA

Games like Dune 2000, Red Alert 2 / Tiberian Sun and StarCraft use images that are larger than C&C. So if you borrow units from that format you will probably want to resize them to a smaller scale. You can do this two ways:

1) Use the in-game scaler. To do this, In your unit’s .yaml file, put (under the appropriate Render key for your unit):

RenderInfantryProne:    

        Scale: 0.7

The downside of this method is that it looks too high-res when you turn on pixel-doubling. The quality may also not be as good in general as scaling beforehand. Another downside is that OpenRA doesn’t support scaling for unit death animations. 

2) Resize/resample the images beforehand. 

Red Alert 2 / Tiberian Sun units are larger than their Red Alert / C&C counterparts. From those games, I scale down my units around 65%. I scale Dune2000 vehicles to 80%. 

If you have a single image with many frames in it, avoid scaling using percentages. Scale to a specific size in pixels instead. Make sure image’s new width in pixels will divide by the total number of frames, with no decimals.

If you have many images, you can either resize them all separately using a program like Irfanview's batch conversion feature, or collate them together using a program like ImageMagick. To collate them, run the command:

>convert *.png +append output.png

It’s usually best to apply the color palette of your game to your images before resizing them. This is especially true if you’re changing the team colors, since rescaling them can change those colors. This isn’t good if you were going to use a script to change those specific colors.

To use Irfanview for this, open the file menu -> batch conversion. Select the images you want to include for the unit (all of your frames) and then click the “advanced” button. There, select the resize radio button and enter 65% (or your desired proportions). Then click OK and then start your batch conversion. Note that if you resample the image, some colors will change.

After you’ve rescaled the unit, you will need to apply the color palette again before converting it into a SHP.

Reference: frame size comparisons for infantry between games:

C&C / Red Alert:

    Infantry Height: ~11 px

    Frame size: 50 x 39 pixels

Dune 2000:

    Infantry height: ~14 px

    Frame size: 48  x 35 px

Tiberian Sun / Red Alert 2:

    Infantry height: ~20 px

    Frame size: 61 x 61 px

StarCraft:

    Infantry height: ~25-28 px

    Frame size: variable

Scripts - Changing “team colors” from other games to OpenRA

Color palettes on units have 16 colors set aside to be your “team colors”. They vary from game to game. I have made some scripts that allow you to convert those team colors quickly so that you can import units from one game to another with minimum of hassle. You will need to install ImageMagick for these scripts. The script will convert colors for all .PNG images in the folder you run it from. 

Red Alert 2 / TS -> Red Alert

Red Alert 2 / TS -> C&C

Red Alert 2 / TS -> Dune 2000

Dune 2000 -> Red Alert

Dune 2000 -> C&C

StarCraft -> Red Alert

StarCraft -> C&C

StarCraft -> Dune 2000

Dark Colony -> Red Alert

You want to convert team colors from other games (purple for StarCraft):

image

… into these team colors:

image