function unitIsInRange($id, $argRange = false) { $b = Battle::getBattle(); $isInRange = false; $range = $this->units[$id]->range; if ($argRange !== false) { $range = $argRange; } if ($range <= 1) { return false; } if ($this->ZOCrule == true) { $los = new Los(); $los->setOrigin($this->units[$id]->hexagon); for ($i = 0; $i < count($this->units); $i++) { /* hexagons without names are off map */ if (!$this->units[$i]->hexagon->name) { continue; } $los->setEndPoint($this->units[$i]->hexagon); $losRange = $los->getRange(); if ($losRange <= $range && $this->units[$i]->forceId != $this->units[$id]->forceId && $this->units[$i]->status != STATUS_CAN_REINFORCE && $this->units[$i]->status != STATUS_ELIMINATED) { if ($b->combatRules->checkBlocked($los, $id)) { $isInRange = true; break; } } } } return $isInRange; }
function rangeIsOneHexagon($startHexagon, $endHexagon) { $rangeIsOne = false; $los = new Los(); $los->setOrigin($startHexagon); $los->setEndPoint($endHexagon); if ($los->getRange() == 1) { $rangeIsOne = true; } return $rangeIsOne; }
public function setCombatIndex($defenderId) { $combatLog = ""; $battle = Battle::getBattle(); $scenario = $battle->scenario; $combats = $battle->combatRules->combats->{$defenderId}; if (count((array) $combats->attackers) == 0) { $combats->index = null; $combats->attackStrength = null; $combats->defenseStrength = null; $combats->terrainCombatEffect = null; return; } $defenders = $combats->defenders; $isCrest = $isCavalry = $isTown = $isHill = $isForest = $isSwamp = $attackerIsSunkenRoad = $isRedoubt = $isElevated = false; $combats->index = []; foreach ($defenders as $defId => $defender) { $defUnit = $battle->force->units[$defId]; $hexagon = $defUnit->hexagon; if ($defUnit->class === 'cavalry') { $isCavalry = true; } $hexpart = new Hexpart(); $hexpart->setXYwithNameAndType($hexagon->name, HEXAGON_CENTER); $isTown |= $battle->terrain->terrainIs($hexpart, 'town'); $isForest |= $battle->terrain->terrainIs($hexpart, 'forest'); if ($battle->terrain->terrainIs($hexpart, 'elevation')) { $isElevated = 1; } if ($battle->terrain->terrainIs($hexpart, 'elevation2')) { $isElevated = 2; } $defenseStrength = $defUnit->defenseStrength; } $isClear = true; if ($isTown || $isForest || $isHill || $isSwamp) { $isClear = false; } $attackers = $combats->attackers; $attackStrength = 0; $attackersCav = false; $combinedArms = array(); $combatLog .= "<br>"; foreach ($attackers as $attackerId => $attacker) { $terrainReason = ""; $unit = $battle->force->units[$attackerId]; $unitStrength = $unit->strength; $hexagon = $unit->hexagon; $hexpart = new Hexpart(); $hexpart->setXYwithNameAndType($hexagon->name, HEXAGON_CENTER); $los = new Los(); $los->setOrigin($battle->force->getUnitHexagon($attackerId)); $los->setEndPoint($battle->force->getUnitHexagon($defenderId)); $range = $los->getRange(); $hexParts = $los->getlosList(); $targetHex = array_pop($hexParts); $targetHexSide = array_pop($hexParts); if ($battle->terrain->terrainIs($targetHexSide, "crest")) { $isCrest = true; } $combatLog .= $unit->strength . " " . $unit->class . " = " . $unit->strength . "<br>"; if ($range == 1) { $isCloseAssault = false; if ($unit->weapons === ModernTacticalUnit::SM_WEAPONS) { if ($defenderId !== false) { $defUnit = $battle->force->units[$defenderId]; if ($defUnit->target === ModernTacticalUnit::HARD_TARGET) { $isCloseAssault = true; } } } if (!$isCloseAssault) { $unitStrength *= 2; $combatLog .= "range 1, doubled = {$unitStrength}<br>"; } else { $combatLog .= "close assult no range attenuation = {$unitStrength}<br>"; } } if ($range >= 4 && $range <= 5) { $unitStrength -= 1; $combatLog .= " -1 range attentuation = {$unitStrength}<br>"; } if ($range >= 6 && $range <= 8) { $unitStrength -= 2; $combatLog .= " -2 range attentuation = {$unitStrength}<br>"; } if ($range >= 9 && $range <= 10) { $unitStrength -= 3; $combatLog .= " -3 range attentuation = {$unitStrength}<br>"; } if ($range >= 11) { $unitStrength -= 6; $combatLog .= "-6 range attentuation = {$unitStrength}<br>"; } $attackerIsElevated = false; if ($battle->terrain->terrainIs($hexpart, 'elevation')) { $attackerIsElevated = 1; } if ($battle->terrain->terrainIs($hexpart, 'elevation2')) { $attackerIsElevated = 2; } $unitStrength -= $defenseStrength; $combatLog .= " - {$defenseStrength} defender = {$unitStrength}<br>"; if ($isForest) { $unitStrength--; $combatLog .= " in forest - 1 = <span class='fixed-width' >{$unitStrength}</span><br>"; } if ($isTown) { $unitStrength -= 2; $combatLog .= " in town - 2 = <span class='fixed-width' >{$unitStrength}</span><br>"; } if ($isCrest) { $unitStrength -= 1; $combatLog .= " in crest - 1 = <span class='fixed-width' >{$unitStrength}</span><br>"; } $combatLog .= "final = {$unitStrength}<br><br>"; $combats->index[] = $unitStrength; } $combats->combatLog = $combatLog; }
function thisAttackAcrossTwoType($defenderId, $attackerId, $type) { $los = new Los(); $los->setOrigin($this->force->getUnitHexagon($defenderId)); $los->setEndPoint($this->force->getUnitHexagon($attackerId)); $hexParts = $los->getlosList(); /* * defender is located in hexParts[0], * x first hexside adjacent to defender is in $hexParts[1] need to check second hexside for elevations checks from behind. */ return $this->terrain->terrainIs($hexParts[1], $type) || $this->terrain->terrainIs($hexParts[2], $type); }
public function setCombatIndex($defenderId) { $combatLog = ""; /* @var JagCore $battle */ $battle = Battle::getBattle(); $scenario = $battle->scenario; $combats = $battle->combatRules->combats->{$defenderId}; if (count((array) $combats->attackers) == 0) { $combats->index = null; $combats->attackStrength = null; $combats->defenseStrength = null; $combats->terrainCombatEffect = null; return; } $defenders = $combats->defenders; $isCavalry = $isTown = $isHill = $isForest = $isSwamp = $attackerIsSunkenRoad = $isRedoubt = $isElevated = false; foreach ($defenders as $defId => $defender) { $defUnit = $battle->force->units[$defId]; $hexagon = $defUnit->hexagon; if ($defUnit->class === 'cavalry') { $isCavalry = true; } $hexpart = new Hexpart(); $hexpart->setXYwithNameAndType($hexagon->name, HEXAGON_CENTER); $isTown |= $battle->terrain->terrainIs($hexpart, 'town'); $isForest |= $battle->terrain->terrainIs($hexpart, 'forest'); if ($battle->terrain->terrainIs($hexpart, 'elevation')) { $isElevated = 1; } if ($battle->terrain->terrainIs($hexpart, 'elevation2')) { $isElevated = 2; } } $isClear = true; if ($isTown || $isForest || $isHill || $isSwamp) { $isClear = false; } $attackers = $combats->attackers; $attackStrength = 0; $attackersCav = false; $combinedArms = array(); $combatLog .= "Attackers<br>"; foreach ($attackers as $attackerId => $attacker) { $terrainReason = ""; $unit = $battle->force->units[$attackerId]; $unitStrength = $unit->strength; $hexagon = $unit->hexagon; $hexpart = new Hexpart(); $hexpart->setXYwithNameAndType($hexagon->name, HEXAGON_CENTER); $los = new Los(); $los->setOrigin($battle->force->getUnitHexagon($attackerId)); $los->setEndPoint($battle->force->getUnitHexagon($defenderId)); $range = $los->getRange(); $combatLog .= $unit->strength . " " . $unit->class . " "; if ($isCavalry) { $combatLog .= "defender is cavalry, doubled "; $unitStrength *= 2; } if ($unit->class === "infantry" && $range == 1) { $combatLog .= "infantry at range 1, doubled "; $unitStrength *= 2; } if ($unit->class === "mg" && $range <= 3) { $combatLog .= "machine gun at range 3 or less, doubled "; $unitStrength *= 2; } if ($isTown || $isForest) { if ($range > 1) { $combatLog .= "using observation fire, halved "; $unitStrength /= 2; } } $attackerIsElevated = false; if ($battle->terrain->terrainIs($hexpart, 'elevation')) { $attackerIsElevated = 1; } if ($battle->terrain->terrainIs($hexpart, 'elevation2')) { $attackerIsElevated = 2; } $combatLog .= "<br>"; $attackStrength += $unitStrength; } $combatLog .= " = {$attackStrength}<br>Defenders<br>"; $defenseStrength = 0; foreach ($defenders as $defId => $defender) { $unitStrength = 2; $terrain = ''; $unit = $battle->force->units[$defId]; $class = $unit->class; $clearHex = false; $notClearHex = false; $hexagon = $unit->hexagon; $hexpart = new Hexpart(); $hexpart->setXYwithNameAndType($hexagon->name, HEXAGON_CENTER); $isTown = $battle->terrain->terrainIs($hexpart, 'town'); // $isHill = $battle->terrain->terrainIs($hexpart, 'hill'); $isForest = $battle->terrain->terrainIs($hexpart, 'forest'); $isSwamp = $battle->terrain->terrainIs($hexpart, 'swamp'); $terran = ""; if ($attackerIsElevated < $isElevated) { $unitStrength = 4; $terrain = "uphill "; } if ($isTown) { $terrain = "in town "; $unitStrength = 8; } if ($isForest) { $terrain = "in forest "; $unitStrength = 5; } if ($unit->isImproved) { $unitStrength *= 2; $terrain .= "Improved "; } $combatLog .= "{$unitStrength} " . $unit->class . " {$terrain}"; $defenseStrength += $unitStrength; $combatLog .= "<br>"; } $combatLog .= " = {$defenseStrength}"; $combatIndex = $this->getCombatIndex($attackStrength, $defenseStrength); /* Do this before terrain effects */ if ($combatIndex >= $this->maxCombatIndex) { $combatIndex = $this->maxCombatIndex; } // $terrainCombatEffect = $battle->combatRules->getDefenderTerrainCombatEffect($defenderId); // $combatIndex -= $terrainCombatEffect; $combats->attackStrength = $attackStrength; $combats->defenseStrength = $defenseStrength; $combats->terrainCombatEffect = 0; // // if($combats->pinCRT !== false){ // $pinIndex = $combats->pinCRT; // if($combatIndex > $pinIndex){ // $combatLog .= "<br>Pinned to {$this->combatResultsHeader[$pinIndex]} "; // }else{ // $combats->pinCRT = false; // } // } $combats->index = $combatIndex; $combats->useAlt = false; $combats->combatLog = $combatLog; }
function unitIsInRange($id) { $isZOC = false; $range = $this->units[$id]->range; if ($range <= 1) { return false; } if ($this->ZOCrule == true) { $los = new Los(); $los->setOrigin($this->units[$id]->hexagon); for ($i = 0; $i < count($this->units); $i++) { $los->setEndPoint($this->units[$i]->hexagon); if ($los->getRange() <= $range && $this->units[$i]->forceId != $this->units[$id]->forceId && $this->units[$i]->status != STATUS_CAN_REINFORCE && $this->units[$i]->status != STATUS_ELIMINATED) { $isZOC = true; break; } } } return $isZOC; }
public function checkLos(\Wargame\Los $los, $defenderId = false) { $b = Battle::getBattle(); if ($this->weapons === ModernTacticalUnit::SM_WEAPONS) { if ($defenderId !== false) { $defUnit = $b->force->units[$defenderId]; if ($defUnit->target === ModernTacticalUnit::HARD_TARGET) { if ($los->getRange() > 1) { return false; } } } } return true; }
function checkBombardment($cd = false) { if ($cd === false) { $cd = $this->currentDefender; } $attackers = $this->combats->{$cd}->attackers; $defenders = $this->combats->{$cd}->defenders; foreach ($defenders as $defenderId => $defender) { foreach ($this->combats->{$cd}->attackers as $attackerId => $attacker) { $los = new Los(); $los->setOrigin($this->force->getUnitHexagon($attackerId)); $los->setEndPoint($this->force->getUnitHexagon($defenderId)); $range = $los->getRange(); if ($range == 1) { $this->combats->{$cd}->isBombardment = false; return; } } } $this->combats->{$cd}->isBombardment = true; $this->combats->{$cd}->useDetermined = false; }
public function checkCommand($unit) { $id = $unit->id; $b = Battle::getBattle(); $cmdRange = 8; if ($b->gameRules->phase == RED_MOVE_PHASE || $b->gameRules->phase == BLUE_MOVE_PHASE) { foreach ($this->headQuarters as $hq) { if ($id == $hq) { return; } $los = new Los(); $los->setOrigin($b->force->getUnitHexagon($id)); $los->setEndPoint($b->force->getUnitHexagon($hq)); $range = $los->getRange(); if ($range <= $cmdRange) { return; } } $unit->status = STATUS_UNAVAIL_THIS_PHASE; return; } }