Pillbox and Barbed Wire
The original Invasion of France scenario code uses unit types unique to each nation as pillbox garrisons. In the present modified code the pillbox becomes functional whenever a pillbox tile improvement is created and any infantry unit of the pillbox owner may serve as a garrison.
Technically the script creates a "pillbox unit" whenever a "pillbox tileimp" is finished, which is able to carry the pillbox garrison (infantry units). The script also handles terrain owner changes and the removal of the "pillbox tileimp" if the "pillbox unit" is destroyed (and vice versa).
Barbed wires work as known from the Invasion of France scenario (they stop enemy units from moving for 1 turn).
A separate script handles the AI’s building of military facilities, including pillboxes and barbed wires.
1The Script1
//--------------------------------------------------------------------------
// MoT Mod for CTP2 (Apolyton Edition) by BureauBert
// v1.1
// http://motmod.ctp2.info
//--------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////
// Original Pillbox and barbed wire code from Invasion of France scenario
// update 12-19-00 by Tony Evans.
// Unlike the original script, the present version does not require special
// pillbox garrison units -- any infantry unit of the
// pillbox owner may serve as a pillbox garrison.
////////////////////////////////////////////////////////////////////////////
// Zeroes out movements points from any land units that move onto Barbed Wire
HandleEvent(MoveUnits) 'BarbedWireMove' post {
location_t pibTmpLoc;
location_t pibArmyLoc;
army_t pibTmpArmy;
unit_t pibTmpUnit;
int_t pibNumUnits;
int_t pibCount;
int_t pibTileOwner;
int_t pibTmpArmyOwner;
int_t pibMovementDeduct;
pibTmpLoc = location[1]; // destination location
pibArmyLoc = location[0];
pibTileOwner = CellOwner(pibArmyLoc);
if(TileHasImprovement(pibTmpLoc, TerrainImprovementDB(TILEIMP_BARBED_WIRE))) {
pibTmpArmy = army[0];
pibNumUnits = pibTmpArmy.size;
pibTmpArmyOwner = pibTmpArmy.owner;
if(pibTileOwner != pibTmpArmyOwner) {
for(pibCount = 0; pibCount < pibNumUnits; pibCount = pibCount + 1) {
if(GetUnitFromArmy(pibTmpArmy, pibCount, pibTmpUnit)) {
if(!IsAirUnit(pibTmpUnit)) {
pibMovementDeduct = 1 - UnitMovementLeft(pibTmpUnit);
AddMovement(pibTmpUnit, pibMovementDeduct);
}
}
}
}
}
}
// Creates/removes pillbox unit
HandleEvent(ImprovementComplete) 'ActivatePillbox' post {
location_t pibTmpLoc;
int_t pibPillboxOwner;
pibTmpLoc = location[0];
pibPillboxOwner = CellOwner(location[0]);
// If the tile has a pillbox ti, create pillbox unit
if(TileHasImprovement(pibTmpLoc, TerrainImprovementDB(TILEIMP_PILLBOX))) {
CreateUnit(pibPillboxOwner, UnitDB(PILLBOX), pibTmpLoc, 0);
}
}
HandleEvent(CutImprovements) 'DeActivatePillbox1' post {
location_t pibTmpLoc;
unit_t pibTmpUnit;
int_t pibNumUnits;
int_t pibCount;
int_t pibPillboxOwner;
pibTmpLoc = location[0];
// If the tile has a Pillbox, kill the pillbox unit
if(!TileHasImprovement(pibTmpLoc, TerrainImprovementDB(TILEIMP_PILLBOX))) {
pibPillboxOwner = CellOwner(pibTmpLoc);
pibNumUnits = GetUnitsAtLocation(pibTmpLoc);
for(pibCount = 0; pibCount < pibNumUnits; pibCount = pibCount + 1) {
GetUnitFromCell(pibTmpLoc, pibCount, pibTmpUnit);
if(pibTmpUnit.valid && IsPillboxUnit(pibTmpUnit)) {
KillUnit(pibTmpUnit);
}
}
}
}
HandleEvent(ImprovementComplete) 'DeActivatePillbox2' post {
location_t pibTmpLoc;
unit_t pibTmpUnit;
int_t pibNumUnits;
int_t pibCount;
int_t pibPillboxOwner;
pibTmpLoc = location[0]; // start location
// If the tile has no Pillbox, kill the pillbox unit
if(!TileHasImprovement(pibTmpLoc, TerrainImprovementDB(TILEIMP_PILLBOX))) {
pibPillboxOwner = CellOwner(pibTmpLoc);
pibNumUnits = GetUnitsAtLocation(pibTmpLoc);
for(pibCount = 0; pibCount < pibNumUnits; pibCount = pibCount + 1) {
GetUnitFromCell(pibTmpLoc, pibCount, pibTmpUnit);
if(pibTmpUnit.valid && IsPillboxUnit(pibTmpUnit)) {
KillUnit(pibTmpUnit);
}
}
}
}
HandleEvent(KillUnit) 'DeActivatePillboxTileimp' pre {
location_t pibTmpLoc;
unit_t pibTmpUnit;
pibTmpUnit = unit[1];
pibTmpLoc = pibTmpUnit.location;
if(pibTmpUnit.valid && IsPillboxUnit(pibTmpUnit)) {
Event:CutImprovements(pibTmpLoc);
}
}
HandleEvent(BeginTurnUnit) 'PillboxChangeOwner' pre {
location_t pibTmpLoc;
unit_t pibTmpUnit;
int_t pibUnitOwner;
int_t pibTileOwner;
pibTmpUnit = unit[0];
pibTmpLoc = pibTmpUnit.location;
pibUnitOwner = pibTmpUnit.owner;
pibTileOwner = CellOwner(pibTmpLoc);
if(pibTmpUnit.valid && IsPillboxUnit(pibTmpUnit)) {
if(pibUnitOwner != pibTileOwner) {
if(TileHasImprovement(pibTmpLoc, TerrainImprovementDB(TILEIMP_PILLBOX))) {
KillUnit(pibTmpUnit);
CreateUnit(pibTileOwner, UnitDB(PILLBOX), pibTmpLoc, 0);
}
}
}
}