예제 #1
0
function skirmish($aforce, $dforce)
{
    global $t, $options, $submerged;
    //conduct opening fire step
    $ofsaresolved = false;
    $ofsdresolved = false;
    $killsfireback = false;
    $air_a = false;
    $air_d = false;
    $avals = array('totalhits' => 0);
    $dvals = array('totalhits' => 0);
    $alost = array();
    $dlost = array();
    if ($options['seabattle']) {
        //if sea battle:
        if (has_sub($aforce)) {
            $avals['ofs'] = subattack($aforce, 'attack');
        }
        //handle attack subs
        if (has_sub($dforce)) {
            $dvals['ofs'] = subattack($dforce, 'defend');
        }
    } else {
        if ($t == 1 && ($_REQUEST['ruleset'] == 'Classic' || $_REQUEST['ruleset'] == 'Revised')) {
            //check for other opening fire
            //the amphibious assault casualties for AA50 and AA1942 are moved into the regular take casualities section
            if (has_land($aforce) && can_bombard($aforce)) {
                //Amphibious assault
                #debug ('Bombarding');
                $avals['ofs'] = bombard($aforce);
                if (isset($aforce['Bat'])) {
                    $submerged['att']['Bat'] = $aforce['Bat'];
                    unset($aforce['Bat']);
                }
                if (isset($aforce['Des'])) {
                    $submerged['att']['Des'] = $aforce['Des'];
                    unset($aforce['Des']);
                }
            }
        }
    }
    if ($t == 1) {
        if (aa_present() && has_air($aforce)) {
            $dvals['ofs'] = aa_fire($aforce);
        }
    }
    if (isset($avals['ofs'])) {
        $ofsd_triaged = triage($dforce, $avals['ofs'], $dlost, 'def');
        //determine what the casualties will be from OFS for each side:
        $dlost = $ofsd_triaged['lost'];
        $avals['totalhits'] += $avals['ofs']['hits'];
        if (!$options['seabattle'] or $options['seabattle'] && !isset($dforce['Des'])) {
            //resolve casualties if OFS victims are not saved by destroyers
            $dforce = $ofsd_triaged['force'];
            $ofsdresolved = true;
        }
    }
    //lather, rinse, repeat for defender.
    if (isset($dvals['ofs'])) {
        //triage attacking casualties from OFS
        $ofsa_triaged = triage($aforce, $dvals['ofs'], $alost, 'att');
        $alost = $ofsa_triaged['lost'];
        $dvals['totalhits'] += $dvals['ofs']['hits'];
        if (!$options['seabattle'] or $options['seabattle'] && (!isset($aforce['Des']) && $_REQUEST['ruleset'] !== 'Europe')) {
            #take hits right away
            $aforce = $ofsa_triaged['force'];
            $ofsaresolved = true;
        }
    }
    // for all but sub sneak attacks vs a force with DDs and AA50/AA1942 bombardment, OFS casualties already taken.
    //for AA50 and AA1942, taking casualties from bombardment - if it is round 1
    if ($t == 1 && ($_REQUEST['ruleset'] == 'AA50' || $_REQUEST['ruleset'] == 'AA1942')) {
        if (has_land($aforce) && can_bombard($aforce)) {
            //Amphibious assault attacker has to have land units
            //bombards can hit air units now in the AA50 and AA1942 editions.
            #debug ('Bombarding');
            $killsfireback = true;
            $avals['ofs'] = bombard($aforce);
            #print_r ($avals['ofs']);
            $avals['totalhits'] += $avals['ofs']['hits'];
            if (isset($aforce['Bat'])) {
                $submerged['att']['Bat'] = $aforce['Bat'];
                unset($aforce['Bat']);
            }
            if (isset($aforce['Cru'])) {
                $submerged['att']['Cru'] = $aforce['Cru'];
                unset($aforce['Cru']);
            }
        }
    }
    //if AA50/AA1942 AND attacker has air, but no destroyer, and defender has subs, then
    //find hits scored by air (so their hits can be applied to subs or not with DD interaction)
    $air_a = false;
    //reset boolean flags that keep track if air have already fired in this round of combat
    $air_d = false;
    if ($_REQUEST['ruleset'] == 'AA50' or $_REQUEST['ruleset'] == 'AA1942') {
        if (has_air($aforce) && !isset($aforce['Des']) && has_sub($dforce)) {
            //if there are nonsubs in the defenders, then roll for attacking air units
            if (nonsubs($dforce)) {
                $avals['norm'] = airattack($aforce, 'attack');
                $avals['totalhits'] += $avals['norm']['hits'];
                //store result from airattack function in a temp array to be merged with the takeshots results later
                $airavals = $avals;
            }
            //set boolean flag to indicate air have fired in this round already
            $air_a = true;
        }
        if (has_air($dforce) && !isset($dforce['Des']) && has_sub($aforce)) {
            //if there are nonsubs in the attackers, then roll for defending air units
            if (nonsubs($aforce)) {
                $dvals['norm'] = airattack($dforce, 'defend');
                $dvals['totalhits'] += $dvals['norm']['hits'];
                //store result from airattack function in a temp array to be merged with the takeshots results later
                $airdvals = $dvals;
            }
            //set boolean flag to indicate air have fired in this round already
            $air_d = true;
        }
    }
    //find number of hits scored by all regular remaining units
    if (nonsubs($aforce)) {
        $avals['norm'] = takeshots($aforce, 'attack', $air_a);
        //pass tracking flag if air has already fired
        $avals['totalhits'] += $avals['norm']['hits'];
    }
    if (nonsubs($dforce) or $options['AA']) {
        $dvals['norm'] = takeshots($dforce, 'defend', $air_d);
        //pass tracking flag if air has already fired
        $dvals['totalhits'] += $dvals['norm']['hits'];
    }
    //Having allowed the counterattack for sub victims saved by destroyers, now take them off before other casualties are taken
    if (isset($ofsa_triaged) && !$ofsaresolved) {
        $aforce = $ofsa_triaged['force'];
    }
    if (isset($ofsd_triaged) && !$ofsdresolved) {
        $dforce = $ofsd_triaged['force'];
    }
    //triage casualties from bombardment for AA50 and AA1942, so use all other OFS hits besides subs
    if ($_REQUEST['ruleset'] == 'AA50' || $_REQUEST['ruleset'] == 'AA1942') {
        if (nonsubs($aforce) && nonsubs($dforce) && $killsfireback) {
            if (isset($avals['ofs'])) {
                $d_triaged = triage($dforce, $avals['ofs'], $dlost, 'def');
                $dforce = $d_triaged['force'];
                $dlost = $d_triaged['lost'];
            }
        }
    }
    //Now triagecasualties from air attack
    //determine air casualties for defender
    if ($air_a && isset($airavals['norm'])) {
        $aird_triaged = triage($dforce, $airavals['norm'], $dlost, 'def');
        //determine defender's casualties from air attack
        $dforce = $aird_triaged['force'];
        $dlost = $aird_triaged['lost'];
    }
    //determine air casualties for attacker
    if ($air_d && isset($airdvals['norm'])) {
        $aira_triaged = triage($aforce, $airdvals['norm'], $alost, 'att');
        //determine attacker's casualties from air attack
        $aforce = $aira_triaged['force'];
        $alost = $aira_triaged['lost'];
    }
    //Now, triage all other casualties
    if (isset($avals['norm'])) {
        $d_triaged = triage($dforce, $avals['norm'], $dlost, 'def');
        $dforce = $d_triaged['force'];
        $dlost = $d_triaged['lost'];
    }
    if (isset($dvals['norm'])) {
        $a_triaged = triage($aforce, $dvals['norm'], $alost, 'att');
        $aforce = $a_triaged['force'];
        $alost = $a_triaged['lost'];
    }
    //merge the attacker airvals and vals arrays into one so dice get displayed correctly.
    if ($air_a && isset($airavals['norm'])) {
        $avals["totalhits"] += $airavals["totalhits"];
        $avals["norm"]["hits"] += $airavals["norm"]["hits"];
        $avals["norm"]["punch"] += $airavals["norm"]["punch"];
        $avals["norm"]["dice"]["rolled"] += $airavals["norm"]["dice"]["rolled"];
        //ADD dice rolls at 1 3 4 5 (possible dice rolls for air units)
        //may not need dice rolls at 2 or 6 until air is listed to hit at 2 or 6.
        $index = array(1, 3, 4, 5);
        foreach ($index as $v) {
            if (array_key_exists($v, $airavals["norm"]["dice"]) && array_key_exists($v, $avals["norm"]["dice"])) {
                $avals["norm"]["dice"][$v] = array_merge($airavals["norm"]["dice"][$v], $avals["norm"]["dice"][$v]);
            } elseif (array_key_exists($v, $airavals["norm"]["dice"])) {
                $avals["norm"]["dice"][$v] = $airavals["norm"]["dice"][$v];
            }
        }
        ksort($avals["norm"]["dice"]);
    }
    //merge the defender airvals and vals arrays into one so dice get displayed correctly.
    if ($air_d && isset($airdvals['norm'])) {
        $dvals["totalhits"] += $airdvals["totalhits"];
        $dvals["norm"]["hits"] += $airdvals["norm"]["hits"];
        $dvals["norm"]["punch"] += $airdvals["norm"]["punch"];
        $dvals["norm"]["dice"]["rolled"] += $airdvals["norm"]["dice"]["rolled"];
        //ADD dice rolls at 1 3 4 5 (possible dice rolls for air units)
        //may not need dice rolls at 2 or 6 until air is listed to hit at 2 or 6.
        $index = array(1, 3, 4, 5);
        foreach ($index as $v) {
            if (array_key_exists($v, $airdvals["norm"]["dice"]) && array_key_exists($v, $dvals["norm"]["dice"])) {
                $dvals["norm"]["dice"][$v] = array_merge($airdvals["norm"]["dice"][$v], $dvals["norm"]["dice"][$v]);
            } elseif (array_key_exists($v, $airdvals["norm"]["dice"])) {
                $dvals["norm"]["dice"][$v] = $airdvals["norm"]["dice"][$v];
            }
        }
        ksort($dvals["norm"]["dice"]);
    }
    return array('att' => array('force' => $aforce, 'lost' => $alost, 'vals' => $avals), 'def' => array('force' => $dforce, 'lost' => $dlost, 'vals' => $dvals));
}
예제 #2
0
파일: index.php 프로젝트: Techdojo/AACalc
     $def[$t]['force'] = $outcome['def']['force'];
     $astats = assess($att[$t]['force'], 'attack');
     $dstats = assess($def[$t]['force'], 'defend');
     $abort = ($astats['count'] - round(($dstats['punch'] + 3) / 6) < $saveunits && $saveunits > 0 or $dstats['count'] - round(($astats['punch'] + 3) / 6) < $strafeunits && $strafeunits > 0 or $dstats['punch'] > 0 and $astats['punch'] / $dstats['punch'] * 100 < $abortratio);
     if (!$stalemate) {
         if (!has_sea($def[$t]['force']) && (!nonsubs($att[$t]['force']) or isset($_REQUEST['asubschicken'])) && has_sub($att[$t]['force'])) {
             $submerged['att'] = array();
             if (isset($att[$t]['force']['Sub'])) {
                 $submerged['att']['Sub'] = $att[$t]['force']['Sub'];
             }
             if (isset($att[$t]['force']['SSub'])) {
                 $submerged['att']['SSub'] = $att[$t]['force']['SSub'];
             }
             $att[$t]['force'] = submerge($att[$t]['force']);
         } else {
             if (!has_sea($att[$t]['force']) && (!nonsubs($def[$t]['force']) or isset($_REQUEST['dsubschicken'])) && has_sub($def[$t]['force'])) {
                 $submerged['def'] = array();
                 if (isset($def[$t]['force']['Sub'])) {
                     $submerged['def']['Sub'] = $def[$t]['force']['Sub'];
                 }
                 if (isset($def[$t]['force']['SSub'])) {
                     $submerged['def']['SSub'] = $def[$t]['force']['SSub'];
                 }
                 $def[$t]['force'] = submerge($def[$t]['force']);
             }
         }
     }
 }
 // Battle has been resolved
 //Note that bombarding Battleships, Cruisers, and Destroyers are also tracked in $submerged.
 if (isset($submerged['att']['Sub']) or isset($submerged['att']['SSub'])) {