////////////////////////////// //// 8. Piracy Code //// //////////////////////////// // 8) Piracy code - Creates Barbarian ships every few // turns, what unit is created depends on // available technology HandleEvent(BeginTurn) 'CRA_PiracyTest' post { location_t tmpLoc; int_t xcoord; int_t ycoord; int_t width; int_t height; int_t i; int_t type; int_t PiracyBeginTurn; // store in what turn piracy should become possible int_t PiracyChance; // change of piracy attack; on average, 1 piracy attack every PiracyChance turns PiracyBeginTurn=80; PiracyChance=10; if (Random(PiracyChance) == 0 && g.year > PiracyBeginTurn) { width=GetMapWidth(); height=GetMapHeight(); xcoord = Random(width); ycoord = Random(height); MakeLocation(tmpLoc, xcoord, ycoord ); //make a random location if ( (TerrainType(tmpLoc) >9 && TerrainType(tmpLoc)<17) || TerrainType(tmpLoc)==22 || TerrainType(tmpLoc)==23 ) { //if it's a water location, choose a type of pirate ship (providing player[0] has ships): if (HasAdvance(player[0], ID_ADVANCE_OIL_REFINING)) { type = UnitDB(UNIT_SUBMARINE); } elseif (HasAdvance(player[0], ID_ADVANCE_CHRONOMETER)) { type = UnitDB(UNIT_GALLEON); } elseif (HasAdvance(player[0], ID_ADVANCE_ASTROLABE)) { type = UnitDB(UNIT_DROMON); } elseif (HasAdvance(player[0], ID_ADVANCE_HULL_MAKING)) { type = UnitDB(UNIT_HEPTIREME); } elseif (HasAdvance(player[0], ID_ADVANCE_SAILS)) { type = UnitDB(UNIT_BIREME); } else { type = -100; // don't create pirate unit } if (type != -100) { CreateUnit(0, type, tmpLoc, 0); } } } }