public static function setMinMax() { $mapData = MapData::getInstance(); $x = $mapData->maxX; $y = $mapData->maxY; self::$evenColumnShiftDown = true; self::$minX = 4; self::$minY = 8; self::$maxY = 4 * ($y - 1) + self::$minY + 2; // if(self::$evenColumnShiftDown == true) // { // if ( $x % 2 == 0 ) self::$maxY += 2; // } else { // if ( $x % 2 == 0 ) self::$maxY -= 2; // } self::$maxX = 2 * ($x - 1) + self::$minX; self::$setup = true; }
function __construct($Force, $Terrain, $data = null) { // Class references $this->mapData = MapData::getInstance(); $this->moves = new stdClass(); $this->path = new stdClass(); $this->force = $Force; $this->terrain = $Terrain; if ($data) { foreach ($data as $k => $v) { $this->{$k} = $v; } } else { $this->movingUnitId = NONE; $this->anyUnitIsMoving = false; $this->storm = false; $this->railMove = true; $this->stickyZoc = false; } }
function __construct($data = null, $arg = false, $scenario = false, $game = false) { $this->mapData = MapData::getInstance(); if ($data) { $this->arg = $data->arg; $this->scenario = $data->scenario; $this->terrainName = $data->terrainName; $this->game = $data->game; $this->mapData->init($data->mapData); $this->mapViewer = array(new MapViewer($data->mapViewer[0]), new MapViewer($data->mapViewer[1]), new MapViewer($data->mapViewer[2])); $units = $data->force->units; unset($data->force->units); $this->force = new Force($data->force); foreach ($units as $unit) { $this->force->injectUnit(static::buildUnit($unit)); } if (isset($data->terrain)) { $this->terrain = new Terrain($data->terrain); } else { $this->terrain = new \stdClass(); } $this->moveRules = new MoveRules($this->force, $this->terrain, $data->moveRules); $this->combatRules = new TacticalCombatRules($this->force, $this->terrain, $data->combatRules); $this->gameRules = new GameRules($this->moveRules, $this->combatRules, $this->force, $data->gameRules); $this->victory = new Victory($data); $this->players = $data->players; } else { $this->arg = $arg; $this->scenario = $scenario; $this->game = $game; $this->mapViewer = array(new MapViewer(), new MapViewer(), new MapViewer()); $this->force = new Force(); $this->terrain = new Terrain(); $this->moveRules = new MoveRules($this->force, $this->terrain); $this->combatRules = new TacticalCombatRules($this->force, $this->terrain); $this->gameRules = new GameRules($this->moveRules, $this->combatRules, $this->force); } }
function __construct($data = null, $arg = false, $scenario = false, $game = false) { /* * do not call parent constructor :( */ $this->mapData = MapData::getInstance(); if ($data) { $this->arg = $data->arg; $this->scenario = $data->scenario; $this->terrainName = $data->terrainName; $this->game = $data->game; $this->mapData->init($data->mapData); $this->mapViewer = array(new MapViewer($data->mapViewer[0]), new MapViewer($data->mapViewer[1]), new MapViewer($data->mapViewer[2])); $units = $data->force->units; unset($data->force->units); $this->force = new Force($data->force); foreach ($units as $unit) { $this->force->injectUnit(static::buildUnit($unit)); } if (isset($data->terrain)) { $this->terrain = new Terrain($data->terrain); } else { $this->terrain = new \stdClass(); } $this->moveRules = new MoveRules($this->force, $this->terrain, $data->moveRules); $this->combatRules = new ModernTacticalCombatRules($this->force, $this->terrain, $data->combatRules); $this->gameRules = new GameRules($this->moveRules, $this->combatRules, $this->force, $data->gameRules); $this->victory = new Victory($data); $this->players = $data->players; } else { $this->arg = $arg; $this->scenario = $scenario; $this->game = $game; $this->mapViewer = array(new MapViewer(), new MapViewer(), new MapViewer()); $this->force = new Force(); $this->terrain = new Terrain(); $this->moveRules = new MoveRules($this->force, $this->terrain); $this->combatRules = new ModernTacticalCombatRules($this->force, $this->terrain); $this->gameRules = new GameRules($this->moveRules, $this->combatRules, $this->force); } $crt = new \Wargame\Troops\ModernTactics\CombatResultsTable(); $this->combatRules->injectCrt($crt); if ($data) { } else { $this->victory = new \Wargame\Victory("\\Wargame\\Troops\\ModernTactics\\modernTacticsVictoryCore"); $this->mapData->blocksZoc->blocked = true; $this->mapData->blocksZoc->blocksnonroad = true; $this->moveRules->enterZoc = 0; $this->moveRules->exitZoc = 0; $this->moveRules->noZocZoc = false; $this->moveRules->zocBlocksRetreat = false; $this->moveRules->oneHex = false; $this->gameRules->gameHasCombatResolutionMode = false; // game data if (!empty($scenario->seven)) { $this->gameRules->setMaxTurn(12); } elseif (!empty($scenario->one)) { $this->gameRules->setMaxTurn(18); } else { $this->gameRules->setMaxTurn(15); } $this->gameRules->setInitialPhaseMode(BLUE_DEPLOY_PHASE, DEPLOY_MODE); $this->gameRules->attackingForceId = BLUE_FORCE; /* object oriented! */ $this->gameRules->defendingForceId = RED_FORCE; /* object oriented! */ $this->force->setAttackingForceId($this->gameRules->attackingForceId); /* so object oriented */ $this->gameRules->addPhaseChange(BLUE_DEPLOY_PHASE, RED_DEPLOY_PHASE, DEPLOY_MODE, RED_FORCE, BLUE_FORCE, false); $this->gameRules->addPhaseChange(RED_DEPLOY_PHASE, BLUE_FIRST_COMBAT_PHASE, COMBAT_SETUP_MODE, BLUE_FORCE, RED_FORCE, false); $this->gameRules->addPhaseChange(BLUE_FIRST_COMBAT_PHASE, RED_FIRST_COMBAT_PHASE, COMBAT_SETUP_MODE, RED_FORCE, BLUE_FORCE, false); $this->gameRules->addPhaseChange(RED_FIRST_COMBAT_PHASE, BLUE_COMBAT_RES_PHASE, COMBAT_RESOLUTION_MODE, BLUE_FORCE, RED_FORCE, false); $this->gameRules->addPhaseChange(BLUE_COMBAT_RES_PHASE, BLUE_MOVE_PHASE, MOVING_MODE, BLUE_FORCE, RED_FORCE, false); $this->gameRules->addPhaseChange(BLUE_MOVE_PHASE, RED_MOVE_PHASE, MOVING_MODE, RED_FORCE, BLUE_FORCE, false); $this->gameRules->addPhaseChange(RED_MOVE_PHASE, BLUE_FIRST_COMBAT_PHASE, COMBAT_SETUP_MODE, BLUE_FORCE, RED_FORCE, true); } }
function set($unitId, $unitName, $unitForceId, $unitHexagon, $unitImage, $firstUnitStrength, $secondUnitStrength, $firstUnitDefstrength, $secondUnitDefStrength, $unitMaxMove, $isReduced, $unitStatus, $unitReinforceZone, $unitReinforceTurn, $range, $nationality = "neutral", $forceMarch, $class, $unitDesig) { $this->dirty = true; $this->id = $unitId; $this->name = $unitName; $this->forceId = $unitForceId; $this->class = $class; $this->hexagon = new Hexagon($unitHexagon); /* blah! this can get called from the constructor of Battle. so we can't get ourselves while creating ourselves */ // $battle = Battle::getBattle(); // $mapData = $battle->mapData; $mapData = MapData::getInstance(); $mapHex = $mapData->getHex($this->hexagon->getName()); if ($mapHex) { $mapHex->setUnit($this->forceId, $this); } $this->image = $unitImage; // $this->strength = $isReduced ? $unitMinStrength : $unitMaxStrength; $this->maxMove = $unitMaxMove; $this->moveAmountUnused = $unitMaxMove; $this->unitStrength = $firstUnitStrength; $this->secondUnitStrength = $secondUnitStrength; $this->isReduced = $isReduced; $this->status = $unitStatus; $this->moveAmountUsed = 0; $this->reinforceZone = $unitReinforceZone; $this->reinforceTurn = $unitReinforceTurn; $this->combatNumber = 0; $this->combatIndex = 0; $this->combatOdds = ""; $this->moveCount = 0; $this->retreatCountRequired = 0; $this->combatResults = NE; $this->range = $range; $this->nationality = $nationality; $this->forceMarch = $forceMarch; $this->unitDesig = $unitDesig; $this->unitDefStrength = $firstUnitDefstrength; $this->secondUnitDefStrength = $secondUnitDefStrength; }
function checkBlocked($los, $id) { $mapData = MapData::getInstance(); $good = true; $hexParts = $los->getlosList(); // remove first and last hexPart $src = array_shift($hexParts); $target = array_pop($hexParts); $srcElevated = $targetElevated = $srcElevated2 = $targetElevated2 = false; if ($this->terrain->terrainIs($src, "elevation2")) { $srcElevated2 = true; } if ($this->terrain->terrainIs($target, "elevation2")) { $targetElevated2 = true; } if ($this->terrain->terrainIs($src, "elevation1")) { $srcElevated = true; } if ($this->terrain->terrainIs($target, "elevation1")) { $targetElevated = true; } $hasElevated1 = $hasElevated2 = false; foreach ($hexParts as $hexPart) { if ($this->terrain->terrainIs($hexPart, "blocksRanged") && (!$srcElevated2 || !$targetElevated2)) { return false; } if ($this->terrain->terrainIs($hexPart, "elevation2")) { $hasElevated2 = true; continue; } if ($this->terrain->terrainIs($hexPart, "elevation1")) { $hasElevated1 = true; break; } } /* don't do elevation check if non elevation (1) set. This deals with case of coming up * back side of not circular hill */ if ($hasElevated1 || $targetElevated || $srcElevated) { /* * Ugly if statement. If elevation1 both src and target MUST be elevation1 OR either src or target can be elevation2. * otherwise, blocked. */ if ($hasElevated1 && !($srcElevated && $targetElevated || ($targetElevated2 || $srcElevated2))) { $good = false; } if ($hasElevated2 && (!$srcElevated2 || !$targetElevated2)) { $good = false; } } if ($good === false) { return false; } $mapHex = $mapData->getHex($this->force->getUnitHexagon($id)->name); if ($this->force->mapHexIsZOC($mapHex)) { return false; } return $good; }
function __construct($data = null, $arg = false, $scenario = false) { parent::__construct($data, $arg, $scenario); $crt = new \Wargame\TMCW\Chawinda1965\CombatResultsTable(); $this->combatRules->injectCrt($crt); $this->mapData = MapData::getInstance(); if ($data) { $this->specialHexA = $data->specialHexA; $this->specialHexB = $data->specialHexB; $this->specialHexC = $data->specialHexC; } else { $this->victory = new \Wargame\Victory("Wargame\\TMCW\\Chawinda1965\\chawinda1965VictoryCore"); if (!empty($scenario->supplyLen)) { $this->victory->setSupplyLen($scenario->supplyLen); } $this->moveRules->enterZoc = 1; $this->moveRules->exitZoc = 2; $this->moveRules->noZocZocOneHex = false; $this->moveRules->stacking = 3; $this->moveRules->friendlyAllowsRetreat = true; $this->moveRules->blockedRetreatDamages = true; $this->gameRules->legacyExchangeRule = false; // game data $this->gameRules->setMaxTurn(8); $this->gameRules->setInitialPhaseMode(BLUE_DEPLOY_PHASE, DEPLOY_MODE); $this->gameRules->attackingForceId = BLUE_FORCE; /* object oriented! */ $this->gameRules->defendingForceId = RED_FORCE; /* object oriented! */ $this->force->setAttackingForceId($this->gameRules->attackingForceId); /* so object oriented */ $this->gameRules->addPhaseChange(BLUE_DEPLOY_PHASE, RED_DEPLOY_PHASE, DEPLOY_MODE, PAKISTANI_FORCE, INDIAN_FORCE, false); $this->gameRules->addPhaseChange(RED_DEPLOY_PHASE, BLUE_MOVE_PHASE, MOVING_MODE, INDIAN_FORCE, PAKISTANI_FORCE, false); // $this->gameRules->addPhaseChange(BLUE_REPLACEMENT_PHASE, BLUE_MOVE_PHASE, MOVING_MODE, INDIAN_FORCE, PAKISTANI_FORCE, false); $this->gameRules->addPhaseChange(BLUE_MOVE_PHASE, BLUE_COMBINE_PHASE, COMBINING_MODE, INDIAN_FORCE, PAKISTANI_FORCE, false); $this->gameRules->addPhaseChange(BLUE_COMBINE_PHASE, BLUE_COMBAT_PHASE, COMBAT_SETUP_MODE, INDIAN_FORCE, PAKISTANI_FORCE, false); $this->gameRules->addPhaseChange(BLUE_COMBAT_PHASE, BLUE_MECH_PHASE, MOVING_MODE, INDIAN_FORCE, PAKISTANI_FORCE, false); $this->gameRules->addPhaseChange(BLUE_MECH_PHASE, BLUE_MECH_COMBINE_PHASE, COMBINING_MODE, INDIAN_FORCE, PAKISTANI_FORCE, false); $this->gameRules->addPhaseChange(BLUE_MECH_COMBINE_PHASE, RED_MOVE_PHASE, MOVING_MODE, PAKISTANI_FORCE, INDIAN_FORCE, false); // $this->gameRules->addPhaseChange(RED_REPLACEMENT_PHASE, RED_MOVE_PHASE, MOVING_MODE, PAKISTANI_FORCE, INDIAN_FORCE, false); $this->gameRules->addPhaseChange(RED_MOVE_PHASE, RED_COMBINE_PHASE, COMBINING_MODE, PAKISTANI_FORCE, INDIAN_FORCE, false); $this->gameRules->addPhaseChange(RED_COMBINE_PHASE, RED_COMBAT_PHASE, COMBAT_SETUP_MODE, PAKISTANI_FORCE, INDIAN_FORCE, false); $this->gameRules->addPhaseChange(RED_COMBAT_PHASE, RED_MECH_PHASE, MOVING_MODE, PAKISTANI_FORCE, INDIAN_FORCE, false); $this->gameRules->addPhaseChange(RED_MECH_PHASE, RED_MECH_COMBINE_PHASE, COMBINING_MODE, PAKISTANI_FORCE, INDIAN_FORCE, false); $this->gameRules->addPhaseChange(RED_MECH_COMBINE_PHASE, BLUE_MOVE_PHASE, MOVING_MODE, INDIAN_FORCE, PAKISTANI_FORCE, true); } $this->moveRules->stacking = function ($mapHex, $forceId, $unit) { $limit = 0; if ($unit->isReduced !== true) { $limit++; } $limit++; foreach ($mapHex->forces[$forceId] as $mKey => $mVal) { if ($this->force->units[$mKey]->isReduced !== true) { $limit++; } $limit++; } return $limit > 6; }; }
public function calcFromAttackers() { $mapData = \Wargame\MapData::getInstance(); $battle = Battle::getBattle(); /* @var CombatRules $cR */ $cR = $battle->combatRules; /* @var Force $force */ $force = $battle->force; $force->clearRequiredCombats(); $defenderForceId = $force->defendingForceId; foreach ($cR->attackers as $attackId => $combatId) { $mapHex = $mapData->getHex($force->getUnitHexagon($attackId)->name); $neighbors = $mapHex->neighbors; foreach ($neighbors as $neighbor) { /* @var MapHex $hex */ $hex = $mapData->getHex($neighbor); if ($hex->isOccupied($defenderForceId)) { $units = $hex->forces[$defenderForceId]; foreach ($units as $unitId => $unitVal) { $requiredVal = true; $combatId = isset($cR->defenders->{$unitId}) ? $cR->defenders->{$unitId} : null; if ($combatId !== null) { $attackers = $cR->combats->{$combatId}->attackers; if ($attackers) { if (count((array) $attackers) > 0) { $requiredVal = false; } } } $force->requiredDefenses->{$unitId} = $requiredVal; } } } } }
function __construct($data = null, $arg = false, $scenario = false, $game = false) { $this->mapData = MapData::getInstance(); if ($data) { $this->arg = $data->arg; $this->scenario = $data->scenario; $this->terrainName = $data->terrainName; $this->game = $data->game; $this->mapData->init($data->mapData); $this->mapViewer = array(new MapViewer($data->mapViewer[0]), new MapViewer($data->mapViewer[1]), new MapViewer($data->mapViewer[2])); $units = $data->force->units; unset($data->force->units); $this->force = new Force($data->force); foreach ($units as $unit) { $this->force->injectUnit(static::buildUnit($unit)); } if (isset($data->terrain)) { $this->terrain = new Terrain($data->terrain); } else { $this->terrain = new \stdClass(); } $this->moveRules = new MoveRules($this->force, $this->terrain, $data->moveRules); $this->combatRules = new CombatRules($this->force, $this->terrain, $data->combatRules); $this->gameRules = new GameRules($this->moveRules, $this->combatRules, $this->force, $data->gameRules); $this->victory = new Victory($data); $this->players = $data->players; } else { $this->arg = $arg; $this->scenario = $scenario; $this->game = $game; $this->mapViewer = array(new MapViewer(), new MapViewer(), new MapViewer()); $this->force = new Force(); $this->force->exchangesKill = true; $this->terrain = new Terrain(); $this->moveRules = new MoveRules($this->force, $this->terrain); $this->combatRules = new CombatRules($this->force, $this->terrain); $this->gameRules = new GameRules($this->moveRules, $this->combatRules, $this->force); } $this->moveRules->stacking = function ($mapHex, $forceId, $unit) { /* * Return false if can stack, true if stacking forbidden. */ /* * If entering unit is hq, can stack with one other unit, but no more. */ if ($unit->class == "hq") { return count((array) $mapHex->forces[$forceId]) > 1; } /* * entering unit not hq, cannot stack with no hq unit. */ foreach ($mapHex->forces[$forceId] as $mKey => $mVal) { if ($this->force->units[$mKey]->class !== "hq") { return true; } } /* * can stack if hex empty or has just one hq in it. */ return count((array) $mapHex->forces[$forceId]) > 1; }; static::getPlayerData($this->scenario); $crt = new \Wargame\Mollwitz\CombatResultsTable(); $this->combatRules->injectCrt($crt); }
public function setMaxHex() { $mapData = MapData::getInstance(); $x = $mapData->maxX; $y = $mapData->maxY; $hexName = sprintf("%02d%02d", $x, $y); new Hexagon(); list($x, $y) = Hexagon::getHexPartXY($hexName); $this->maxTerrainY = $y + 4; /* for bottom and even odd columns */ $this->maxTerrainX = $x; // for ($x = 0; $x < $this->maxTerrainX; $x++) { // for ($y = 0; $y <= $this->maxTerrainY; $y++) { // $this->terrainArray[$y][$x] = new stdClass(); // } // // } }
function set($unitForceId, $unitHexagon, $attackStrength, $range, $defenseStrength, $unitMaxMove, $weapons, $target, $unitStatus, $unitReinforceZone, $unitReinforceTurn, $nationality = "neutral", $class, $unitDesig) { $this->dirty = true; $this->forceId = $unitForceId; $this->class = $class; $this->hexagon = new Hexagon($unitHexagon); /* blah! this can get called from the constructor of Battle. so we can't get ourselves while creating ourselves */ // $battle = Battle::getBattle(); // $mapData = $battle->mapData; $mapData = MapData::getInstance(); $mapHex = $mapData->getHex($this->hexagon->getName()); if ($mapHex) { $mapHex->setUnit($this->forceId, $this); } $this->maxMove = $unitMaxMove; $this->normalMoveAmount = $this->moveAmountUnused = $unitMaxMove; $this->attackStrength = $attackStrength; $this->defenseStrength = $defenseStrength; $this->target = $target; $this->status = $unitStatus; $this->moveAmountUsed = 0; $this->weapons = $weapons; $this->reinforceZone = $unitReinforceZone; $this->reinforceTurn = $unitReinforceTurn; $this->combatNumber = 0; $this->combatIndex = 0; $this->combatOdds = ""; $this->moveCount = 0; $this->combatResults = NE; $this->range = $range; $this->nationality = $nationality; $this->forceMarch = true; $this->unitDesig = $unitDesig; }
function checkBlocked($los, $id) { $mapData = MapData::getInstance(); $good = true; $hexParts = $los->getlosList(); // remove first and last hexPart $src = array_shift($hexParts); $target = array_pop($hexParts); $srcHexSide = $hexParts[0]; $targetHexSide = $hexParts[count($hexParts) - 1]; $localLos = new Los(); $localLos->originX = $los->originX; $localLos->originY = $los->originY; $range = $los->getRange(); $hasElevated1 = $hasElevated2 = false; foreach ($hexParts as $hexPart) { if ($this->terrain->terrainIs($hexPart, "blocksRanged")) { if ($this->terrain->terrainIs($hexPart, "crest")) { if ($hexPart === $targetHexSide || $hexPart === $srcHexSide) { continue; } } return false; } } if ($good === false) { return false; } return $good; }
function checkBlocked($los, $id) { $mapData = MapData::getInstance(); $good = true; $hexParts = $los->getlosList(); // remove first and last hexPart $src = array_shift($hexParts); $target = array_pop($hexParts); $srcElevated = $targetElevated = $srcElevated2 = $targetElevated2 = false; if ($this->terrain->terrainIs($src, "elevation2")) { $srcElevated2 = true; } if ($this->terrain->terrainIs($target, "elevation2")) { $targetElevated2 = true; } if ($this->terrain->terrainIs($src, "elevation1")) { $srcElevated = true; } $localLos = new Los(); $localLos->originX = $los->originX; $localLos->originY = $los->originY; $range = $los->getRange(); $hasElevated1 = $hasElevated2 = false; foreach ($hexParts as $hexPart) { if ($this->terrain->terrainIs($hexPart, "blocksRanged") && ($srcElevated2 || $targetElevated2)) { $localLos->setEndPoint($hexPart); $localRange = $localLos->getRange(); if ($targetElevated2 && $localRange > $range / 2) { continue; } if ($srcElevated2 && $localRange < $range / 2) { continue; } } if ($this->terrain->terrainIs($hexPart, "blocksRanged") && (!$srcElevated2 || !$targetElevated2)) { return false; } if ($this->terrain->terrainIs($hexPart, "elevation2")) { $hasElevated2 = true; continue; } } /* don't do elevation check if non elevation (1) set. This deals with case of coming up * back side of not circular hill */ if ($hasElevated2 || $targetElevated || $srcElevated) { if ($hasElevated2 && (!$srcElevated2 || !$targetElevated2)) { $good = false; } } if ($good === false) { return false; } return $good; }
public static function getInstance() { if (!MapData::$instance) { MapData::$instance = new MapData(); } return MapData::$instance; }
public function setUnit($forceId, $unit) { $id = $unit->id; $battle = \Wargame\Battle::getBattle(); if (!$this->forces) { /* * 5, 0 is observer and up to 4 players :( */ $this->forces = array(new stdClass(), new stdClass(), new stdClass(), new stdClass(), new stdClass()); } if (!$this->forces[$forceId]) { $this->forces[$forceId] = new stdClass(); } $this->forces[$forceId]->{$id} = $id; $neighbors = $this->neighbors; $mapData = MapData::getInstance(); $blocksZoc = $mapData->blocksZoc; $unitHex = $unit->hexagon; if ($unit->noZoc !== true) { $neighbors = $this->getZocNeighbors($unit); foreach ($neighbors as $neighbor) { $hex = $mapData->getHex($neighbor); if (!empty($blocksZoc->blocked) && $battle->terrain->terrainIsHexSide($unitHex->name, $neighbor, "blocked")) { continue; } if (!empty($blocksZoc->blocksnonroad) && $battle->terrain->terrainIsHexSide($unitHex->name, $neighbor, "blocksnonroad")) { continue; } if ($hex) { if (!$hex->zocs) { $hex->zocs = array(new stdClass(), new stdClass(), new stdClass(), new stdClass(), new stdClass()); } if (!$hex->zocs[$forceId]) { $hex->zocs[$forceId] = new stdClass(); } $hex->zocs[$forceId]->{$id} = $id; } } } $neighbors = $this->neighbors; foreach ($neighbors as $neighbor) { $hex = $mapData->getHex($neighbor); if (!empty($blocksZoc->blocked) && $battle->terrain->terrainIsHexSide($unitHex->name, $neighbor, "blocked")) { continue; } if ($hex) { if (!$hex->adjacent) { $hex->adjacent = array(new stdClass(), new stdClass(), new stdClass(), new stdClass(), new stdClass()); } if (!$hex->adjacent[$forceId]) { $hex->adjacent[$forceId] = new stdClass(); } $hex->adjacent[$forceId]->{$id} = $id; } } $this->dirty = true; }