op2_sdk:placing_units

Placing Units

Reviewed For: SDK 2.1

The Unit class represents all buildings and vehicles in Outpost 2. New units should be created using the function CreateUnit defined in TethysGame.h. Initial Units should be defined within the function InitProc().

Positions in game are represented by either the structure LOCATION or by passing 2 integers into a function, representing the X and Y position. The Outpost 2 game engine requires units to be placed +31 X tiles and -1 Y tiles from their actual position. For example: LOCATION(21 + 31, 15 - 1) would be the position (21, 15) on the map.

For buildings in Outpost 2 that span more than one tile, the position is determined by the point where the vertical and horizontal tube of a building would intercept if they were continuous. See the graphic below for a visual representation. For a building without tube connections, like a Tokamak, the LOCATION of the building corresponds with the lower right tile of the structure.

<html><center></html><fs small>Image Credits: Sir Bomber</fs><html></center></html>

When attempting to place units on the map, map coordinates can be referenced by using the mapper and looking in the lower right corner to see which coordinate is highlighted.

<html><center></html>Mapper: The position of the white highlighted tile is shown at the bottom right of the screen<html></center></html>

If you can load the map in Outpost 2, map coordinates can also be referenced in the lower left side of the in game screen. The current highlighted coordinate still updates as you move your mouse after pausing a game. See the image below for an example.

<html><center></html>In Game: The position of the tile highlighted by the cursor is shown at the bottom left side of the screen<html></center></html>

When any vehicle is created, the Outpost 2 SDK defaults to turning its lights off. The function DoSetLights(int boolOn) from Unit.h can be used to turn the lights on. See example code below for context.

During level initialization, units can be placed in a garage using the Unit function PutInGarage(int bayIndex, int tileX, int tileY).

Call PutInGarage on the vehicle that you plan to place in a garage. The arguments tileX and tileY are the position of the garage you want the vehicle placed inside.

You CAN add vehicles to a garage that are not owned by the same player as the garage owner.

static int __fastcall CreateUnit(
    Unit& returnedUnit,
    map_id unitType, 
    LOCATION location, 
    int playerNum, 
    map_id weaponCargoType, 
    int rotation);
 
Unit& returnedUnit //Passes the address of a unit. Where you can access the newly created unit later.
map_id unitType //The type of unit to create. Check the map_id enum set in MapIdEnum.h.
LOCATION location //Where the unit will be created.
int playerNum //The player who will own the structure, with player 1 being represented as 0.
map_id weaponCargoType //For a guardpost or tank, the turret type. 
                       //Use map_id::mapEnergyCannon for a scorpion's weapon.
                       //For a ConVec or Cargo Truck, this represents the vehicle's starting cargo.
                       //This will not set the initial cargo of a building. 
                       //For a building, use the function SetFactoryCargo.
int rotation //Sets the initial rotation of a unit. 0 is east and continues in clockwise direction.
             //Consider using the enum UnitDirection to set as opposed to an integer.

Some variables used in CreateUnit are not required depending on what unit is being created. For example, a command center cannot have cargo or if you want to create a truck that does not contain any cargo. In these situations use the enum map_id::mapNone to indicate no cargo is required.

The variable rotation is meaningless to the creation of a structure. Any value can be used.

From TethysGame

static int __fastcall CreateUnit(
    Unit& returnedUnit, map_id unitType, LOCATION location, int playerNum, map_id weaponCargoType, int rotation);

Unit.h

void DoSetLights(int boolOn);

NonExportedEnums.h

enum UnitDirection
{
    East	= 0,
    SouthEast	= 1,
    South	= 2,
    SouthWest	= 3,
    West	= 4,
    NorthWest	= 5,
    North	= 6,
    NorthEast	= 7,
};

MapIdEnum.h

enum map_id {
    mapAny = -1,			// FF Use to specify 'all' or 'any'
 
    mapNone = 0,			// 00
    mapCargoTruck,			// 01
    mapConVec,				// 02
    mapSpider,				// 03
    mapScorpion,			// 04
    mapLynx,				// 05
    mapPanther,				// 06
    mapTiger,				// 07
    mapRoboSurveyor,			// 08
    mapRoboMiner,			// 09
    mapGeoCon,				// 0A
    mapScout,				// 0B
    mapRoboDozer,			// 0C
    mapEvacuationTransport,		// 0D
    mapRepairVehicle,			// 0E
    mapEarthworker,			// 0F
    mapSmallCapacityAirTransport,	// 10 Crashes game when it moves (looks like a scout)
 
    mapTube,				// 11
    mapWall,				// 12
    mapLavaWall,			// 13
    mapMicrobeWall,			// 14
 
