コード例 #1
0
ファイル: functions.php プロジェクト: Techdojo/AACalc
function getformdata($posted)
{
    global $options, $canhit, $rounds, $sides, $ool, $baseool, $mustland, $round, $abortratio, $unitspecs;
    $customOOL = array();
    $valid = true;
    $options['tech'] = (isset($_REQUEST['toggletechs']) && $_REQUEST['toggletechs'] == "Enable techs" or isset($_REQUEST['techs']) && (!isset($_REQUEST['toggletechs']) or $_REQUEST['toggletechs'] !== 'Disable techs'));
    #debugarray ($options);
    if ($options['tech']) {
        $units = allunits();
    } else {
        $units = notechunits();
    }
    /* DO NOT NEED IF NOT STORING GAMES ANYMORE?
    	#validate gameid:
    	#$gameid=$_REQUEST['gameid'];
    	
    	if ($gameid!=='') {
    		#$gameid=intval($gameid);
    		#if (strval($gameid)!==$_REQUEST['gameid']) {
    		#	echo 'No non-numeric characters permitted in Game ID #<p>';
    		#	$gameid='';
    		#} else
    		$options['gameidok']=false;
    		if (!file_exists('makegame/games/'.$gameid.'.php')) {
    			echo "No record exists for game ID # $gameid.<p>";
    			$gameid='';
    		} else if ($_REQUEST['territory']=='' or $_REQUEST['turnid']=='') {
    			echo "<div style=\"color: red\"><b>Error:</b> You must specify a territory and a Turn ID for the game record.</div>";
    			$_REQUEST['pbem']='';
    		} else { #Game ID is valid and file exists
    			include ('makegame/games/'.$gameid.'.php');
    			if ($_REQUEST['password']==$data['password']) {
    				$_REQUEST['ruleset']=$data['ruleset'];
    				$_REQUEST['luck']=$data['luck'];
    				if (isset ($_REQUEST['pbem']) && strlen($_REQUEST['pbem']) > 6 ) { # User has entered a game id but also entered e-mail addresses 
    					$_REQUEST['pbem']=str_replace (array($data['player1'],$data['player2']), '', $_REQUEST['pbem']).' '.$data['player1'].' '.$data['player2'];
    					#Previous line strips out the e-mail addresses from the pbem field that are already saved in game ID.
    				} else {				
    					$_REQUEST['pbem']=$data['player1'].' '.$data['player2']; # This line preloads the saved e-mail addresses.
    				}
    				$_REQUEST['reps']=1;
    				$_REQUEST['gameid']=$gameid;
    				$turnid=$_REQUEST['turnid'];
    				$options['gameidok']=true;
    			} else { 
    				echo "The password provided did not match.<p>";
    				$_REQUEST['gameid']='';
    			}
    		}
    	}
    	*/
    /* OLD OPTIONS FOR OTHER RULESETS...SHOULD BE PUT IN THE UPDATEUNITS FUNCTION IF WE WANT BACK IN
    	if (isset($_REQUEST['ruleset'])) {
    		if 	($_REQUEST['ruleset'] == 'LHTR' ) {
    			#$unitspecs['HBom']['attack']=5.33;
    			$unitspecs['SSub']['defend']=3;
    			$unitspecs['HBom']['attackdice']=1;
    			if ($_REQUEST['luck']!=='pure') $unitspecs['HBom']['attack']=5.33;
    			#debug ($_REQUEST['luck']);
    		}
    		if ($_REQUEST['ruleset'] == 'Europe' ) {
    			$unitspecs['Fig']['cost']=12;
    			$unitspecs['Arm']['defend']=2;
    			$unitspecs['Car']['cost']=18;
    		}
    	}*/
    if (isset($_REQUEST['round'])) {
        $round = intval($_REQUEST['round']);
    }
    foreach ($sides as $side => $name) {
        $string = trim($_REQUEST['ool_' . $side]);
        $string = str_replace(' ', '-', $string);
        $replacechars = array('  ', ' ', ',', '.', '<', '>', '?', '/', '\\', '!');
        $string = str_replace($replacechars, '', $string);
        $array = explode('-', $string);
        //find if any elements are missing or changed names
        foreach ($baseool as $type) {
            if (!in_array($type, $array)) {
                $valid = false;
            }
        }
        //find if number of elements is the the same
        if (count($array) !== count($baseool)) {
            $valid = false;
        }
        $customOOL[$side] = $array;
    }
    if ($valid) {
        $ool = $customOOL;
        $warned = false;
        foreach ($sides as $side => $name) {
            //prevent battleships being killed first if Classic ruleset used and Bat's listed first in OOL
            if ($_REQUEST['ruleset'] == 'Classic' && $ool[$side][0] == 'Bat') {
                #debug ("Saving $side's battleships!");
                if (!$warned) {
                    echo "<b>Notice:</b> OOL adjusted to prevent battleships being killed first.";
                }
                $warned = true;
            }
            $string = implode('-', $ool[$side]);
            #setcookie ('ool_'.$side, $string, +31536000);
        }
    } else {
        echo "<p><strong>Error</strong> - elements in the custom Order of Loss should be separated only by dashes.\n\t\t\tThe elements themselves should not be edited, deleted or added to.</p>";
    }
    $mustland = 0;
    if (isset($_REQUEST['mustland']) && $_REQUEST['mustland'] !== '' && !isset($_REQUEST['Clear'])) {
        $_REQUEST['mustland'] = intval($_REQUEST['mustland']);
        $mustland = $_REQUEST['mustland'];
    }
    $abortratio = intval($_REQUEST['abortratio']);
    if ($abortratio > 1000 or $abortratio < 1) {
        $abortratio = 0;
    }
    $options['legal'] = false;
    $_REQUEST['reps'] = intval($_REQUEST['reps']);
    $options['AA'] = (isset($_REQUEST['AA']) or isset($_REQUEST['AAr']));
    $_REQUEST['pbem'] = str_replace(array(',', ';'), ' ', $_REQUEST['pbem']);
    $_REQUEST['pbem'] = explode(' ', $_REQUEST['pbem']);
    foreach ($_REQUEST['pbem'] as $key => $val) {
        if (!valid_email($val)) {
            unset($_REQUEST['pbem'][$key]);
        }
    }
    if ($_REQUEST['reps'] > 1 && ($_REQUEST['luck'] == 'none' or $_REQUEST['battle'] == 'Evaluate units')) {
        echo '<p><strong>Note:</strong> in No Luck mode or Evaluate Units mode, every battle turns out the same
			(so not much point running it 1000x). Battle has only been run once.</p>';
        $_REQUEST['reps'] = 1;
    }
    foreach ($posted as $key => $value) {
        if ((!isset($value) or $value == '') && $key !== 'rounds') {
            $posted[$key] = 0;
        } else {
            $posted[$key] = intval($value);
        }
    }
    $forces = array('att' => array(), 'def' => array());
    foreach ($units as $type) {
        if ($posted['a' . $type] > 0) {
            $forces['att'][$type] = $posted['a' . $type];
        }
        if ($posted['d' . $type] > 0) {
            $forces['def'][$type] = $posted['d' . $type];
        }
    }
    //check that both sides have units:
    $options['nounits'] = count($forces['att']) == 0 && count($forces['def']) == 0;
    if (!$options['nounits']) {
        //seabattle boolean conditions. check if seabattle or not.
        $options['seabattle'] = (has_sea($forces['def']) or has_sea($forces['att'])) && !has_land($forces['att']) && !has_land($forces['def']) && !isset($forces['def']['Bom']) && !isset($forces['def']['HBom']);
        //landbattle boolean must also be set to true if a shore bombardment is possible
        $options['landbattle'] = (has_land($forces['def']) or has_land($forces['att']) or has_air($forces['def']) or has_air($forces['att']));
        if (isset($forces['att']['Bat'])) {
            $options['landbattle'] = $options['landbattle'] && has_land($forces['att']);
        }
        //if AA50 or AA1942, add Des as invalid attacker and Cru as valid attacker into landbattle option
        if ($_REQUEST['ruleset'] == 'AA50' || $_REQUEST['ruleset'] == 'AA1942') {
            if (isset($forces['att']['Cru'])) {
                $options['landbattle'] = $options['landbattle'] && has_land($forces['att']);
            }
            $options['landbattle'] = $options['landbattle'] && !isset($forces['att']['Des']);
        }
        //if Revised, add Des as valid attacker into landbattle option -- No need to address Cru since it's not on Revised form
        if ($_REQUEST['ruleset'] == 'Revised') {
            if (isset($forces['att']['Des'])) {
                $options['landbattle'] = $options['landbattle'] && has_land($forces['att']);
            }
        }
        //no need to address Cru and Des in Classic either since they are not on the Classic form now
        //finish list of requirements for landbattle to not include any of the following
        $options['landbattle'] = $options['landbattle'] && !has_sea($forces['def']) && !isset($forces['att']['Tra']) && !isset($forces['att']['Sub']) && !isset($forces['att']['SSub']) && !isset($forces['att']['Car']) && !isset($forces['att']['dBat']);
        // check if attacker has combined standard and upgraded units of the same class:
        $illegalattackcomb = (isset($forces['att']['Art']) && isset($forces['att']['AArt']) or isset($forces['att']['Bom']) && isset($forces['att']['HBom']) or isset($forces['att']['Fig']) && isset($forces['att']['JFig']) or isset($forces['att']['Sub']) && isset($forces['att']['SSub']));
        $options['legal'] = $options['landbattle'] + $options['seabattle'] !== 2 && $options['landbattle'] + $options['seabattle'] !== 0 && $illegalattackcomb == false;
    }
    return $forces;
}
コード例 #2
0
ファイル: form.php プロジェクト: Techdojo/AACalc
        echo ' class="noshow"/><span id="txtAAr" class="noshow">AA radar</span><br /><br />';
    }
} else {
    echo ' class="noshow"/><span id="txtAAr" class="noshow">AA radar</span><br /><br />';
}
echo '			<input type="submit" name="battle" value="Evaluate units" /><br />
				<input type="submit" name="battle" value="Swap units" /> <br />
				<input type="submit" name="Clear" value="Clear units/OOLs" /><br />
';
$units = allunits();
if ($tech) {
    echo '<input type="submit" id="toggletechs" name="toggletechs" value="Disable techs" />
	<input type="hidden" name="techs" value="on" />';
} else {
    echo '<input type="submit" id="toggletechs" name="toggletechs" value="Enable techs" />';
    $units = notechunits();
}
#debugarray ($units);
echo '		</td>
		</tr>
		<tr style="font-size: 55%; text-align: center;"> 
			<td>&nbsp;</td>
';
//set class suffix to change colors and units for rulesets on PHP-side generated form
$className = '';
if (isset($_REQUEST['ruleset'])) {
    if ($_REQUEST['ruleset'] == 'Classic') {
        $className = 'cla';
    }
    if ($_REQUEST['ruleset'] == 'Revised') {
        $className = 'rev';