op2_sdk:placing_units

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
op2_sdk:placing_units [2016/01/31 20:43] vagabondop2_sdk:placing_units [2016/10/12 21:32] (current) – external edit 127.0.0.1
Line 3: Line 3:
 ''Reviewed For: SDK 2.1'' ''Reviewed For: SDK 2.1''
  
-The Unit class represents all buildings and vehicles in Outpost 2. All scenarios will require some initial units+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()''
- +
-Building position is determined by the point where the vertical and horizontal tube of a building would intercept if they continued through.+
  
 ===== LOCATION offset ===== ===== LOCATION offset =====
  
-Unit positions are represented in game by either the structure LOCATION or by passing 2 integers into a function, representing the and position. LOCATION represents the tile currently being occupied by the unit. 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.+Positions in game are represented by either the structure ''LOCATION'' or by passing 2 integers into a function, representing the and 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.
  
 +===== Building Origin =====
  
 +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.
  
-===== Building Origin =====+{{ op2_sdk:buildingoriginexample.png.png?450 }} 
 +<html><center></html><fs small>//Image Credits: Sir Bomber//</fs><html></center></html>
  
-When attempting to place units on the map, you can reference the map coordinates by using the mapper and looking in the lower right corner. See the image below for an example.+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
  
-For building without tube connections like Tokamak, the LOCATION of the building cooresponds with the lower right tile of the structure.+{{ op2_sdk:mappercoordinatesexample.png }} 
 +<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 game. See the image below for an example. 
 + 
 +{{ op2_sdk:ingamecoordinatesexample.png }} 
 +<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> 
 + 
 +===== Vehicle Lights ===== 
 + 
 +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. 
 + 
 +===== Placing Units In Garage ===== 
 + 
 +During level initializationunits 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. 
 +===== Using the CreateUnit Function ===== 
 + 
 +<code cpp> 
 +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. 
 +</code> 
 + 
 +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.
  
-{{op2_sdk:buildingoriginexample.png.png?450}}\\ 
-<fs small>//Image Credits: Sir Bomber//</fs> 
  
 ===== Related Source Code ===== ===== Related Source Code =====
Line 27: Line 71:
 <code cpp> <code cpp>
 static int __fastcall CreateUnit( static int __fastcall CreateUnit(
-    Unit& returnedUnit,  +    Unit& returnedUnit, map_id unitType, LOCATION location, int playerNum, map_id weaponCargoType, int rotation); 
-    map_id unitType,  +</code> 
-    LOCATION location, int playerNum, map_id weaponCargoType, int rotation);+ 
 +//Unit.h// 
 +<code cpp> 
 +void DoSetLights(int boolOn);
 </code> </code>
  
Line 36: Line 83:
 enum UnitDirection enum UnitDirection
 { {
- East = 0, +    East = 0, 
- SouthEast = 1, +    SouthEast = 1, 
- South = 2, +    South = 2, 
- SouthWest = 3, +    SouthWest = 3, 
- West = 4, +    West = 4, 
- NorthWest = 5, +    NorthWest = 5, 
- North = 6, +    North = 6, 
- NorthEast = 7,+    NorthEast = 7,
 }; };
 </code> </code>
Line 192: Line 239:
 int InitProc() 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);
 } }
  
Line 201: Line 282:
  - //Go Back to [[op2_sdk:software_development_kit_sdk|Outpost 2 Mapmaking]]//\\  - //Go Back to [[op2_sdk:software_development_kit_sdk|Outpost 2 Mapmaking]]//\\
  - //Go Back to [[outpost_2:outpost_2|Outpost 2 Main page]]//\\  - //Go Back to [[outpost_2:outpost_2|Outpost 2 Main page]]//\\
- - //Go Back to [[http://wiki.outpostuniverse.org/doku.php?id=start|Wiki Home Page]]//+ - //Go Back to [[http://wiki.outpost2.net/doku.php?id=start|Wiki Home Page]]//
  • op2_sdk/placing_units.1454273012.txt.gz
  • Last modified: 2016/01/31 20:43
  • by vagabond