IUnit.h

From OPU Wiki

This header contains the class definition for IUnit : the Internal Unit structure. This naming is not 100% correct, coz it's just another 'wrapper' around the existing Unit class, and adding some more member functions, but i've named it so, because it lets the programmer access the internal unit structure to give it some additional commands, that were never included in the exported Unit class.

Use the IUnit carefully. Test your code thoroughly, and make sure it runs fine.

Table of contents

New commands

Doze

Use Doze on a RoboDozer unit only, and give it a region that should be bulldozed:

IUnit dozer;
MAP_RECT region(40,20,45,22);
TethysGame::CreateUnit(dozer,mapRoboDozer,LOCATION(40,15),0,mapNone,0);
dozer.Doze(region);


Build

Use Build with a Convec, RoboMiner or GeoCon. When used on a convec it should have a kit in its storage:

IUnit convec;
LOCATION loc(42,22);
TethysGame::CreateUnit(convec,mapConVec,LOCATION(42,15),0,mapResidence,0);
convec.Build(loc);


Produce

This can be used on factories or a spaceport to build a kit, vehicle or spacecraft/unit:

IUnit fact;
TethysGame::CreateUnit(fact,mapStructureFactory,LOCATION(40,20),0,mapNone,0);
fact.Produce(mapGuardPost,mapMicrowave);


TransferCargo

When you want to transfer cargo to or from a factory to a convec, use TransferCargo on the convec:

IUnit fact,convec;
TethysGame::CreateUnit(convec,mapConVec,LOCATION(42,15),0,mapResidence,0);
TethysGame::CreateUnit(fact,mapStructureFactory,LOCATION(40,20),0,mapNone,0);
convec.TransferCargo(0);

The above coe illustrates a FAULTY command, since the convec has to be on the pad of the factory for this to work; it will not move to the pad itself, it has to be moved there using DoMove. It is also not possible to "stack" the TransferCargo command, so that it will be executed after the unit has reached the pad. To determine if the unit has occupied the pad either check convec.Location() yourself, or create a PointTrigger

LoadCargo

LoadCargo is the same as TransferCargo, but it only loads the cargo, specificly a food or metals cargo. No bay# is required

UnloadCargo

UnloadCargo is the same as TransferCargo, but it only unloads the cargo, specificly a food or metals cargo. No bay# is required

DumpCargo

DumpCargo simply dumps the cargo, no matter where the unit is.


Research

Research will start the selected research at the lab. Be carefull: it has not yet been tested what happens when you change the research topic during a running research. It might have unwanted effects.

IUnit lab;
TethysGame::CreateUnit(lab,mapStandardLab,LOCATION(40,20),0,mapNone,0);
lab.Research(techOffspringEnhancement,4);


TrainScientists

To train additional scientists, use TrainScientists with a university:

IUnit univ;
TethysGame::CreateUnit(univ,mapUniversity,LOCATION(40,20),0,mapNone,0);
univ.TrainScientists(2);


Salvage

Salvage rubble with this command. It takes a region and a unit as params:

IUnit gorf,truck;
MAP_RECT region(50,20,55,22);
TethysGame::CreateUnit(gorf,mapGorf,LOCATION(40,20),0,mapNone,0);
TethysGame::CreateUnit(truck,mapCargoTruck,LOCATION(42,15),0,mapNone,0);
truck.Salvage(region,gorf);


Poof

Ever wondered how units just seem to disappear right at the edge of the map ? That's done with Poof:

IUnit tank;
TethysGame::CreateUnit(tank,mapLynx,LOCATION(40,20),0,mapRPG,0);
tank.Poof();

This will really POOF the lynx: it'll just disappear from the location it's showing at that moment, it does NOT move to the edge of the map first! This command also causes some slight graphics anomalies: the unit image will stick to its last location, until the map viewport is moved.


Repair

Repair sends the unit to its target unit and repairs it:

IUnit convec,tok;
TethysGame::CreateUnit(convec,mapConVec,LOCATION(42,20),0,mapNone,0);
TethysGame::CreateUnit(tok,mapTokamak,LOCATION(40,25),0,mapNone,0);
tok.SetDamage(100);
convec.Repair(tok);

Reprogram

Reprogram is exactly the same command as Repair. This is actually an empty (inline) procedure that invokes Repair. It was included for clarity only, and does a check on the type of vehicle: it should be a spider.

Dismantle

Dismantle is exactly the same command as Repair. This is actually an empty (inline) procedure that invokes Repair. It was included for clarity only, and does a check on the type of vehicle: it should be a convec.


Extra unit information

GetBusy

GetBusy returns the command that the unit is currently performing. See commands.h for a complete list.


GetFactoryCargo

This is actually the opposite of SetFactoryCargo: it retrieves the cargo at the specified bay#. Use it only for Structure Factories and SpacePorts.


GetCargo

This one is specificly for convecs: it returns the contents into the cargoType and weaponType params.


GetTruckCargo

GetTruckCargo returns the cargo in a truck. Do not use GetCargo on trucks, but use this one instead. The cargoType param is set to the type of cargo (see enums.h for a list of Truck_Cargo types). The function itself returns an integer of the amount (tons) of cargo in the truck.


GetDamage

The original exported units have a SetDamage function, but no GetDamage. This member function solves that. GetDamage (and SetDamage) return the amount of DAMAGE i.e. if a unit has NO damage, it's value is 0; full damage is determined by the its HITPOINTS (see building.txt in sheets.vol)


IsInRect

IsInRect is a function that can be used within an if-statement or a while-loop for example. it just returns true or false to the question: is this unit within the specified rect?

Personal tools