function setCombatIndex($defenderId) { $combatLog = ""; $battle = Battle::getBattle(); $combatRules = $battle->combatRules; $combats = $battle->combatRules->combats->{$defenderId}; /* @var Force $force */ $force = $battle->force; $hexagon = $battle->force->units[$defenderId]->hexagon; $hexpart = new Hexpart(); $hexpart->setXYwithNameAndType($hexagon->name, HEXAGON_CENTER); if (count((array) $combats->attackers) == 0) { $combats->index = null; $combats->attackStrength = null; $combats->defenseStrength = null; $combats->terrainCombatEffect = null; return; } $defenders = $combats->defenders; $attackStrength = 0; $combatLog .= "Attackers<br>"; foreach ($combats->attackers as $id => $v) { $unit = $force->units[$id]; $combatLog .= $unit->strength . " " . $unit->class . " "; $attackStrength += $unit->strength; } $defenseStrength = 0; $combatLog .= " = {$attackStrength}<br>Defenders<br> "; foreach ($defenders as $defId => $defender) { $unit = $battle->force->units[$defId]; $combatLog .= $unit->strength . " " . $unit->class . " "; $defenseStrength += $unit->defStrength; $combatLog .= "<br>"; } $combatLog .= " = {$defenseStrength}"; $combatIndex = $this->getCombatIndex($attackStrength, $defenseStrength); /* Do this before terrain effects */ if ($combatIndex >= $this->maxCombatIndex) { $combatIndex = $this->maxCombatIndex; } /* @var $combatRules CombatRules */ // $terrainCombatEffect = $combatRules->getDefenderTerrainCombatEffect($defenderId); // $combatIndex -= $terrainCombatEffect; $combats->attackStrength = $attackStrength; $combats->defenseStrength = $defenseStrength; // $combats->terrainCombatEffect = $terrainCombatEffect; $combats->terrainCombatEffect = 0; $combats->index = $combatIndex; $combats->combatLog = $combatLog; }
function setCombatIndex($defenderId) { $combatLog = ""; $battle = Battle::getBattle(); $combatRules = $battle->combatRules; $combats = $battle->combatRules->combats->{$defenderId}; /* @var Force $force */ $force = $battle->force; $hexagon = $battle->force->units[$defenderId]->hexagon; $hexpart = new Hexpart(); $hexpart->setXYwithNameAndType($hexagon->name, HEXAGON_CENTER); $attackingForceId = $battle->force->attackingForceId; $attackingForceName = preg_replace("/ /", "-", Battle::$forceName[$attackingForceId]); $defendingForceId = $battle->force->defendingForceId; $defendingForceName = preg_replace("/ /", "-", Battle::$forceName[$defendingForceId]); if (count((array) $combats->attackers) == 0) { $combats->index = null; $combats->attackStrength = null; $combats->defenseStrength = null; $combats->terrainCombatEffect = null; return; } $defenders = $combats->defenders; $isTown = $isHill = $isForest = $isSwamp = $attackerIsSunkenRoad = $isRedoubt = $isElevated = false; foreach ($defenders as $defId => $defender) { $hexagon = $battle->force->units[$defId]->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'); $isElevated |= $battle->terrain->terrainIs($hexpart, 'elevation'); } $isClear = true; if ($isTown || $isForest || $isHill || $isSwamp) { $isClear = false; } $attackStrength = 0; $combatLog .= "<span class='combatants {$attackingForceName}'>Attackers</span><br>"; foreach ($combats->attackers as $attackerId => $v) { $unit = $force->units[$attackerId]; $combatLog .= $unit->class . " " . $unit->strength . "<br>"; $acrossRiver = false; foreach ($defenders as $defId => $defender) { if ($battle->combatRules->thisAttackAcrossRiver($defId, $attackerId)) { $acrossRiver = true; } } $strength = $unit->strength; if ($acrossRiver) { $strength /= 2; $combatLog .= " halved across river or wadi {$strength}<br>"; } $attackStrength += $strength; } $defenseStrength = 0; $combatLog .= " total {$attackStrength}<br>"; $combatLog .= "<br><span class='combatants {$defendingForceName}'>Defenders</span><br>"; foreach ($defenders as $defId => $defender) { $unit = $battle->force->units[$defId]; $combatLog .= $unit->class . " " . $unit->defStrength . "<br>"; $defenseStrength += $unit->defStrength; } if ($isTown) { $defenseStrength *= 2; $combatLog .= "In Town doubled {$defenseStrength}<br>"; } $combatLog .= " Total {$defenseStrength}<br>"; $combatIndex = $this->getCombatIndex($attackStrength, $defenseStrength); if ($combatIndex >= $this->maxCombatIndex) { $combatIndex = $this->maxCombatIndex; } $combats->attackStrength = $attackStrength; $combats->defenseStrength = $defenseStrength; $combats->index = $combatIndex; $combats->combatLog = $combatLog; }
function setCombatIndex($defenderId) { $combatLog = ""; $battle = Battle::getBattle(); $combatRules = $battle->combatRules; $combats = $battle->combatRules->combats->{$defenderId}; /* @var Force $force */ $force = $battle->force; $hexagon = $battle->force->units[$defenderId]->hexagon; $hexpart = new Hexpart(); $hexpart->setXYwithNameAndType($hexagon->name, HEXAGON_CENTER); if (count((array) $combats->attackers) == 0) { $combats->index = null; $combats->attackStrength = null; $combats->defenseStrength = null; $combats->terrainCombatEffect = null; return; } $defenders = $combats->defenders; $isTown = $isHill = $isForest = $isSwamp = $attackerIsSunkenRoad = $isRedoubt = $isElevated = false; $totalDefense = 1; $terrain = $battle->terrain; $defCombatLog = ""; foreach ($defenders as $defId => $defender) { $hexagon = $battle->force->units[$defId]->hexagon; $hexpart = new Hexpart(); $hexpart->setXYwithNameAndType($hexagon->name, HEXAGON_CENTER); $thisHex = []; $thisLog = ""; $hexName = $hexagon->name; if ($battle->mapData->getMapSymbol($hexagon->name, 'westwall')) { $thisHex['forta'] = 2; $thisLog .= "2x defend in westwall<br>"; } if ($terrain->terrainIs($hexpart, 'roughone')) { $thisHex['roughone'] = 2; $thisLog .= "2x defend in rough<br>"; } if ($terrain->terrainIs($hexpart, 'roughtwo')) { $thisHex['roughtwo'] = 3; $thisLog .= "3x defend in mountain<br>"; } if ($battle->combatRules->allAreAttackingAcrossRiver($defId)) { $thisHex['river'] = 2; $thisLog .= "2x defend behind river<br>"; } $multiple = count($thisHex); $defense = array_sum($thisHex); if ($multiple > 1) { $defense--; } if ($defense > $totalDefense) { $totalDefense = $defense; $defCombatLog = $thisLog . "total def {$defense}x<br>"; } } $attackStrength = 0; $combatLog .= "Attackers<br>"; foreach ($combats->attackers as $attackerId => $v) { $unit = $force->units[$attackerId]; $combatLog .= $unit->strength . " " . $unit->class . "<br>"; $strength = $unit->strength; $attackStrength += $strength; } $defenseStrength = 0; $combatLog .= " = {$attackStrength}<br><br>Defenders<br> "; $unitDefenseStrength = 0; foreach ($defenders as $defId => $defender) { $unit = $battle->force->units[$defId]; $combatLog .= $unit->defStrength . " " . $unit->class . " "; $unitDefenseStrength += $unit->defStrength; $defenseStrength += $unit->defStrength * $totalDefense; $combatLog .= "<br>"; } $combatLog .= "= {$unitDefenseStrength}<br>"; $combatLog .= $defCombatLog; $combatLog .= " = {$defenseStrength}<br><br>"; $combatIndex = $this->getCombatIndex($attackStrength, $defenseStrength); /* Do this before terrain effects */ if ($combatIndex >= $this->maxCombatIndex) { $combatIndex = $this->maxCombatIndex; } /* @var $combatRules CombatRules */ // $terrainCombatEffect = $combatRules->getDefenderTerrainCombatEffect($defenderId); // $combatIndex -= $terrainCombatEffect; $combats->attackStrength = $attackStrength; $combats->defenseStrength = $defenseStrength; $combats->terrainCombatEffect = 0; $combats->index = $combatIndex; $combats->combatLog = $combatLog; }
function setCombatIndex($defenderId) { $combatLog = ""; $battle = Battle::getBattle(); $combatRules = $battle->combatRules; $combats = $battle->combatRules->combats->{$defenderId}; /* @var Force $force */ $force = $battle->force; $hexagon = $battle->force->units[$defenderId]->hexagon; $hexpart = new Hexpart(); $hexpart->setXYwithNameAndType($hexagon->name, HEXAGON_CENTER); if (count((array) $combats->attackers) == 0) { $combats->index = null; $combats->attackStrength = null; $combats->defenseStrength = null; $combats->terrainCombatEffect = null; return; } $defenders = $combats->defenders; $attackStrength = 0; $combatLog .= "Attackers<br>"; $attackers = 0; foreach ($combats->attackers as $id => $v) { $attackers++; $unit = $force->units[$id]; $los = new Los(); $los->setOrigin($force->getUnitHexagon($id)); $los->setEndPoint($force->getUnitHexagon($defenderId)); $range = (int) $los->getRange(); $strength = $unit->strength; $combatLog .= $strength . " " . $unit->class; if ($battle->gameRules->phase == BLUE_TORP_COMBAT_PHASE || $battle->gameRules->phase == RED_TORP_COMBAT_PHASE) { if ($range > 2 * $unit->range) { $strength /= 3; $combatLog .= " One third for extended Range {$strength}"; } elseif ($range > $unit->range) { $strength /= 2; $combatLog .= " Halved for extended Range {$strength}"; } if ($range === 1) { $strength *= 2; $combatLog .= " Doubled for close Range {$strength}"; } if ($range === 2 && $unit->nationality === 'ijn') { $strength *= 2; $combatLog .= " Doubled for close Range {$strength}"; } } else { if ($range > $unit->range) { $strength /= 2; $combatLog .= " Halved for extended Range {$strength}"; } if ($range <= $unit->range / 2) { if ($range <= 2) { $strength *= 3; $combatLog .= " Tripled for range 2 or less {$strength}"; } else { $strength *= 2; $combatLog .= " Doubled for Range less than half normal {$strength}"; } } } $combatLog .= "<br>"; $attackStrength += $strength; } if ($attackers > 1 && !($battle->gameRules->phase == BLUE_TORP_COMBAT_PHASE || $battle->gameRules->phase == RED_TORP_COMBAT_PHASE)) { $beforeStr = $attackStrength; $attackStrength /= 2; $combatLog .= "{$beforeStr} Attack strength halved fore multi ship attack {$attackStrength}<br>"; } $defenseStrength = 0; $combatLog .= " = {$attackStrength}<br>Defenders<br> "; foreach ($defenders as $defId => $defender) { $unit = $battle->force->units[$defId]; $combatLog .= " " . $unit->class . " "; $defenseStrength += $unit->defStrength; $combatLog .= "<br>"; } if ($battle->gameRules->phase == BLUE_TORP_COMBAT_PHASE || $battle->gameRules->phase == RED_TORP_COMBAT_PHASE) { $combats->unitDefenseStrength = $defenseStrength; $combats->oneHitCol = $this->getOneHitColumn($defenseStrength); $combats->twoHitCol = $this->getTwoHitColumn($defenseStrength); $defenseStrength = $unit->maxMove + 1; } $combatLog .= " = {$defenseStrength}"; $combatIndex = $this->getCombatIndex($attackStrength, $defenseStrength); /* Do this before terrain effects */ if ($combatIndex >= $this->maxCombatIndex) { $combatIndex = $this->maxCombatIndex; } /* @var $combatRules CombatRules */ $combats->attackStrength = $attackStrength; $combats->defenseStrength = $defenseStrength; $combats->terrainCombatEffect = 0; $combats->index = $combatIndex; $combats->combatLog = $combatLog; }
function setCombatIndex($defenderId) { $combatLog = ""; $battle = \Wargame\Battle::getBattle(); $combatRules = $battle->combatRules; $combats = $battle->combatRules->combats->{$defenderId}; /* @var Force $force */ $force = $battle->force; $attackingForceId = $force->attackingForceId; $hexagon = $battle->force->units[$defenderId]->hexagon; $hexpart = new Hexpart(); $hexpart->setXYwithNameAndType($hexagon->name, HEXAGON_CENTER); if (count((array) $combats->attackers) == 0) { $combats->index = null; $combats->attackStrength = null; $combats->defenseStrength = null; $combats->terrainCombatEffect = null; return; } $defenders = $combats->defenders; $attackStrength = 0; $isFortA = $isFortB = $isHeavy = $isShock = $isMountain = $isMountainInf = $isTown = $isHill = $isForest = $isSwamp = $attackerIsSunkenRoad = $isRedoubt = false; foreach ($defenders as $defId => $defender) { $unit = $battle->force->units[$defId]; $hexagon = $unit->hexagon; $hexpart = new Hexpart(); $hexpart->setXYwithNameAndType($hexagon->name, HEXAGON_CENTER); $isMountain |= $battle->terrain->terrainIs($hexpart, 'mountain'); $isFortA = $battle->terrain->terrainIs($hexpart, 'forta'); $isFortB = $battle->terrain->terrainIs($hexpart, 'fortb'); if (($isFortB || $isFortA) && $unit->class == "heavy") { $isHeavy = true; } } $combatLog .= "Attackers<br>"; foreach ($combats->attackers as $id => $v) { $unit = $force->units[$id]; $combatLog .= $unit->class . " " . $unit->strength . "<br>"; if ($unit->class == "mountain") { $combatLog .= "+1 shift Mountain Inf in Mountain<br>"; $isMountainInf = true; } if ($unit->class == "shock") { $combatLog .= "+1 shift Attacking with Shock Troops<br>"; $isShock = true; } $attackStrength += $unit->strength; } $combatLog .= "total {$attackStrength}<br>"; $combatLog .= "<br>Defenders<br> "; $defenseStrength = 0; foreach ($defenders as $defId => $defender) { $unit = $battle->force->units[$defId]; $combatLog .= $unit->class . " " . $unit->defStrength . "<br>"; $defenseStrength += $unit->defStrength; } if ($isHeavy) { $defenseStrength++; $combatLog .= "+1 Strength for Heavy Inf in Fortified 1<br>"; } $combatLog .= " total {$defenseStrength}<br><br>"; $combatIndex = $this->getCombatIndex($attackStrength, $defenseStrength); /* Do this before terrain effects */ if ($combatIndex >= $this->maxCombatIndex) { $combatIndex = $this->maxCombatIndex; } /* @var $combatRules CombatRules */ $terrainCombatEffect = $combatRules->getDefenderTerrainCombatEffect($defenderId); if ($isMountainInf && $isMountain) { /* Mountain Inf helps combat agains Mountain hexes */ $terrainCombatEffect--; } /* FortB trumps FortA in multi defender attacks */ /* TODO: FORCED ID SHOULD NOT BE HERE!!! */ if (isset($this->aggressorId) && $attackingForceId !== $this->aggressorId) { } else { $forceName = Battle::$forceName; $player = $forceName[$attackingForceId]; if ($isFortB) { $combatLog .= "Shift 2 left for {$player} attacking into Fortified B<br>"; $terrainCombatEffect += 2; } else { if ($isFortA) { $combatLog .= "Shift 1 left for {$player} attacking into Fortified A<br>"; $terrainCombatEffect += 1; } } } $combatLog .= "Total Shift {$terrainCombatEffect}<br>"; $combatIndex -= $terrainCombatEffect; if ($isShock && $combatIndex >= 0) { $combatIndex++; } $combats->attackStrength = $attackStrength; $combats->defenseStrength = $defenseStrength; $combats->terrainCombatEffect = $terrainCombatEffect; $combats->index = $combatIndex; $combats->combatLog = $combatLog; }