    mapCommonOreMine,			// 15
    mapRareOreMine,			// 16
    mapGuardPost,			// 17
    mapLightTower,			// 18
    mapCommonStorage,			// 19
    mapRareStorage,			// 1A
    mapForum,				// 1B
    mapCommandCenter,			// 1C
    mapMHDGenerator,			// 1D
    mapResidence,			// 1E
    mapRobotCommand,			// 1F
    mapTradeCenter,			// 20
    mapBasicLab,			// 21
    mapMedicalCenter,			// 22
    mapNursery,				// 23
    mapSolarPowerArray,			// 24
    mapRecreationFacility,		// 25
    mapUniversity,			// 26
    mapAgridome,			// 27
    mapDIRT,				// 28
    mapGarage,				// 29
    mapMagmaWell,			// 2A
    mapMeteorDefense,			// 2B
    mapGeothermalPlant,			// 2C
    mapArachnidFactory,			// 2D
    mapConsumerFactory,			// 2E
    mapStructureFactory,		// 2F
    mapVehicleFactory,			// 30
    mapStandardLab,			// 31
    mapAdvancedLab,			// 32
    mapObservatory,			// 33
    mapReinforcedResidence,		// 34
    mapAdvancedResidence,		// 35
    mapCommonOreSmelter,		// 36
    mapSpaceport,			// 37
    mapRareOreSmelter,			// 38
    mapGORF,				// 39
    mapTokamak,				// 3A
 
    mapAcidCloud,			// 3B
    mapEMP,				// 3C
    mapLaser,				// 3D
    mapMicrowave,			// 3E
    mapRailGun,				// 3F
    mapRPG,				// 40
    mapStarflare,			// 41 Vehicle Starflare
    mapSupernova,			// 42 Vehicle Supernova
    mapStarflare2,			// 43 GuardPost Starflare
    mapSupernova2,			// 44 GuardPost Supernova
    mapNormalUnitExplosion,		// 45
    mapESG,				// 46
    mapStickyfoam,			// 47
    mapThorsHammer,			// 48
    mapEnergyCannon,			// 49
 
    mapBlast,				// 4A EMP/Sticky foam blast
    //mapUnknown4B,			// 4B Unknown what this is  "BFG"
 
    mapLightning = 0x4C,		// 4C
    mapVortex,				// 4D
    mapEarthquake,			// 4E
    mapEruption,			// 4F
    mapMeteor,				// 50
 
    mapMiningBeacon,			// 51
    mapMagmaVent,			// 52
    mapFumarole,			// 53
 
    mapWreckage,			// 54
 
    mapDisasterousBuildingExplosion,	// 55
    mapCatastrophicBuildingExplosion,	// 56
    mapAtheistBuildingExplosion,	// 57
 
    mapEDWARDSatellite,			// 58  Lynx (in Cargo Truck)
    mapSolarSatellite,			// 59  Wreckage (in Cargo Truck)
    mapIonDriveModule,			// 5A  Gene Bank 5 (in Cargo Truck)
    mapFusionDriveModule,		// 5B
    mapCommandModule,			// 5C
    mapFuelingSystems,			// 5D
    mapHabitatRing,			// 5E
    mapSensorPackage,			// 5F
    mapSkydock,				// 60
    mapStasisSystems,			// 61
    mapOrbitalPackage,			// 62
    mapPhoenixModule,			// 63
 
    mapRareMetalsCargo,			// 64
    mapCommonMetalsCargo,		// 65
    mapFoodCargo,			// 66
    mapEvacuationModule,		// 67
    mapChildrenModule,			// 68
 
    mapSULV,				// 69
    mapRLV,				// 6A
    mapEMPMissile,			// 6B
 
    mapImpulseItems,			// 6C
    mapWares,				// 6D
    mapLuxuryWares,			// 6E
 
    mapInterColonyShuttle,		// 6F
    mapSpider3Pack,			// 70
    mapScorpion3Pack,			// 71
 
    mapPrettyArt,			// 72 (Used for explosions)
 
    mapGeneralUnit,			// 73 Don't try to create this unless you're implementing a new unit class
};
int InitProc()
{
    // Create a Command Center for player 1.
    Unit commandCenter;
 
    TethysGame::CreateUnit(
        commandCenter, 
        map_id::mapCommandCenter, 
        LOCATION(30 + 31, 208 - 1), 
        0, 
        map_id::mapNone, 
        UnitDirection::East);
 
 
    // Create an Acid Cloud guard post for player 2.
    Unit guardPost;
 
    TethysGame::CreateUnit(
        guardPost, 
        map_id::mapGuardPost, 
        LOCATION(3 + 31, 2 - 1), 
        1, 
        map_id::mapAcidCloud, 
        UnitDirection::East)
 
    // Create a ConVec with a Tokamak Kit for player 2 and turn it's lights on.
    Unit conVec;
 
    TethysGame::CreateUnit(
        conVec, 
        map_id::mapConVec, 
        LOCATION(50 + 31, 10 - 1), 
        1, 
        map_id::mapTokamak, 
        UnitDirection::North);
 
    conVec.DoSetLights(true);
}

- Go Back to Programming a Scenario
- Go Back to Outpost 2 Mapmaking
- Go Back to Outpost 2 Main page
- Go Back to Wiki Home Page

  • op2_sdk/placing_units.txt
  • Last modified: 2016/10/12 21:32
  • by 127.0.0.1