function DoTask() { global $Administrator, $GAME; if (!$Administrator) { $mypage = page::standard(); $mypage->title_body('Not authorised'); $mypage->leaf('p', 'You are not authorised to make use of this page. Please click <a href="board.php?GameID=' . $GAME['GameID'] . '">here</a> to go to the board page, or <a href="index.php">here</a> to return to the Main Page.'); $mypage->finish(); } $thenumber = sanitise_int(@$_POST['thenumber']); if ($thenumber < -9 or $thenumber > 99 or $thenumber == 0) { $mypage = page::standard(); $mypage->title_body('Invalid input'); $mypage->leaf('p', 'Expected a nonzero integer between -9 and 99 inclusive, but received ' . $thenumber . '. Please click <a href="board.php?GameID=' . $GAME['GameID'] . '">here</a> to go to the board page, or <a href="index.php">here</a> to return to the Main Page.'); $mypage->finish(); } $interval = sanitise_enum(@$_POST['theinterval'], array('MINUTE', 'HOUR', 'DAY')); if (@$_POST['whattime'] == 'now') { $whattime = 'UTC_TIMESTAMP()'; } else { $whattime = '"LastMove"'; } $time_expr = 'TIMESTAMPADD(' . $interval . ', :thenumber:, ' . $whattime . ')'; dbquery(DBQUERY_WRITE, 'UPDATE "Game" JOIN "GameInProgress" ON "Game"."GameID" = "GameInProgress"."Game" SET "Game"."LastMove" = ' . $time_expr . ', "GameInProgress"."GIPLastMove" = ' . $time_expr . ' "Game"."GameTicker" = CONCAT("Game"."GameTicker", :tickerconcat:), "Game"."GameTickerNames" = CONCAT("Game"."GameTickerNames", :namesconcat:) WHERE "GameID" = :game:', 'thenumber', $thenumber, 'tickerconcat', '3A' . callmovetimediff() . letter_end_number($_SESSION['MyUserID']) . letter_end_number($_SESSION['MyGenderCode']), 'namesconcat', '|' . $_SESSION['MyUserName'], 'game', $GAME['GameID']); dbquery(DBQUERY_COMMIT); page::redirect(3, 'board.php?GameID=' . $GAME['GameID'], 'Successfully altered clock.'); }
function DoTask() { global $GAME; if ($GAME['GameStatus'] != 'In Progress' and $GAME['GameStatus'] != 'Recruiting Replacement' or !$GAME['PlayersMissingThatMatter']) { $mypage = page::standard(); $mypage->title_body('No replacements needed'); $mypage->leaf('p', 'No replacement players are needed for this game at the moment. (Perhaps something happened after you loaded the board page.) Please click <a href="board.php?GameID=' . $GAME['GameID'] . '">here</a> to go to the board page, or <a href="index.php">here</a> to return to the Main Page.'); $mypage->finish(); } $mycol = dbquery(DBQUERY_READ_SINGLEROW, 'SELECT "Colour" FROM "ReplacementOffer" WHERE "Game" = :game: AND "User" = :user:'******'game', $GAME['GameID'], 'user', $_SESSION['MyUserID']); if ($mycol === 'NONE') { $mypage = page::standard(); $mypage->title_body('Not currently a candidate replacement'); $mypage->leaf('p', 'You are not currently a candidate replacement. You might be seeing this message because you clicked the button twice. Please click <a href="board.php?GameID=' . $GAME['GameID'] . '">here</a> to go to the board page, or <a href="index.php">here</a> to return to the Main Page.'); $mypage->finish(); } dbquery(DBQUERY_WRITE, 'DELETE FROM "ReplacementOffer" WHERE "Game" = :game: AND "User" = :user:'******'game', $GAME['GameID'], 'user', $_SESSION['MyUserID']); if ($mycol['Colour'] == $GAME['PlayerToMove']) { $GAME['AltGameTicker'] .= '8F' . callmovetimediff() . letter_end_number($_SESSION['MyUserID']) . letter_end_number($_SESSION['MyGenderCode']); $GAME['GameTickerNames'] .= '|' . $_SESSION['MyUserName']; dbformatgamedata(); } else { dbquery(DBQUERY_COMMIT); } page::redirect(3, 'board.php?GameID=' . $GAME['GameID'], 'Successfully withdrew request.'); }
function callmovetimediff() { global $GAME; $tempvar = $GAME['movetimediff']; $GAME['movetimediff'] = 0; $GAME['LastEventSQL'] = ', "GameInProgress"."LastEvent" = \'' . date(MYSQL_DATETIME_FORMAT) . '\''; return letter_end_number($tempvar); }
function DoTask() { global $Administrator, $GAME, $unexpectederrormessage; if ($GAME['GameStatus'] != 'Recruiting Replacement') { $mypage = page::standard(); $mypage->title_body('Current player is not missing'); $mypage->leaf('p', 'The current player is not missing. (Perhaps somebody accepted a replacement player after you had loaded the board page.) Please click <a href="board.php?GameID=' . $GAME['GameID'] . '">here</a> to go to the board page, or <a href="index.php">here</a> to return to the Main Page.'); $mypage->finish(); } if ($GAME['MyColour'] == 50) { $mypage = page::standard(); $mypage->title_body('Not playing in this game'); $mypage->leaf('p', 'You are not currently playing in this game, so you cannot choose replacement players. Please click <a href="board.php?GameID=' . $GAME['GameID'] . '">here</a> to go to the board page, or <a href="index.php">here</a> to return to the Main Page.'); $mypage->finish(); } $ReplacementValid = false; for ($i = 0; $i < count($GAME['ReplacementOffers']); $i++) { if ($GAME['ReplacementOffers'][$i][2] == $GAME['PlayerToMove'] and $GAME['ReplacementOffers'][$i][0] == @$_POST['whotoaccept']) { $ReplacementValid = $i; } } if ($ReplacementValid === false) { $mypage = page::standard(); $mypage->title_body('User ID not found among replacements'); $mypage->leaf('p', 'The submitted user ID was not found among the candidate replacements. (Perhaps the user withdrew his request after you had loaded the board page.) Please click <a href="board.php?GameID=' . $GAME['GameID'] . '">here</a> to go to the board page, or <a href="index.php">here</a> to return to the Main Page.'); $mypage->finish(); } $QR = dbquery(DBQUERY_READ_SINGLEROW, 'SELECT "Name", "Pronoun", "Email", "EmailPrompt" FROM "User" WHERE "UserID" = :user:'******'user', $GAME['ReplacementOffers'][$ReplacementValid][0]); if ($QR === 'NONE') { myerror($unexpectederrormessage, 'Candidate replacements list contains invalid user'); } switch ($QR['Pronoun']) { case 'He': $RepPronoun = 'A'; break; case 'She': $RepPronoun = 'B'; break; default: $RepPronoun = 'C'; break; } $GAME['AltGameTicker'] .= '8E' . callmovetimediff() . letter_end_number($GAME['ReplacementOffers'][$ReplacementValid][0]) . $RepPronoun . letter_end_number($GAME['MyColour']); $GAME['GameTickerNames'] .= '|' . $GAME['ReplacementOffers'][$ReplacementValid][1]; $GAME['PlayerName'][$GAME['PlayerToMove']] = $QR['Name']; $GAME['KickVote'] = '00000'; $GAME['GameStatus'] = 'In Progress'; $GAME['MoveMade'] = 1; dbquery(DBQUERY_WRITE, 'DELETE FROM "ReplacementOffer" WHERE "Game" = :game: AND "Colour" = :colour:', 'game', $GAME['GameID'], 'colour', $GAME['PlayerToMove']); dbquery(DBQUERY_WRITE, 'INSERT INTO "PlayerGameRcd" ("User", "Game", "GameResult", "Inherited", "GameCounts", "Colour", "NumLongTurns", "CurrentOccupant") VALUES (:user:, :game:, \'Playing\', 1, :counts:, :colour:, 0, 0)', 'user', $GAME['ReplacementOffers'][$ReplacementValid][0], 'game', $GAME['GameID'], 'counts', $GAME['ReplacementOffers'][$ReplacementValid][3], 'colour', $GAME['PlayerToMove']); dbformatgamedata(); if ($QR['EmailPrompt'] and $QR['Email'] != '') { $subject = 'Your request to join game number ' . $GAME['GameID'] . ' has been accepted'; $body = '<p>This is an automated message. One of the players in game number ' . $GAME['GameID'] . ' has accepted your request to join the game as a replacement player. This means that it is now your turn to move; please visit the game\'s page and take your turn. Here is the URL of the game page:</p><p><a href="' . SITE_ADDRESS . 'board.php?GameID=' . $GAME['GameID'] . '">' . SITE_ADDRESS . 'board.php?GameID=' . $GAME['GameID'] . '</a></p>' . EMAIL_FOOTER; send_email($subject, $body, $QR['Email'], null); } page::redirect(3, 'board.php?GameID=' . $GAME['GameID'], 'Successfully accepted replacement.'); }
function DoTask() { global $Administrator, $GAME, $unexpectederrormessage; if (!$Administrator) { $mypage = page::standard(); $mypage->title_body('Not authorised'); $mypage->leaf('p', 'You are not authorised to make use of this page. Please click <a href="board.php?GameID=' . $GAME['GameID'] . '">here</a> to go to the board page, or <a href="index.php">here</a> to return to the Main Page.'); $mypage->finish(); } $EscapedComment = sanitise_str(@$_POST['AdminComment'], STR_GPC | STR_STRIP_TAB_AND_NEWLINE); $EscapedComment = str_replace(array('|', '"'), array('', ''), $EscapedComment); $EscapedComment = htmlspecialchars($EscapedComment); if ($EscapedComment == '') { $mypage = page::standard(); $mypage->title_body('Comment is missing'); $mypage->leaf('p', 'The coment you entered is missing. Please click <a href="board.php?GameID=' . $GAME['GameID'] . '">here</a> to go to the board page, or <a href="index.php">here</a> to return to the Main Page.'); $mypage->finish(); } dbquery(DBQUERY_WRITE, 'UPDATE "Game" SET "GameTicker" = CONCAT("GameTicker", :tickerconcat:), "GameTickerNames" = CONCAT("GameTickerNames", :namesconcat:) WHERE "GameID" = :game:', 'tickerconcat', '3B' . callmovetimediff() . letter_end_number($_SESSION['MyUserID']) . letter_end_number($_SESSION['MyGenderCode']), 'namesconcat', '|' . $_SESSION['MyUserName'] . '|' . $EscapedComment, 'game', $GAME['GameID']); dbquery(DBQUERY_COMMIT); page::redirect(3, 'board.php?GameID=' . $GAME['GameID'], 'Successfully added comment.'); }
function CheckNoMovesShell() { global $GAME; while (CheckNoMoves(99)) { $GAME['AltGameTicker'] .= '9H' . letter_end_number($GAME['carddetailarrayb'][$GAME['Cards'][$GAME['PlayerToMove']][0]]) . letter_end_number($GAME['carddetailarrayb'][$GAME['Cards'][$GAME['PlayerToMove']][1]]); $GAME['DiscardPile'][] = array_pop($GAME['Cards'][$GAME['PlayerToMove']]); $GAME['DiscardPile'][] = array_pop($GAME['Cards'][$GAME['PlayerToMove']]); $GAME['HandSize'][$GAME['PlayerToMove']] = 0; $GAME['AltGameTicker'] .= 'A'; for ($i = 0; $i < MAX_PLAYERS; $i++) { if ($GAME['TurnOrder'][$i] == $GAME['PlayerToMove']) { $WhereInTurnOrder = $i; } } $EndRound = true; for ($i = MAX_PLAYERS - 1; $i > $WhereInTurnOrder; $i--) { if ($GAME['PlayerExists'][$GAME['TurnOrder'][$i]]) { $GAME['PlayerToMove'] = $GAME['TurnOrder'][$i]; $EndRound = false; } } if ($EndRound) { require_once HIDDEN_FILES_PATH . 'scoringresource.php'; endgamescoring(); break; } } }
function develop($tiletype, $ironsource, $continuing, $thecard) { global $GAME, $SystemActing; $errorlist = ''; if (!$GAME['RemainingTiles'][$tiletype][$GAME['PlayerToMove']]) { $errorlist = transtext('memOutOfTiles') . '<br>'; // "You have run out of industry tiles of the chosen type." } if ($ironsource == 50 and $GAME['Money'][$GAME['PlayerToMove']] < $GAME['cubeprice'][$GAME['IronDemand']]) { $errorlist = transtext('memDevPoor') . '<br>'; // "You cannot develop, as you cannot afford the iron cube." } switch ($ironsource) { case 90: $errorlist .= transtext('memIronNotValid') . '<br>'; break; // "The selected source of iron is not valid." // "The selected source of iron is not valid." case 91: $errorlist .= transtext('memIronOnBoard') . '<br>'; break; // "You cannot buy iron from the Demand Track, // as there is iron available on the board for you to use." } if ($ironsource == 50) { $altironsource = 99; } else { $altironsource = $ironsource; } if ($errorlist == '') { $GAME['RemainingTiles'][$tiletype][$GAME['PlayerToMove']]--; if ($ironsource == 50) { $GAME['Money'][$GAME['PlayerToMove']] -= $GAME['cubeprice'][$GAME['IronDemand']]; $GAME['AmountSpent'][$GAME['PlayerToMove']] += $GAME['cubeprice'][$GAME['IronDemand']]; if ($GAME['CurrentPlayers'] == 2 and $GAME['IronDemand'] < 6 or $GAME['CurrentPlayers'] > 2 and $GAME['IronDemand'] < 8) { $GAME['IronDemand']++; } } else { $GAME['IronInLancs']--; $GAME['SpaceCubes'][$ironsource] = $GAME['SpaceCubes'][$ironsource] - 1; // This is written in this way because SpaceCubes is a string consisting of digits // (it is not legal to use increment/decrement operators on string offsets). if (!$GAME['SpaceCubes'][$ironsource]) { fliptile($ironsource); } } if ($SystemActing) { $AdminTakingMove = 0; } else { if ($GAME['PlayerUserID'][$GAME['PlayerToMove']] == $_SESSION['MyUserID']) { $AdminTakingMove = 0; } else { $AdminTakingMove = 1; } } if ($continuing) { if ($AdminTakingMove) { $altgoodoutput = '2D' . callmovetimediff() . letter_end_number($_SESSION['MyUserID']) . letter_end_number($_SESSION['MyGenderCode']) . letter_end_number($tiletype) . letter_end_number($altironsource); $altgoodoutputName = '|' . $_SESSION['MyUserName']; } else { $altgoodoutput = 'I' . callmovetimediff() . letter_end_number($tiletype) . letter_end_number($altironsource); $altgoodoutputName = ''; } $GAME['SecondDevelopMode'] = 0; } else { if ($AdminTakingMove) { $altgoodoutput = '1J' . callmovetimediff() . letter_end_number($_SESSION['MyUserID']) . letter_end_number($_SESSION['MyGenderCode']) . letter_end_number($thecard) . letter_end_number($tiletype) . letter_end_number($altironsource); $altgoodoutputName = '|' . $_SESSION['MyUserName']; } else { $altgoodoutput = 'E' . callmovetimediff() . letter_end_number($thecard) . letter_end_number($tiletype) . letter_end_number($altironsource); $altgoodoutputName = ''; } if ($GAME['RemainingTiles'][0][$GAME['PlayerToMove']] or $GAME['RemainingTiles'][1][$GAME['PlayerToMove']] or $GAME['RemainingTiles'][2][$GAME['PlayerToMove']] or $GAME['RemainingTiles'][3][$GAME['PlayerToMove']] or $GAME['RemainingTiles'][4][$GAME['PlayerToMove']]) { $CanGetIronFree = false; for ($i = 0; $i < $GAME['NumIndustrySpaces']; $i++) { if ($GAME['SpaceStatus'] != 9 and $GAME['SpaceTile'][$i] == 2 and $GAME['SpaceCubes'][$i]) { $CanGetIronFree = true; } } if (!$CanGetIronFree and $GAME['Money'][$GAME['PlayerToMove']] < $GAME['cubeprice'][$GAME['IronDemand']]) { $altgoodoutput .= '9IA'; } else { $GAME['SecondDevelopMode'] = 1; } } else { $altgoodoutput .= '9IB'; } } } else { $altgoodoutput = ''; $altgoodoutputName = ''; } return array($errorlist, '', $altgoodoutput, $altgoodoutputName); }
function buildtile($wheretobuild, $whattobuild, $coalsource, $ironsource, $card, $doublebuild, $thecardA, $thecardB) { global $GAME, $SystemActing; $errorlist = ''; $TheTechLevel = $GAME['TechLevelArray'][$whattobuild][$GAME['RemainingTiles'][$whattobuild][$GAME['PlayerToMove']]]; $carddetail = $GAME['carddetailarray'][$GAME['Cards'][$GAME['PlayerToMove']][$card]]; if ($coalsource == 50) { $altcoalsource = 99; } else { $altcoalsource = $coalsource; } if ($ironsource == 50) { $altironsource = 99; } else { $altironsource = $ironsource; } if ($TheTechLevel == 9) { $errorlist = transtext('memOutOfTiles') . '<br>'; // "You have run out of industry tiles of the chosen type." } else { if ($GAME['HasBuilt'][$GAME['PlayerToMove']] and !$doublebuild and $GAME['Cards'][$GAME['PlayerToMove']][$card] > $GAME['TopLocationCard'] and !$GAME['HasBuiltInTown'][$GAME['PlayerToMove']][$GAME['spacetowns'][$wheretobuild]] and !$GAME['HasLinkedToTown'][$GAME['PlayerToMove']][$GAME['spacetowns'][$wheretobuild]]) { $CannotBuildHere = true; for ($i = 0; $i < count($GAME['GeneralisedVCs']); $i++) { if ($GAME['spacetowns'][$wheretobuild] == $GAME['GeneralisedVCs'][$i][0] and ($GAME['HasBuiltInTown'][$GAME['PlayerToMove']][$GAME['GeneralisedVCs'][$i][1]] or $GAME['HasLinkedToTown'][$GAME['PlayerToMove']][$GAME['GeneralisedVCs'][$i][1]]) or ($GAME['SpecialRules'] & 1 and $GAME['GeneralisedVCs'][$i][2] or $GAME['GeneralisedVCs'][$i][2] == 2) and $GAME['spacetowns'][$wheretobuild] == $GAME['GeneralisedVCs'][$i][1] and ($GAME['HasBuiltInTown'][$GAME['PlayerToMove']][$GAME['GeneralisedVCs'][$i][0]] or $GAME['HasLinkedToTown'][$GAME['PlayerToMove']][$GAME['GeneralisedVCs'][$i][0]])) { $CannotBuildHere = false; } } if ($CannotBuildHere) { if ($GAME['RailPhase']) { $errorlist .= transtext('memIndyCardBadR') . '<br>'; // "You cannot use an industry card to build in that location, // as you have neither connected to the location nor built a tile there." } else { $errorlist .= transtext('memIndyCardBadC') . '<br>'; // "You cannot use an industry card to build in that location, // as you have not connected to the location." } } } if (!$GAME['SpaceAlwaysExists'][$wheretobuild] and ($GAME['ModularBoardParts'] & $GAME['SpaceExistenceArray'][$wheretobuild]) != $GAME['SpaceExistenceArray'][$wheretobuild]) { $errorlist .= transtext('memSpaceNotThere') . '<br>'; // "That industry space does not exist (or it no longer exists) in this game." } if ($GAME['tileindustries'][$wheretobuild] != $whattobuild and ($whattobuild > 1 or $GAME['tileindustries'][$wheretobuild] != 5) and ($whattobuild and $whattobuild != 3 or $GAME['tileindustries'][$wheretobuild] != 6) and ($whattobuild != 2 and $whattobuild != 3 or $GAME['tileindustries'][$wheretobuild] != 7)) { $errorlist .= transtext('memWrongTileType') . '<br>'; // "The tile that you attempted to build cannot be built in the chosen industry space." } if (!$GAME['RailPhase'] and $GAME['HasBuiltInTown'][$GAME['PlayerToMove']][$GAME['spacetowns'][$wheretobuild]] and $GAME['SpaceStatus'][$wheretobuild] != $GAME['PlayerToMove']) { $errorlist .= transtext('memAlreadyInTown') . '<br>'; // "You have already built an industry tile in that location." } $StrategicBlockAttempt = false; for ($i = 0; $i < count($GAME['GeneralisedNoStratBlock']); $i++) { if ($whattobuild == $GAME['GeneralisedNoStratBlock'][$i][0] and $GAME['SpaceStatus'][$GAME['GeneralisedNoStratBlock'][$i][1]] == 9 and $wheretobuild == $GAME['GeneralisedNoStratBlock'][$i][2]) { $StrategicBlockAttempt = true; } } if ($StrategicBlockAttempt) { $errorlist .= transtext('memTacticalBlock') . '<br>'; } if ($GAME['SpaceStatus'][$wheretobuild] != 9 and $GAME['SpaceTile'][$wheretobuild] != $whattobuild) { $errorlist .= transtext('memOvrSameType') . '<br>'; } if ($GAME['SpaceStatus'][$wheretobuild] != 9 and $GAME['TechLevels'][$wheretobuild] >= $TheTechLevel) { $errorlist .= transtext('memOvrTechLevel') . '<br>'; } if ($GAME['SpaceStatus'][$wheretobuild] == 8 and !$GAME['SpaceTile'][$wheretobuild]) { $errorlist .= transtext('memOvrCM') . '<br>'; // "You can never build over an opponent's Cotton Mill." // (Prevents building over an orphan Cotton Mill.) } if ($GAME['SpaceStatus'][$wheretobuild] != 9 and $GAME['SpaceStatus'][$wheretobuild] != 8 and $GAME['SpaceStatus'][$wheretobuild] != $GAME['PlayerToMove']) { switch ($GAME['SpaceTile'][$wheretobuild]) { case 0: $errorlist .= transtext('memOvrCM') . '<br>'; // "You can never build over an opponent's Cotton Mill." break; case 1: if ($GAME['CurrentPlayers'] > 2 and $GAME['CoalDemand'] < 8 or $GAME['CurrentPlayers'] == 2 and $GAME['CoalDemand'] < 6 or $GAME['CoalInLancs']) { $errorlist .= transtext('memOvrCoalCubes') . '<br>'; // "You cannot currently build over an opponent's Coal Mine: // the cube scarcity condition is not satisfied." } if ($GAME['SpecialRules'] & 4) { for ($i = 0; $i < $GAME['NumIndustrySpaces']; $i++) { if ($GAME['spacetowns'][$i] == $GAME['spacetowns'][$wheretobuild] and ($GAME['tileindustries'][$i] == 1 or $GAME['tileindustries'][$i] == 5) and $GAME['SpaceStatus'][$i] == 9) { $errorlist .= transtext('memOvrCoalMCOR') . '<br>'; // There is a free space in the same location for a Coal Mine. // You cannot build over your opponent's Coal Mine here. break; } } } break; case 2: if ($GAME['CurrentPlayers'] > 2 and $GAME['IronDemand'] < 8 or $GAME['CurrentPlayers'] == 2 and $GAME['IronDemand'] < 6 or $GAME['IronInLancs']) { $errorlist .= transtext('memOvrIronCubes') . '<br>'; // "You cannot currently build over an opponent's Iron Works: // the cube scarcity condition is not satisfied." } break; case 3: $errorlist .= transtext('memOvrPort') . '<br>'; // "You can never build over an opponent's Port." break; default: $errorlist .= transtext('memOvrShipyard') . '<br>'; // "You can never build over an opponent's Shipyard." } } if (!$doublebuild and $GAME['Cards'][$GAME['PlayerToMove']][$card] <= $GAME['TopLocationCard'] and $carddetail != $GAME['spacetowns'][$wheretobuild]) { $errorlist .= transtext('memLocnCardBad') . '<br>'; // "The space where you attempted to build is not in // the location named on the card that you tried to use." } if ($doublebuild and !$GAME['RailPhase'] and $GAME['Round'] == 1) { $errorlist .= transtext('memFirstTurnDbl') . '<br>'; // "You cannot use two cards to build on the first turn of the game." } if ($doublebuild and $GAME['HandSize'][$GAME['PlayerToMove']] % 2 == 1) { $errorlist .= transtext('mem2ndActionDbl') . '<br>'; // "You cannot use two cards to build for your second action of the turn." } if (!$doublebuild and $GAME['Cards'][$GAME['PlayerToMove']][$card] > $GAME['TopLocationCard'] and $carddetail != $whattobuild) { $errorlist .= transtext('memIndyCardType') . '<br>'; // "The tile that you attempted to build does not match // the industry type of the card that you tried to use." } if (!$GAME['RailPhase'] and $whattobuild == 4 and $TheTechLevel == 2) { $errorlist .= transtext('memTech2Shipyard') . '<br>'; // "You cannot build a Tech Level 2 Shipyard during the Canal Phase." } if ($whattobuild == 4 and $TheTechLevel == 0) { $errorlist .= transtext('memTech0Shipyard') . '<br>'; // "You cannot build a Tech Level 0 Shipyard at any time. // These tiles must be developed away before you can build Shipyards." } if ($GAME['RailPhase'] and $TheTechLevel == 1) { $errorlist .= transtext('memTech1Rails') . '<br>'; // You cannot build a Tech Level 1 industry tile during the Rail Phase. } if ($GAME['Money'][$GAME['PlayerToMove']] < $GAME['TileCosts'][$whattobuild][$TheTechLevel - 1]) { $errorlist .= 'You cannot afford to build that industry tile.<br>'; } else { if ($GAME['TileRequireCoal'][$whattobuild][$TheTechLevel - 1] and $coalsource == 50 and $GAME['Money'][$GAME['PlayerToMove']] < $GAME['TileCosts'][$whattobuild][$TheTechLevel - 1] + $GAME['cubeprice'][$GAME['CoalDemand']] or $GAME['TileRequireIron'][$whattobuild][$TheTechLevel - 1] and $ironsource == 50 and $GAME['Money'][$GAME['PlayerToMove']] < $GAME['TileCosts'][$whattobuild][$TheTechLevel - 1] + $GAME['cubeprice'][$GAME['IronDemand']] or $GAME['TileRequireCoal'][$whattobuild][$TheTechLevel - 1] and $GAME['TileRequireIron'][$whattobuild][$TheTechLevel - 1] and $coalsource == 50 and $ironsource == 50 and $GAME['Money'][$GAME['PlayerToMove']] < $GAME['TileCosts'][$whattobuild][$TheTechLevel - 1] + $GAME['cubeprice'][$GAME['CoalDemand']] + $GAME['cubeprice'][$GAME['IronDemand']]) { $errorlist .= transtext('memTilePoorCubes') . '<br>'; // Although you can afford to build the chosen industry tile, // you cannot afford to buy from the Demand Track(s) the cube(s) needed to build it. } } if ($GAME['TileRequireCoal'][$whattobuild][$TheTechLevel - 1]) { switch ($coalsource) { case 90: $errorlist .= transtext('memCoalNotValid') . '<br>'; break; // "The selected source of coal is not valid." // "The selected source of coal is not valid." case 91: $errorlist .= transtext('memCoalOnBoard') . '<br>'; break; // "You cannot buy coal from the Demand Track, // as there is coal available on the board for you to use." // "You cannot buy coal from the Demand Track, // as there is coal available on the board for you to use." case 92: $errorlist .= transtext('memCoalNearer') . '<br>'; break; case 93: $errorlist .= 'The selected source of coal is not connected to the location where you are trying to build.<br>'; break; case 95: $errorlist .= transtext('memCoalNoPorts') . '<br>'; break; // "You cannot buy coal from the Demand Track, // as the location where you want to build is not connected to a Port." } } if ($GAME['TileRequireIron'][$whattobuild][$TheTechLevel - 1]) { switch ($ironsource) { case 90: $errorlist .= transtext('memIronNotValid') . '<br>'; break; // "The selected source of iron is not valid." // "The selected source of iron is not valid." case 91: $errorlist .= transtext('memIronOnBoard') . '<br>'; break; // "You cannot buy iron from the Demand Track, // as there is iron available on the board for you to use." } } } if ($errorlist == '') { if ($GAME['SpaceStatus'][$wheretobuild] != 9) { destroytile($wheretobuild, 0, 1); } $GAME['HasBuilt'][$GAME['PlayerToMove']] = 1; $GAME['HasBuiltInTown'][$GAME['PlayerToMove']][$GAME['spacetowns'][$wheretobuild]] = 1; $GAME['SpaceStatus'][$wheretobuild] = $GAME['PlayerToMove']; $GAME['SpaceTile'][$wheretobuild] = $whattobuild; $GAME['TechLevels'][$wheretobuild] = $TheTechLevel; $GAME['Money'][$GAME['PlayerToMove']] -= $GAME['TileCosts'][$whattobuild][$TheTechLevel - 1]; $GAME['AmountSpent'][$GAME['PlayerToMove']] += $GAME['TileCosts'][$whattobuild][$TheTechLevel - 1]; $GAME['RemainingTiles'][$whattobuild][$GAME['PlayerToMove']]--; if ($GAME['TileRequireCoal'][$whattobuild][$TheTechLevel - 1]) { if ($coalsource == 50) { $GAME['Money'][$GAME['PlayerToMove']] -= $GAME['cubeprice'][$GAME['CoalDemand']]; $GAME['AmountSpent'][$GAME['PlayerToMove']] += $GAME['cubeprice'][$GAME['CoalDemand']]; if ($GAME['CurrentPlayers'] == 2 and $GAME['CoalDemand'] < 6 or $GAME['CurrentPlayers'] > 2 and $GAME['CoalDemand'] < 8) { $GAME['CoalDemand']++; } } else { $GAME['CoalInLancs']--; $GAME['SpaceCubes'][$coalsource] = $GAME['SpaceCubes'][$coalsource] - 1; // This is written in this way because SpaceCubes is a string consisting of digits // (it is not legal to use increment/decrement operators on string offsets). if (!$GAME['SpaceCubes'][$coalsource]) { fliptile($coalsource); } } } else { $altcoalsource = 98; } if ($GAME['TileRequireIron'][$whattobuild][$TheTechLevel - 1]) { if ($ironsource == 50) { $GAME['Money'][$GAME['PlayerToMove']] -= $GAME['cubeprice'][$GAME['IronDemand']]; $GAME['AmountSpent'][$GAME['PlayerToMove']] += $GAME['cubeprice'][$GAME['IronDemand']]; if ($GAME['CurrentPlayers'] == 2 and $GAME['IronDemand'] < 6 or $GAME['CurrentPlayers'] > 2 and $GAME['IronDemand'] < 8) { $GAME['IronDemand']++; } } else { $GAME['IronInLancs']--; $GAME['SpaceCubes'][$ironsource] = $GAME['SpaceCubes'][$ironsource] - 1; // This is written in this way because SpaceCubes is a string consisting of digits // (it is not legal to use increment/decrement operators on string offsets). if (!$GAME['SpaceCubes'][$ironsource]) { fliptile($ironsource); } } } else { $altironsource = 98; } switch ($whattobuild) { case 0: $GAME['SpaceCubes'][$wheretobuild] = 1; break; case 1: $GAME['SpaceCubes'][$wheretobuild] = $GAME['TileInitialCubes'][0][$TheTechLevel - 1]; $GAME['CoalInLancs'] += $GAME['SpaceCubes'][$wheretobuild]; if ($GAME['HasPort'][$GAME['spacetowns'][$wheretobuild]]) { if ($GAME['CoalDemand'] >= $GAME['SpaceCubes'][$wheretobuild]) { $GAME['CoalInLancs'] -= $GAME['SpaceCubes'][$wheretobuild]; $CoalIncome = 0; for ($i = 0; $i < $GAME['SpaceCubes'][$wheretobuild]; $i++) { $GAME['CoalDemand']--; $CoalIncome += $GAME['cubeprice'][$GAME['CoalDemand']]; } $GAME['SpaceCubes'][$wheretobuild] = 0; fliptile($wheretobuild); } else { $GAME['CoalInLancs'] -= $GAME['CoalDemand']; $GAME['SpaceCubes'][$wheretobuild] = $GAME['TileInitialCubes'][0][$TheTechLevel - 1] - $GAME['CoalDemand']; $oldcoaldemand = $GAME['CoalDemand']; $CoalIncome = 0; for ($i = 0; $i < $oldcoaldemand; $i++) { $GAME['CoalDemand']--; $CoalIncome += $GAME['cubeprice'][$GAME['CoalDemand']]; } } if ($CoalIncome) { $GAME['Money'][$GAME['PlayerToMove']] += $CoalIncome; $altcoalsource = 97; } } break; case 2: $GAME['SpaceCubes'][$wheretobuild] = $GAME['TileInitialCubes'][1][$TheTechLevel - 1]; $GAME['IronInLancs'] += $GAME['SpaceCubes'][$wheretobuild]; if ($GAME['IronDemand'] >= $GAME['SpaceCubes'][$wheretobuild]) { $GAME['IronInLancs'] -= $GAME['SpaceCubes'][$wheretobuild]; $IronIncome = 0; for ($i = 0; $i < $GAME['SpaceCubes'][$wheretobuild]; $i++) { $GAME['IronDemand']--; $IronIncome += $GAME['cubeprice'][$GAME['IronDemand']]; } $GAME['SpaceCubes'][$wheretobuild] = 0; fliptile($wheretobuild); } else { $GAME['IronInLancs'] -= $GAME['IronDemand']; $GAME['SpaceCubes'][$wheretobuild] = $GAME['TileInitialCubes'][1][$TheTechLevel - 1] - $GAME['IronDemand']; $oldirondemand = $GAME['IronDemand']; $IronIncome = 0; for ($i = 0; $i < $oldirondemand; $i++) { $GAME['IronDemand']--; $IronIncome += $GAME['cubeprice'][$GAME['IronDemand']]; } } if ($IronIncome) { $GAME['Money'][$GAME['PlayerToMove']] += $IronIncome; $altironsource = 97; } break; case 3: for ($i = 0; $i < $GAME['NumTowns']; $i++) { if ($GAME['CoalNet'][$i] == $GAME['CoalNet'][$GAME['spacetowns'][$wheretobuild]]) { $GAME['HasPort'][$i] = 1; } } $GAME['SpaceCubes'][$wheretobuild] = 1; break; case 4: fliptile($wheretobuild); } if ($SystemActing) { $AdminTakingMove = 0; } else { if ($GAME['PlayerUserID'][$GAME['PlayerToMove']] == $_SESSION['MyUserID']) { $AdminTakingMove = 0; } else { $AdminTakingMove = 1; } } if ($doublebuild) { $dbcard = letter_end_number($thecardB); $actionnuma = '1H'; $actionnumb = 'C'; } else { $dbcard = ''; $actionnuma = '1G'; $actionnumb = 'B'; } if ($AdminTakingMove) { $altgoodoutput = $actionnuma . callmovetimediff() . letter_end_number($_SESSION['MyUserID']) . letter_end_number($_SESSION['MyGenderCode']) . letter_end_number($thecardA) . $dbcard . letter_end_number($whattobuild) . letter_end_number($wheretobuild) . letter_end_number($altcoalsource) . letter_end_number($altironsource); $altgoodoutputName = '|' . $_SESSION['MyUserName']; } else { $altgoodoutput = $actionnumb . callmovetimediff() . letter_end_number($thecardA) . $dbcard . letter_end_number($whattobuild) . letter_end_number($wheretobuild) . letter_end_number($altcoalsource) . letter_end_number($altironsource); $altgoodoutputName = ''; } } else { $altgoodoutput = ''; $altgoodoutputName = ''; } return array($errorlist, '', $altgoodoutput, $altgoodoutputName); }
function buildlink($linktobuild, $coalsource, $buildnum, $thecard) { global $GAME, $SystemActing; $errorlist = ''; if ($GAME['LinkStatus'][$linktobuild] != 9) { if ($GAME['RailPhase']) { $errorlist .= transtext('memRailBuilt') . '<br>'; } else { $errorlist .= transtext('memCanalBuilt') . '<br>'; } // "The chosen rail/canal link has already been built." } if ($GAME['RailPhase']) { if (!$GAME['RailAlwaysExists'][$linktobuild] and ($GAME['ModularBoardParts'] & $GAME['RailExistenceArray'][$linktobuild]) != $GAME['RailExistenceArray'][$linktobuild]) { $errorlist .= transtext('memRailNotThere') . '<br>'; // "That rail link does not exist (or it no longer exists) in this game." } if (!$GAME['HasBuiltInTown'][$GAME['PlayerToMove']][$GAME['RailStarts'][$linktobuild]] and !$GAME['HasBuiltInTown'][$GAME['PlayerToMove']][$GAME['RailEnds'][$linktobuild]] and !$GAME['HasLinkedToTown'][$GAME['PlayerToMove']][$GAME['RailStarts'][$linktobuild]] and !$GAME['HasLinkedToTown'][$GAME['PlayerToMove']][$GAME['RailEnds'][$linktobuild]]) { $errorlist .= transtext('memRailNotConn') . '<br>'; // "You cannot build that rail link, as you have neither connected to nor built in either location." } switch ($coalsource) { case 90: $errorlist .= transtext('memCoalNotValid') . '<br>'; break; // "The selected source of coal is not valid." // "The selected source of coal is not valid." case 91: $errorlist .= transtext('memCoalOnBoard') . '<br>'; break; // "You cannot buy coal from the Demand Track, // as there is coal available on the board for you to use." // "You cannot buy coal from the Demand Track, // as there is coal available on the board for you to use." case 92: $errorlist .= transtext('memCoalNearer') . '<br>'; break; case 93: $errorlist .= 'The selected source of coal is not connected to the location where you are trying to build.<br>'; break; case 95: $errorlist .= transtext('memCoalNoPorts') . '<br>'; break; // "You cannot buy coal from the Demand Track, // as the location where you want to build is not connected to a Port." } } else { if (!$GAME['CanalAlwaysExists'][$linktobuild] and ($GAME['ModularBoardParts'] & $GAME['CanalExistenceArray'][$linktobuild]) != $GAME['CanalExistenceArray'][$linktobuild]) { $errorlist .= transtext('memCanalNotThere') . '<br>'; // That canal link does not exist (or it no longer exists) in this game. } if (!$GAME['HasBuiltInTown'][$GAME['PlayerToMove']][$GAME['CanalStarts'][$linktobuild]] and !$GAME['HasBuiltInTown'][$GAME['PlayerToMove']][$GAME['CanalEnds'][$linktobuild]] and !$GAME['HasLinkedToTown'][$GAME['PlayerToMove']][$GAME['CanalStarts'][$linktobuild]] and !$GAME['HasLinkedToTown'][$GAME['PlayerToMove']][$GAME['CanalEnds'][$linktobuild]]) { $errorlist .= transtext('memCanalNotConn') . '<br>'; // "You cannot build that canal link, as you have neither connected to nor built in either location." } } $MoneyWarning = true; if (!$GAME['RailPhase'] and $GAME['Money'][$GAME['PlayerToMove']] < 3) { $errorlist .= transtext('memCanalPoor') . '<br>'; // "You cannot afford to build a canal link." } if ($GAME['RailPhase'] and $GAME['Money'][$GAME['PlayerToMove']] < 5) { $MoneyWarning = false; $errorlist .= transtext('memRailPoor') . '<br>'; // "You cannot afford to build a rail link." } if ($GAME['RailPhase'] and $MoneyWarning and $coalsource == 50 and $GAME['Money'][$GAME['PlayerToMove']] < 5 * $buildnum + $GAME['cubeprice'][$GAME['CoalDemand']]) { $errorlist .= transtext('memRailPoorCoal') . '<br>'; // "Although you can afford to build a rail link, you cannot afford // to buy from the Demand Track the coal cube needed to build it." } if (!$GAME['RemainingTiles'][5][$GAME['PlayerToMove']]) { if ($GAME['RailPhase']) { $errorlist .= transtext('memOutOfRails') . '<br>'; } else { $errorlist .= transtext('memOutOfCanals') . '<br>'; } // "You do not have any rail/canal markers left." } if ($coalsource == 50) { $altcoalsource = 99; } else { $altcoalsource = $coalsource; } if ($errorlist == '') { if ($SystemActing) { $AdminTakingMove = 0; } else { if ($GAME['PlayerUserID'][$GAME['PlayerToMove']] == $_SESSION['MyUserID']) { $AdminTakingMove = 0; } else { $AdminTakingMove = 1; } } $GAME['RemainingTiles'][5][$GAME['PlayerToMove']]--; $GAME['LinkStatus'][$linktobuild] = $GAME['PlayerToMove']; $GAME['Money'][$GAME['PlayerToMove']] -= (3 + 2 * $GAME['RailPhase']) * $buildnum; $GAME['AmountSpent'][$GAME['PlayerToMove']] += (3 + 2 * $GAME['RailPhase']) * $buildnum; if ($GAME['RailPhase']) { if ($GAME['CoalNet'][$GAME['RailStarts'][$linktobuild]] < $GAME['CoalNet'][$GAME['RailEnds'][$linktobuild]]) { $LowCoalNet = $GAME['CoalNet'][$GAME['RailStarts'][$linktobuild]]; $HighCoalNet = $GAME['CoalNet'][$GAME['RailEnds'][$linktobuild]]; } else { $LowCoalNet = $GAME['CoalNet'][$GAME['RailEnds'][$linktobuild]]; $HighCoalNet = $GAME['CoalNet'][$GAME['RailStarts'][$linktobuild]]; } if ($GAME['HasPort'][$GAME['RailStarts'][$linktobuild]] or $GAME['HasPort'][$GAME['RailEnds'][$linktobuild]]) { $AssignHasPort = 1; } else { $AssignHasPort = 0; } for ($i = 0; $i < $GAME['NumTowns']; $i++) { if ($GAME['CoalNet'][$i] == $HighCoalNet) { $GAME['CoalNet'][$i] = $LowCoalNet; } if ($GAME['CoalNet'][$i] == $LowCoalNet) { $GAME['HasPort'][$i] = $AssignHasPort; } } if ($coalsource == 50) { $GAME['Money'][$GAME['PlayerToMove']] -= $GAME['cubeprice'][$GAME['CoalDemand']]; $GAME['AmountSpent'][$GAME['PlayerToMove']] += $GAME['cubeprice'][$GAME['CoalDemand']]; if ($GAME['CurrentPlayers'] == 2 and $GAME['CoalDemand'] < 6 or $GAME['CurrentPlayers'] > 2 and $GAME['CoalDemand'] < 8) { $GAME['CoalDemand']++; } } else { $GAME['CoalInLancs']--; $GAME['SpaceCubes'][$coalsource] = $GAME['SpaceCubes'][$coalsource] - 1; // This is written in this way because SpaceCubes is a string consisting of digits // (it is not legal to use increment/decrement operators on string offsets). if (!$GAME['SpaceCubes'][$coalsource]) { fliptile($coalsource); } } $GAME['HasLinkedToTown'][$GAME['PlayerToMove']][$GAME['RailStarts'][$linktobuild]] = 1; $GAME['HasLinkedToTown'][$GAME['PlayerToMove']][$GAME['RailEnds'][$linktobuild]] = 1; if ($buildnum == 2) { if ($AdminTakingMove) { $altgoodoutput = '2D' . callmovetimediff() . letter_end_number($_SESSION['MyUserID']) . letter_end_number($_SESSION['MyGenderCode']) . letter_end_number($linktobuild) . letter_end_number($altcoalsource); $altgoodoutputName = '|' . $_SESSION['MyUserName']; } else { $altgoodoutput = 'I' . callmovetimediff() . letter_end_number($linktobuild) . letter_end_number($altcoalsource); $altgoodoutputName = ''; } $GAME['SecondRailMode'] = 0; } else { if ($AdminTakingMove) { $altgoodoutput = '1I' . callmovetimediff() . letter_end_number($_SESSION['MyUserID']) . letter_end_number($_SESSION['MyGenderCode']) . letter_end_number($thecard) . letter_end_number($linktobuild) . letter_end_number($altcoalsource); $altgoodoutputName = '|' . $_SESSION['MyUserName']; } else { $altgoodoutput = 'D' . callmovetimediff() . letter_end_number($thecard) . letter_end_number($linktobuild) . letter_end_number($altcoalsource); $altgoodoutputName = ''; } if (!$GAME['RemainingTiles'][5][$GAME['PlayerToMove']]) { $altgoodoutput .= '9IB'; } else { if ($GAME['Money'][$GAME['PlayerToMove']] < 10) { $altgoodoutput .= '9IC'; } else { if ($GAME['CoalInLancs'] or $GAME['Money'][$GAME['PlayerToMove']] > 9 + $GAME['cubeprice'][$GAME['CoalDemand']]) { for ($i = 0; $i < $GAME['NumRailLinks']; $i++) { if (($GAME['HasPort'][$GAME['RailEnds'][$i]] or $GAME['HasPort'][$GAME['RailStarts'][$i]]) and $GAME['Money'][$GAME['PlayerToMove']] > 9 + $GAME['cubeprice'][$GAME['CoalDemand']] and $GAME['LinkStatus'][$i] == 9 and ($GAME['HasBuiltInTown'][$GAME['PlayerToMove']][$GAME['RailStarts'][$i]] or $GAME['HasBuiltInTown'][$GAME['PlayerToMove']][$GAME['RailEnds'][$i]] or $GAME['HasLinkedToTown'][$GAME['PlayerToMove']][$GAME['RailStarts'][$i]] or $GAME['HasLinkedToTown'][$GAME['PlayerToMove']][$GAME['RailEnds'][$i]])) { $GAME['SecondRailMode'] = 1; break; } for ($j = 0; $j < $GAME['NumIndustrySpaces']; $j++) { if ($GAME['SpaceStatus'][$j] != 9 and $GAME['SpaceTile'][$j] == 1 and $GAME['SpaceCubes'][$j] and ($GAME['CoalNet'][$GAME['spacetowns'][$j]] == $GAME['CoalNet'][$GAME['RailStarts'][$i]] or $GAME['CoalNet'][$GAME['spacetowns'][$j]] == $GAME['CoalNet'][$GAME['RailEnds'][$i]]) and ($GAME['HasBuiltInTown'][$GAME['PlayerToMove']][$GAME['RailStarts'][$i]] or $GAME['HasBuiltInTown'][$GAME['PlayerToMove']][$GAME['RailEnds'][$i]] or $GAME['HasLinkedToTown'][$GAME['PlayerToMove']][$GAME['RailStarts'][$i]] or $GAME['HasLinkedToTown'][$GAME['PlayerToMove']][$GAME['RailEnds'][$i]]) and $GAME['LinkStatus'][$i] == 9 and ($GAME['RailAlwaysExists'][$i] or $GAME['ModularBoardParts'] & $GAME['RailExistenceArray'][$i])) { $GAME['SecondRailMode'] = 1; break 2; } } } } if (!$GAME['SecondRailMode']) { $altgoodoutput .= '9IA'; } } } } } else { if ($GAME['CoalNet'][$GAME['CanalStarts'][$linktobuild]] < $GAME['CoalNet'][$GAME['CanalEnds'][$linktobuild]]) { $LowCoalNet = $GAME['CoalNet'][$GAME['CanalStarts'][$linktobuild]]; $HighCoalNet = $GAME['CoalNet'][$GAME['CanalEnds'][$linktobuild]]; } else { $LowCoalNet = $GAME['CoalNet'][$GAME['CanalEnds'][$linktobuild]]; $HighCoalNet = $GAME['CoalNet'][$GAME['CanalStarts'][$linktobuild]]; } if ($GAME['HasPort'][$GAME['CanalStarts'][$linktobuild]] or $GAME['HasPort'][$GAME['CanalEnds'][$linktobuild]]) { $AssignHasPort = 1; } else { $AssignHasPort = 0; } for ($i = 0; $i < $GAME['NumTowns']; $i++) { if ($GAME['CoalNet'][$i] == $HighCoalNet) { $GAME['CoalNet'][$i] = $LowCoalNet; } if ($GAME['CoalNet'][$i] == $LowCoalNet) { $GAME['HasPort'][$i] = $AssignHasPort; } } $GAME['HasLinkedToTown'][$GAME['PlayerToMove']][$GAME['CanalStarts'][$linktobuild]] = 1; $GAME['HasLinkedToTown'][$GAME['PlayerToMove']][$GAME['CanalEnds'][$linktobuild]] = 1; if ($AdminTakingMove) { $altgoodoutput = '1I' . callmovetimediff() . letter_end_number($_SESSION['MyUserID']) . letter_end_number($_SESSION['MyGenderCode']) . letter_end_number($thecard) . letter_end_number($linktobuild); $altgoodoutputName = '|' . $_SESSION['MyUserName']; } else { $altgoodoutput = 'D' . callmovetimediff() . letter_end_number($thecard) . letter_end_number($linktobuild); $altgoodoutputName = ''; } } } else { $altgoodoutput = ''; $altgoodoutputName = ''; } return array($errorlist, '', $altgoodoutput, $altgoodoutputName); }
function sellcotton($milllocation, $portlocation, $continuing, $thecard) { global $GAME, $SystemActing; $errorlistA = ''; $errorlistB = ''; $ExclamationMark = 0; if ($GAME['SpaceTile'][$milllocation] or $GAME['SpaceStatus'][$milllocation] == 9) { $errorlistA .= transtext('memIsNotCM') . '<br>'; // "The industry space that you specified as the location // of the Cotton Mill is not occupied by a Cotton Mill." } else { if ($GAME['SpaceStatus'][$milllocation] != $GAME['PlayerToMove']) { $errorlistA .= transtext('memCMNotYours') . '<br>'; } else { if (!$GAME['SpaceCubes'][$milllocation]) { $errorlistA .= transtext('memCMFlipped') . '<br>'; // "The Cotton Mill that you specified is already flipped." } } } if ($errorlistA == '') { if ($portlocation < $GAME['NumIndustrySpaces']) { if ($GAME['SpaceTile'][$portlocation] != 3) { $errorlistB .= transtext('memIsNotPort') . '<br>'; // "The industry space that you specified as the location // of the Port is not occupied by a Port." } else { if ($GAME['CoalNet'][$GAME['spacetowns'][$milllocation]] != $GAME['CoalNet'][$GAME['spacetowns'][$portlocation]]) { $errorlistB .= transtext('memPortNotConn') . '<br>'; // "The Port location that you specified is not connected to the Cotton Mill that you specified." } else { if (!$GAME['SpaceCubes'][$portlocation]) { $errorlistB .= transtext('memPortFlipped') . '<br>'; // "The Port in the location that you specified is already flipped." } } } } else { if (!$GAME['HasPort'][$GAME['spacetowns'][$milllocation]]) { $errorlistB .= transtext('memCMNoPorts') . '<br>'; // "The specified Cotton Mill cannot sell to the Distant Market, as it is not connected to any Ports." } else { if ($GAME['CottonDemand'] == 8) { $errorlistB .= transtext('memNoMoreDemand') . '<br>'; } } } } $errorlist = $errorlistA . $errorlistB; if ($errorlist == '') { if ($SystemActing) { $AdminTakingMove = 0; } else { if ($GAME['PlayerUserID'][$GAME['PlayerToMove']] == $_SESSION['MyUserID']) { $AdminTakingMove = 0; } else { $AdminTakingMove = 1; } } $append_action_end_note = true; if ($portlocation < $GAME['NumIndustrySpaces']) { fliptile($portlocation); fliptile($milllocation); if ($continuing) { if ($AdminTakingMove) { $altgoodoutput = '2D' . callmovetimediff() . letter_end_number($_SESSION['MyUserID']) . letter_end_number($_SESSION['MyGenderCode']) . letter_end_number($milllocation) . letter_end_number($portlocation); $altgoodoutputName = '|' . $_SESSION['MyUserName']; } else { $altgoodoutput = 'I' . callmovetimediff() . letter_end_number($milllocation) . letter_end_number($portlocation); $altgoodoutputName = ''; } } else { if ($AdminTakingMove) { $altgoodoutput = '2B' . callmovetimediff() . letter_end_number($_SESSION['MyUserID']) . letter_end_number($_SESSION['MyGenderCode']) . letter_end_number($thecard) . letter_end_number($milllocation) . letter_end_number($portlocation); $altgoodoutputName = '|' . $_SESSION['MyUserName']; } else { $altgoodoutput = 'G' . callmovetimediff() . letter_end_number($thecard) . letter_end_number($milllocation) . letter_end_number($portlocation); $altgoodoutputName = ''; } } $CheckCtu = true; } else { drawDMtile(); if ($continuing) { if ($AdminTakingMove) { $altgoodoutput = '2D' . callmovetimediff() . letter_end_number($_SESSION['MyUserID']) . letter_end_number($_SESSION['MyGenderCode']) . letter_end_number($milllocation) . '9J'; $altgoodoutputName = '|' . $_SESSION['MyUserName']; } else { $altgoodoutput = 'I' . callmovetimediff() . letter_end_number($milllocation) . '9J'; $altgoodoutputName = ''; } } else { if ($AdminTakingMove) { $altgoodoutput = '2B' . callmovetimediff() . letter_end_number($_SESSION['MyUserID']) . letter_end_number($_SESSION['MyGenderCode']) . letter_end_number($thecard) . letter_end_number($milllocation) . '9J'; $altgoodoutputName = '|' . $_SESSION['MyUserName']; } else { $altgoodoutput = 'G' . callmovetimediff() . letter_end_number($thecard) . letter_end_number($milllocation) . '9J'; $altgoodoutputName = ''; } } if ($GAME['CottonDemand'] < 8) { $CheckCtu = true; $Boost = array(3, 3, 2, 2, 1, 1, 0, 0); $Boost = $Boost[$GAME['CottonDemand']]; $GAME['IncomeSpace'][$GAME['PlayerToMove']] += $Boost; // If IncomeSpace[...] ends up above 99, // it's taken care of by the call to fliptile() fliptile($milllocation); if (!DMSaleSuccessProbability()) { $GAME['CottonDemand'] = 8; $altgoodoutput .= '9J'; } } else { $CheckCtu = false; $append_action_end_note = false; } } $GAME['ContinueSellingMode'] = 0; if ($CheckCtu) { $MillsArray = array(); $PortsArray = array(); for ($i = 0; $i < $GAME['NumIndustrySpaces']; $i++) { if ($GAME['SpaceStatus'][$i] == $GAME['PlayerToMove'] and !$GAME['SpaceTile'][$i] and $GAME['SpaceCubes'][$i]) { $MillsArray[] = $i; } if ($GAME['SpaceStatus'][$i] != 9 and $GAME['SpaceTile'][$i] == 3 and $GAME['SpaceCubes'][$i]) { $PortsArray[] = $i; } } for ($i = 0; $i < count($MillsArray); $i++) { if ($GAME['HasPort'][$GAME['spacetowns'][$MillsArray[$i]]] and $GAME['CottonDemand'] < 8) { $GAME['ContinueSellingMode'] = 1; break; } for ($j = 0; $j < count($PortsArray); $j++) { if ($GAME['CoalNet'][$GAME['spacetowns'][$MillsArray[$i]]] == $GAME['CoalNet'][$GAME['spacetowns'][$PortsArray[$j]]]) { $GAME['ContinueSellingMode'] = 1; break 2; } } } } if (!$GAME['ContinueSellingMode'] and $append_action_end_note) { $altgoodoutput .= '9I'; } } else { $altgoodoutput = ''; $altgoodoutputName = ''; } return array($errorlist, '', $altgoodoutput, $altgoodoutputName); }
function DoTask() { global $Banned, $GAME; if (@$_POST['Counts']) { $ToCount = 1; } else { $ToCount = 0; } if ($GAME['RailPhase']) { $ToCount = 0; } $ChosenColour = sanitise_int(@$_POST['colourtoreplace'], SANITISE_NO_FLAGS, 0, MAX_PLAYERS - 1); $PostFailureTitle = false; do { if (!$GAME['PlayersMissing']) { $PostFailureTitle = 'No missing players'; $PostFailureMessage = 'There aren\'t any players missing from this game at the moment. (Perhaps something happened after you loaded the board page.) Please click <a href="board.php?GameID=' . $GAME['GameID'] . '">here</a> to go to the board page, or <a href="index.php">here</a> to return to the Main Page.'; break; } if ($GAME['GameStatus'] != 'In Progress' and $GAME['GameStatus'] != 'Recruiting Replacement' or !$GAME['PlayersMissingThatMatter']) { $PostFailureTitle = 'No replacements needed'; $PostFailureMessage = 'No replacement players are needed for this game at the moment. (Perhaps something happened after you loaded the board page.) Please click <a href="board.php?GameID=' . $GAME['GameID'] . '">here</a> to go to the board page, or <a href="index.php">here</a> to return to the Main Page.'; break; } if (!$GAME['PlayerMissingAndMatters'][$ChosenColour]) { $PostFailureTitle = 'Cannot join as selected colour'; $PostFailureMessage = 'You cannot join this game as the selected colour. (Perhaps something happened after you loaded the board page.) Please click <a href="board.php?GameID=' . $GAME['GameID'] . '">here</a> to go to the board page, or <a href="index.php">here</a> to return to the Main Page.'; break; } if ($GAME['MyColour'] != 50) { $PostFailureTitle = 'Already playing in this game'; $PostFailureMessage = 'You cannot join this game as a replacement, because you are already playing in it. Please click <a href="board.php?GameID=' . $GAME['GameID'] . '">here</a> to go to the board page, or <a href="index.php">here</a> to return to the Main Page.'; break; } if ($Banned) { $PostFailureTitle = 'Banned'; $PostFailureMessage = 'You cannot join this game as a replacement, because you are banned. Please click <a href="lobby.php?GameID=' . $GAME['GameID'] . '">here</a> to return to the lobby page, or <a href="index.php">here</a> to return to the Main Page.'; break; } if (in_array($_SESSION['MyUserID'], $GAME['ReplacementOffers_Users'])) { $PostFailureTitle = 'Request already received'; $PostFailureMessage = 'You have already made a request to join this game. You might be seeing this message because you clicked the button twice. Please click <a href="lobby.php?GameID=' . $GAME['GameID'] . '">here</a> to return to the lobby page, or <a href="index.php">here</a> to return to the Main Page.'; break; } if (dbquery(DBQUERY_READ_RESULTSET, 'SELECT "User" FROM "PlayerGameRcd" WHERE "User" = :user: AND "Game" = :game:', 'user', $_SESSION['MyUserID'], 'game', $GAME['GameID']) !== 'NONE') { $PostFailureTitle = 'You have previously played in this game'; $PostFailureMessage = 'You have previously played in this game. It is not possible to re-join the game. Please click <a href="lobby.php?GameID=' . $GAME['GameID'] . '">here</a> to return to the lobby page, or <a href="index.php">here</a> to return to the Main Page.'; break; } } while (false); if ($PostFailureTitle !== false) { $mypage = page::standard(); $mypage->title_body($PostFailureTitle); $mypage->leaf('p', $PostFailureMessage); $mypage->finish(); } dbquery(DBQUERY_WRITE, 'INSERT INTO "ReplacementOffer" ("Game", "User", "Colour", "ToCount") VALUES (:game:, :user:, :colour:, :tocount:)', 'game', $GAME['GameID'], 'user', $_SESSION['MyUserID'], 'colour', $ChosenColour, 'tocount', $ToCount); if ($ChosenColour == $GAME['PlayerToMove']) { $GAME['AltGameTicker'] .= '8A' . callmovetimediff() . letter_end_number($_SESSION['MyUserID']) . letter_end_number($_SESSION['MyGenderCode']); $GAME['GameTickerNames'] .= '|' . $_SESSION['MyUserName']; dbformatgamedata(); for ($i = 0; $i < MAX_PLAYERS; $i++) { if ($GAME['PlayerExists'][$i] == 1 and !$GAME['PlayerMissing'][$i] and $GAME['EmailPrompt'][$i] and $GAME['Email'][$i] != '') { $subject = $_SESSION['MyUserName'] . ' wants to join game number ' . $GAME['GameID'] . ' as a replacement'; $body = '<p>This is an automated message. ' . $_SESSION['MyUserName'] . ' has asked to join game number ' . $GAME['GameID'] . ' as a replacement. As you are playing in this game, you can choose to accept this request. Here is the URL of the game page:</p><p><a href="' . SITE_ADDRESS . 'board.php?GameID=' . $GAME['GameID'] . '">' . SITE_ADDRESS . 'board.php?GameID=' . $GAME['GameID'] . '</a></p>' . EMAIL_FOOTER; send_email($subject, $body, $GAME['Email'][$i], null); } } } else { dbformatgamedata(); } page::redirect(3, 'board.php?GameID=' . $GAME['GameID'], 'Successfully requested to join.'); }
function flip_UOCMs() { // This function runs at the end of each phase if the game has been downsized. It simulates // attempting to flip orphan Cotton Mills, in order to avoid unfairness to players who have // attempted a Port strategy. It first makes a list of unflipped orphan Cotton Mills, // then it makes lists of "good" Ports (those that generate points for the "orphan player") // and of "bad" Ports (those that generate points only for the "real" players). Then // it goes through four steps to try and flip these Cotton Mills and good Ports. // "Desirability" of flipping a tile is evaluated first on how many points it would earn for // the "orphan player" (more points is good), then on how many points it would earn for the // the "real players" collectively (more points is bad). If two tiles of the same type are // tied for desirability, then their relative order is randomised. global $GAME; $UOCMs_numbers = array(); $UOCMs_desirability = array(); $UOCMs_networkcomponent = array(); $UOCMs_random = array(); $good_UPs_numbers = array(); $good_UPs_desirability = array(); $good_UPs_networkcomponent = array(); $good_UPs_random = array(); $bad_UPs_numbers = array(); $bad_UPs_desirability = array(); $bad_UPs_networkcomponent = array(); $bad_UPs_random = array(); for ($i = 0; $i < $GAME['NumIndustrySpaces']; $i++) { if ($GAME['SpaceStatus'][$i] == 8 and $GAME['SpaceCubes'][$i] and !$GAME['SpaceTile'][$i]) { $desirability = flip_UOCMs_evaltile($i); if ($desirability > 0) { $UOCMs_numbers[] = $i; $UOCMs_desirability[] = $desirability; $UOCMs_networkcomponent[] = $GAME['CoalNet'][$GAME['spacetowns'][$i]]; $UOCMs_random[] = $i; } } if ($GAME['SpaceStatus'][$i] != 9 and $GAME['SpaceCubes'][$i] and $GAME['SpaceTile'][$i] == 3) { $desirability = flip_UOCMs_evaltile($i); if ($desirability > 0) { $good_UPs_numbers[] = $i; $good_UPs_desirability[] = flip_UOCMs_evaltile($i); $good_UPs_networkcomponent[] = $GAME['CoalNet'][$GAME['spacetowns'][$i]]; $good_UPs_random[] = $i; } else { $bad_UPs_numbers[] = $i; $bad_UPs_desirability[] = flip_UOCMs_evaltile($i); $bad_UPs_networkcomponent[] = $GAME['CoalNet'][$GAME['spacetowns'][$i]]; $bad_UPs_random[] = $i; } } } if (!count($UOCMs_numbers)) { return; } shuffle($UOCMs_random); shuffle($good_UPs_random); shuffle($bad_UPs_random); array_multisort($UOCMs_desirability, SORT_DESC, $UOCMs_random, $UOCMs_numbers, $UOCMs_networkcomponent); array_multisort($good_UPs_desirability, SORT_DESC, $good_UPs_random, $good_UPs_numbers, $good_UPs_networkcomponent); array_multisort($bad_UPs_desirability, SORT_DESC, $bad_UPs_random, $bad_UPs_numbers, $bad_UPs_networkcomponent); for ($i = 0; $i < count($good_UPs_numbers); $i++) { // First, for each "good" Port, I try to find the "best" // Cotton Mill that's connected to it, and flip them both. for ($j = 0; $j < count($UOCMs_numbers); $j++) { if ($UOCMs_networkcomponent[$j] == $good_UPs_networkcomponent[$i]) { $GAME['AltGameTicker'] .= '7F' . letter_end_number($UOCMs_numbers[$j]) . letter_end_number($good_UPs_numbers[$i]); fliptile($UOCMs_numbers[$j]); fliptile($good_UPs_numbers[$i]); array_splice($UOCMs_numbers, $j, 1); array_splice($UOCMs_networkcomponent, $j, 1); array_splice($good_UPs_numbers, $i, 1); array_splice($good_UPs_networkcomponent, $i, 1); $i--; break; } } } if (!count($UOCMs_numbers)) { return; } $NetworkComponents = array_unique($GAME['CoalNet']); $NetworkComponentsRenumbered = array(); foreach ($NetworkComponents as $key => $value) { $NetworkComponentsRenumbered[] = $value; // array_unique() preserves keys, which I don't want. } for ($i = 0; $i < count($NetworkComponentsRenumbered); $i++) { $PortCMBalance[$NetworkComponentsRenumbered[$i]] = 0; } for ($i = 0; $i < count($UOCMs_numbers); $i++) { $PortCMBalance[$UOCMs_networkcomponent[$i]]++; } for ($i = 0; $i < count($bad_UPs_numbers); $i++) { $PortCMBalance[$bad_UPs_networkcomponent[$i]]--; } while (DMSaleSuccessProbability() == 1) { // Second, for as long as success in selling to the Distant Market is assured, // I look for Cotton Mills that are in a network component with too many Cotton // Mills compared to Ports, and I flip them via the Distant Market. I only need // to look for "bad" Ports from this point on, since following the previous step, // all unflipped "good" Ports are disconnected from the remaining Cotton Mills. for ($i = 0; $i < count($UOCMs_numbers); $i++) { if ($GAME['HasPort'][$UOCMs_networkcomponent[$i]] and $PortCMBalance[$UOCMs_networkcomponent[$i]] > 0) { $GAME['AltGameTicker'] .= '7F' . letter_end_number($UOCMs_numbers[$i]) . '9J'; drawDMtile(); fliptile($UOCMs_numbers[$i]); array_splice($UOCMs_numbers, $i, 1); array_splice($UOCMs_networkcomponent, $i, 1); continue 2; } } break; } while (DMSaleSuccessProbability() == 1) { // Third, for as long as success in selling to the Distant Market is assured, // I try to find the "worst" Port and flip, via the Distant Market, any Cotton Mill // that's connected to it. The Port concerned is deleted from the array of // "bad" Ports when I do this - it can no longer be required, so I eliminate it // the better to identify the "worst" Port that I can still be compelled to use. for ($i = count($bad_UPs_numbers) - 1; $i >= 0; $i--) { for ($j = 0; $j < count($UOCMs_numbers); $j++) { if ($UOCMs_networkcomponent[$j] == $bad_UPs_networkcomponent[$i]) { $GAME['AltGameTicker'] .= '7F' . letter_end_number($UOCMs_numbers[$j]) . '9J'; drawDMtile(); fliptile($UOCMs_numbers[$j]); array_splice($UOCMs_numbers, $j, 1); array_splice($UOCMs_networkcomponent, $j, 1); array_splice($bad_UPs_numbers, $i, 1); array_splice($bad_UPs_networkcomponent, $i, 1); continue 3; } } } break; } for ($i = 0; $i < count($UOCMs_numbers); $i++) { // Fourth, for each Cotton Mill, I try to find the "best" Port // that's connected to it, and flip them both. for ($j = 0; $j < count($bad_UPs_numbers); $j++) { if ($bad_UPs_networkcomponent[$j] == $UOCMs_networkcomponent[$i]) { $GAME['AltGameTicker'] .= '7F' . letter_end_number($UOCMs_numbers[$i]) . letter_end_number($bad_UPs_numbers[$j]); fliptile($UOCMs_numbers[$i]); fliptile($bad_UPs_numbers[$j]); array_splice($UOCMs_numbers, $i, 1); array_splice($UOCMs_networkcomponent, $i, 1); array_splice($bad_UPs_numbers, $j, 1); array_splice($bad_UPs_networkcomponent, $j, 1); $i--; break; } } } while ($GAME['CottonDemand'] < 8) { // Finally, I try to flip the remaining Cotton Mills using the Distant Market, // until the demand for cotton runs out. for ($i = 0; $i < count($UOCMs_numbers); $i++) { if ($GAME['HasPort'][$UOCMs_networkcomponent[$i]]) { $GAME['AltGameTicker'] .= '7F' . letter_end_number($UOCMs_numbers[$i]) . '9J'; if (drawDMtile()) { fliptile($UOCMs_numbers[$i]); array_splice($UOCMs_numbers, $i, 1); array_splice($UOCMs_networkcomponent, $i, 1); if (!DMSaleSuccessProbability()) { $GAME['CottonDemand'] = 8; $GAME['AltGameTicker'] .= '9J'; } continue 2; } else { break 2; } } } break; } }
function moveexecute($formdetails) { global $GAME, $SystemActing; $errorlist = ''; $MoveOn = true; if ($GAME['DebtMode']) { if ($GAME['SpaceStatus'][$formdetails['IndustrySpace']] == 9) { $errorlist .= transtext('memNoTileInSpace') . '<br>'; } else { if ($GAME['SpaceStatus'][$formdetails['IndustrySpace']] != $GAME['PlayerToMove']) { $errorlist .= transtext('memTileNotYours') . '<br>'; } else { destroytile($formdetails['IndustrySpace'], 1, 1); $GAME['MoveMade'] = 1; $GAME['MoveMadeByPlayer'][$GAME['PlayerToMove']] = 1; } } if ($GAME['Money'][$GAME['PlayerToMove']] >= 0) { for ($i = 0; $i < MAX_PLAYERS; $i++) { if ($GAME['TurnOrder'][$i] == $GAME['PlayerToMove']) { $WhereInTurnOrder = $i; } } $GAME['DebtMode'] = 0; for ($i = MAX_PLAYERS - 1; $i > $WhereInTurnOrder; $i--) { if ($GAME['PlayerExists'][$GAME['TurnOrder'][$i]] and $GAME['Money'][$GAME['TurnOrder'][$i]] < 0) { for ($j = 0; $j < $GAME['NumIndustrySpaces']; $j++) { if ($GAME['SpaceStatus'][$j] == $GAME['TurnOrder'][$i]) { $GAME['PlayerToMove'] = $GAME['TurnOrder'][$i]; $GAME['DebtMode'] = 1; break; } } } } if (!$GAME['DebtMode']) { $GAME['PlayerToMove'] = $GAME['TurnOrder'][0]; $MoveOn = false; } } } else { if ($GAME['SecondRailMode']) { if ($formdetails['LinkToBuild'] == 50) { if ($SystemActing) { $AdminTakingMove = 0; } else { if ($GAME['PlayerUserID'][$GAME['PlayerToMove']] == $_SESSION['MyUserID']) { $AdminTakingMove = 0; } else { $AdminTakingMove = 1; } } if ($AdminTakingMove) { $ResultArray = array('', '', '2E' . callmovetimediff() . letter_end_number($_SESSION['MyUserID']) . letter_end_number($_SESSION['MyGenderCode']), '|' . $_SESSION['MyUserName']); } else { $ResultArray = array('', '', 'J' . callmovetimediff(), ''); } $GAME['SecondRailMode'] = 0; } else { require_once HIDDEN_FILES_PATH . 'coalresource.php'; require_once HIDDEN_FILES_PATH . 'linkresource.php'; $AssuredCoalSource = ClosestCoal($GAME['RailStarts'][$formdetails['LinkToBuild']], $GAME['RailEnds'][$formdetails['LinkToBuild']], $formdetails['CoalSource']); $ResultArray = buildlink($formdetails['LinkToBuild'], $AssuredCoalSource, 2, 50); } if ($ResultArray[0] == '') { $GAME['AltGameTicker'] .= $ResultArray[2]; $GAME['GameTickerNames'] .= $ResultArray[3]; } else { $errorlist .= $ResultArray[0]; } } else { if ($GAME['SecondDevelopMode']) { if ($formdetails['TileType'] == 9) { if ($SystemActing) { $AdminTakingMove = 0; } else { if ($GAME['PlayerUserID'][$GAME['PlayerToMove']] == $_SESSION['MyUserID']) { $AdminTakingMove = 0; } else { $AdminTakingMove = 1; } } if ($AdminTakingMove) { $ResultArray = array('', '', '2E' . callmovetimediff() . letter_end_number($_SESSION['MyUserID']) . letter_end_number($_SESSION['MyGenderCode']), '|' . $_SESSION['MyUserName']); } else { $ResultArray = array('', '', 'J' . callmovetimediff(), ''); } $GAME['SecondDevelopMode'] = 0; } else { require_once HIDDEN_FILES_PATH . 'developresource.php'; $AssuredIronSource = GetIron($formdetails['IronSource']); $ResultArray = develop($formdetails['TileType'], $AssuredIronSource, 1, 50); } if ($ResultArray[0] == '') { $GAME['AltGameTicker'] .= $ResultArray[2]; $GAME['GameTickerNames'] .= $ResultArray[3]; } else { $errorlist .= $ResultArray[0]; } } else { if ($GAME['ContinueSellingMode']) { if ($formdetails['IndustrySpace'] == 50) { if ($SystemActing) { $AdminTakingMove = 0; } else { if ($GAME['PlayerUserID'][$GAME['PlayerToMove']] == $_SESSION['MyUserID']) { $AdminTakingMove = 0; } else { $AdminTakingMove = 1; } } if ($AdminTakingMove) { $ResultArray = array('', '', '2E' . callmovetimediff() . letter_end_number($_SESSION['MyUserID']) . letter_end_number($_SESSION['MyGenderCode']), '|' . $_SESSION['MyUserName']); } else { $ResultArray = array('', '', 'J' . callmovetimediff(), ''); } $GAME['ContinueSellingMode'] = 0; } else { require_once HIDDEN_FILES_PATH . 'cottonresource.php'; $ResultArray = sellcotton($formdetails['IndustrySpace'], $formdetails['PortSpace'], 1, 50); } if ($ResultArray[0] == '') { $GAME['AltGameTicker'] .= $ResultArray[2]; $GAME['GameTickerNames'] .= $ResultArray[3]; } else { $errorlist .= $ResultArray[0]; } } else { if ($formdetails['CardA'] == 9) { $errorlist .= 'No card selected.<br>'; } else { $CardDetailsA = $GAME['carddetailarrayb'][$GAME['Cards'][$GAME['PlayerToMove']][$formdetails['CardA']]]; if ($formdetails['CardB'] == 9) { $CardDetailsB = 50; $passcb = ''; } else { $CardDetailsB = $GAME['carddetailarrayb'][$GAME['Cards'][$GAME['PlayerToMove']][$formdetails['CardB']]]; if ($GAME['Round'] == 1 and !$GAME['RailPhase'] or $GAME['HandSize'][$GAME['PlayerToMove']] % 2) { $passcb = ''; } else { $passcb = letter_end_number($CardDetailsB); } } switch ($formdetails['MoveType']) { case 0: case 1: if ($formdetails['MoveType'] and $formdetails['CardB'] == 9) { $ResultArray = array(transtext('memNo2ndCard') . '<br>', '', ''); } else { if ($formdetails['MoveType'] and $formdetails['CardB'] == $formdetails['CardA']) { $ResultArray = array(transtext('memDuplicCard') . '<br>', '', ''); // "You have selected the same card twice. Please select two different cards." } else { if ($formdetails['IndustrySpace'] == 50 or $formdetails['TileType'] == 9) { $ResultArray = array(transtext('memBadMoveData') . '<br>', '', ''); } else { require_once HIDDEN_FILES_PATH . 'coalresource.php'; require_once HIDDEN_FILES_PATH . 'tileresource.php'; $AssuredCoalSource = ClosestCoal($formdetails['IndustrySpace'], 50, $formdetails['CoalSource']); $AssuredIronSource = GetIron($formdetails['IronSource']); $ResultArray = buildtile($formdetails['IndustrySpace'], $formdetails['TileType'], $AssuredCoalSource, $AssuredIronSource, $formdetails['CardA'], $formdetails['MoveType'], $CardDetailsA, $CardDetailsB); } } } $TwoCards = $formdetails['MoveType']; break; case 2: require_once HIDDEN_FILES_PATH . 'linkresource.php'; if ($formdetails['LinkToBuild'] == 50) { $ResultArray = array(transtext('memBadMoveData') . '<br>', '', ''); } else { if ($GAME['RailPhase']) { require_once HIDDEN_FILES_PATH . 'coalresource.php'; $AssuredCoalSource = ClosestCoal($GAME['RailStarts'][$formdetails['LinkToBuild']], $GAME['RailEnds'][$formdetails['LinkToBuild']], $formdetails['CoalSource']); $ResultArray = buildlink($formdetails['LinkToBuild'], $AssuredCoalSource, 1, $CardDetailsA); } else { $ResultArray = buildlink($formdetails['LinkToBuild'], 50, 1, $CardDetailsA); } } $TwoCards = 0; break; case 3: if ($formdetails['TileType'] == 9) { $ResultArray = array(transtext('memBadMoveData') . '<br>', '', ''); } else { require_once HIDDEN_FILES_PATH . 'developresource.php'; $AssuredIronSource = GetIron($formdetails['IronSource']); $ResultArray = develop($formdetails['TileType'], $AssuredIronSource, 0, $CardDetailsA); } $TwoCards = 0; break; case 4: $ResultArray = array('', '', ''); if ($formdetails['LoanAmount'] > 3 or $GAME['IncomeSpace'][$GAME['PlayerToMove']] - $formdetails['LoanAmount'] < 0) { $ResultArray[0] .= transtext('memLoanTooBig') . '<br>'; } if ($GAME['RailPhase'] and $GAME['NumRounds'] - $GAME['Round'] < 4) { $ResultArray[0] .= transtext('memLoanTooLate') . '<br>'; } if ($ResultArray[0] == '') { $amount = 10 * $formdetails['LoanAmount']; $GAME['Money'][$GAME['PlayerToMove']] += $amount; $reducearray = array(0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 12, 12, 14, 14, 16, 16, 18, 18, 20, 20, 22, 22, 24, 24, 26, 26, 28, 28, 30, 30, 30, 33, 33, 33, 36, 36, 36, 39, 39, 39, 42, 42, 42, 45, 45, 45, 48, 48, 48, 51, 51, 51, 54, 54, 54, 57, 57, 57, 60, 60, 60, 60, 64, 64, 64, 64, 68, 68, 68, 68, 72, 72, 72, 72, 76, 76, 76, 76, 80, 80, 80, 80, 84, 84, 84, 84, 88, 88, 88, 88, 92, 92, 92, 92, 96, 96, 96); for ($i = 0; $i < $formdetails['LoanAmount']; $i++) { $GAME['IncomeSpace'][$GAME['PlayerToMove']] = $reducearray[$GAME['IncomeSpace'][$GAME['PlayerToMove']]]; } if ($SystemActing) { $AdminTakingMove = 0; } else { if ($GAME['PlayerUserID'][$GAME['PlayerToMove']] == $_SESSION['MyUserID']) { $AdminTakingMove = 0; } else { $AdminTakingMove = 1; } } if ($AdminTakingMove) { $ResultArray[2] = '2A' . callmovetimediff() . letter_end_number($_SESSION['MyUserID']) . letter_end_number($_SESSION['MyGenderCode']) . letter_end_number($CardDetailsA) . letter_end_number($formdetails['LoanAmount']); $ResultArray[3] = '|' . $_SESSION['MyUserName']; } else { $ResultArray[2] = 'F' . callmovetimediff() . letter_end_number($CardDetailsA) . letter_end_number($formdetails['LoanAmount']); $ResultArray[3] = ''; } } $TwoCards = 0; break; case 5: if ($formdetails['IndustrySpace'] == 50) { $ResultArray = array(transtext('memBadMoveData') . '<br>', '', ''); } else { require_once HIDDEN_FILES_PATH . 'cottonresource.php'; $ResultArray = sellcotton($formdetails['IndustrySpace'], $formdetails['PortSpace'], 0, $CardDetailsA); } $TwoCards = 0; break; case 6: $ResultArray[0] = ''; if ($GAME['HandSize'][$GAME['PlayerToMove']] % 2) { $TwoCards = 0; } else { if (!$GAME['RailPhase'] and $GAME['Round'] == 1) { $TwoCards = 0; } else { $TwoCards = 1; if ($CardDetailsB == 50) { $ResultArray[0] = transtext('memNo2ndCard') . '<br>'; // No second card selected. } if ($formdetails[CardB] == $formdetails[CardA]) { $ResultArray[0] = transtext('memDuplicCard') . '<br>'; // "You have selected the same card twice. Please select two different cards." } } } if ($SystemActing) { $AdminTakingMove = 0; } else { if ($GAME['PlayerUserID'][$GAME['PlayerToMove']] == $_SESSION['MyUserID']) { $AdminTakingMove = 0; } else { $AdminTakingMove = 1; } } if ($AdminTakingMove) { $ResultArray[2] = '2C' . callmovetimediff() . letter_end_number($_SESSION['MyUserID']) . letter_end_number($_SESSION['MyGenderCode']) . letter_end_number($CardDetailsA) . $passcb; $ResultArray[3] = '|' . $_SESSION['MyUserName']; } else { $ResultArray[2] = 'H' . callmovetimediff() . letter_end_number($CardDetailsA) . $passcb; $ResultArray[3] = ''; } } if ($ResultArray[0] == '') { $GAME['AltGameTicker'] .= $ResultArray[2]; $GAME['GameTickerNames'] .= $ResultArray[3]; if ($TwoCards) { if ($formdetails['CardA'] < $formdetails['CardB']) { $formdetails['CardB']--; } } $y = $GAME['Cards'][$GAME['PlayerToMove']][$formdetails['CardA']]; for ($i = $formdetails['CardA']; $i < $GAME['HandSize'][$GAME['PlayerToMove']] - 1; $i++) { $GAME['Cards'][$GAME['PlayerToMove']][$i] = $GAME['Cards'][$GAME['PlayerToMove']][$i + 1]; } $GAME['Cards'][$GAME['PlayerToMove']][$GAME['HandSize'][$GAME['PlayerToMove']] - 1] = $y; $GAME['DiscardPile'][] = array_pop($GAME['Cards'][$GAME['PlayerToMove']]); $GAME['HandSize'][$GAME['PlayerToMove']]--; if ($TwoCards) { $y = $GAME['Cards'][$GAME['PlayerToMove']][$formdetails['CardB']]; for ($i = $formdetails['CardB']; $i < $GAME['HandSize'][$GAME['PlayerToMove']] - 1; $i++) { $GAME['Cards'][$GAME['PlayerToMove']][$i] = $GAME['Cards'][$GAME['PlayerToMove']][$i + 1]; } $GAME['Cards'][$GAME['PlayerToMove']][$GAME['HandSize'][$GAME['PlayerToMove']] - 1] = $y; $GAME['DiscardPile'][] = array_pop($GAME['Cards'][$GAME['PlayerToMove']]); $GAME['HandSize'][$GAME['PlayerToMove']]--; } } else { $errorlist .= $ResultArray[0]; } } } } } } if ($errorlist == '') { $GAME['MoveMade'] = 1; if (!$SystemActing) { if ($GAME['PlayerUserID'][$GAME['PlayerToMove']] == $_SESSION['MyUserID']) { $GAME['MoveMadeByPlayer'][$GAME['PlayerToMove']] = 1; } } else { $GAME['MoveMadeByPlayer'][$GAME['PlayerToMove']] = 1; } } if ($MoveOn and !$GAME['DebtMode'] and !$GAME['SecondRailMode'] and !$GAME['SecondDevelopMode'] and !$GAME['ContinueSellingMode'] and $errorlist == '') { if ($GAME['RailPhase'] and $GAME['HandSize'][$GAME['PlayerToMove']] == 1) { require_once HIDDEN_FILES_PATH . 'nomovesresource.php'; if (CheckNoMoves($GAME['Cards'][$GAME['PlayerToMove']][0])) { $GAME['AltGameTicker'] .= '9H' . letter_end_number($GAME['carddetailarrayb'][$GAME['Cards'][$GAME['PlayerToMove']][0]]); $GAME['DiscardPile'][] = array_pop($GAME['Cards'][$GAME['PlayerToMove']]); $GAME['HandSize'][$GAME['PlayerToMove']] = 0; } } $EvenTest = $GAME['HandSize'][$GAME['PlayerToMove']] % 2; if (!$EvenTest or !$GAME['RailPhase'] and $GAME['Round'] == 1) { if ($GAME['NumRounds'] - $GAME['Round'] > 3) { if ($GAME['RailPhase'] or $GAME['Round'] != 1) { $GAME['Cards'][$GAME['PlayerToMove']][6] = array_pop($GAME['ShuffledDeck']); $GAME['HandSize'][$GAME['PlayerToMove']]++; } $GAME['Cards'][$GAME['PlayerToMove']][7] = array_pop($GAME['ShuffledDeck']); $GAME['HandSize'][$GAME['PlayerToMove']]++; if ($GAME['AutoSort'][$GAME['PlayerToMove']]) { sort($GAME['Cards'][$GAME['PlayerToMove']]); } } for ($i = 0; $i < MAX_PLAYERS; $i++) { if ($GAME['TurnOrder'][$i] == $GAME['PlayerToMove']) { $WhereInTurnOrder = $i; } } $EndRound = true; for ($i = MAX_PLAYERS - 1; $i > $WhereInTurnOrder; $i--) { if ($GAME['PlayerExists'][$GAME['TurnOrder'][$i]]) { $GAME['PlayerToMove'] = $GAME['TurnOrder'][$i]; $EndRound = false; } } if ($EndRound) { if ($GAME['Round'] == $GAME['NumRounds']) { if ($GAME['RailPhase']) { require_once HIDDEN_FILES_PATH . 'scoringresource.php'; endgamescoring(); } else { require_once HIDDEN_FILES_PATH . 'scoringresource.php'; require_once HIDDEN_FILES_PATH . 'turnorderresource.php'; canalphasescoring(); DoTurnOrder(1); } } else { require_once HIDDEN_FILES_PATH . 'turnorderresource.php'; DoTurnOrder(1); } } if ($GAME['RailPhase'] and $GAME['Round'] == $GAME['NumRounds'] and $GAME['GameStatus'] != 'Finished') { require_once HIDDEN_FILES_PATH . 'nomovesresource.php'; CheckNoMovesShell(); } } } return $errorlist; }
function startgame($AutoStart) { // Within this function, many variables that in other functions would be keys in the $GAME array are instead stand-alone variables. // These variables are all ones that get initialised within this function. // Some variables, like CurrentPlayers, are keys in the $GAME array as usual. // These are variables initialised earlier and stored as usual in $GAME, whose values are required by this function. // In a third category there is also $AutoStart, which is the argument of this function. global $GAME; if ($GAME['InitialTurnOrder'] == 'Random') { $j = rand(0, 23); $GAME['InitialTurnOrder'] = array('Red, Yellow, Green, Purple, Grey', 'Red, Yellow, Green, Grey, Purple', 'Red, Yellow, Purple, Green, Grey', 'Red, Yellow, Purple, Grey, Green', 'Red, Yellow, Grey, Green, Purple', 'Red, Yellow, Grey, Purple, Green', 'Red, Green, Yellow, Purple, Grey', 'Red, Green, Yellow, Grey, Purple', 'Red, Green, Purple, Yellow, Grey', 'Red, Green, Purple, Grey, Yellow', 'Red, Green, Grey, Yellow, Purple', 'Red, Green, Grey, Purple, Yellow', 'Red, Purple, Yellow, Green, Grey', 'Red, Purple, Yellow, Grey, Green', 'Red, Purple, Green, Yellow, Grey', 'Red, Purple, Green, Grey, Yellow', 'Red, Purple, Grey, Yellow, Green', 'Red, Purple, Grey, Green, Yellow', 'Red, Grey, Yellow, Green, Purple', 'Red, Grey, Yellow, Purple, Green', 'Red, Grey, Green, Yellow, Purple', 'Red, Grey, Green, Purple, Yellow', 'Red, Grey, Purple, Yellow, Green', 'Red, Grey, Purple, Green, Yellow'); $GAME['InitialTurnOrder'] = $GAME['InitialTurnOrder'][$j]; // Generate a random initial turn order. } $TurnOrder = explode(', ', $GAME['InitialTurnOrder']); $j = rand(0, MAX_PLAYERS - 1); $TurnOrderX = array(); for ($i = 0; $i < MAX_PLAYERS; $i++) { $TurnOrderX[] = $TurnOrder[$j]; $j = ($j + 1) % 5; // Construct an initial turn order with a random start player; // the other colours cycle round according to the predetermined order. } $colourtonumber = array('Red' => 0, 'Yellow' => 1, 'Green' => 2, 'Purple' => 3, 'Grey' => 4); for ($i = 0; $i < MAX_PLAYERS; $i++) { $TurnOrder[$i] = $colourtonumber[$TurnOrderX[$i]]; // Convert the colour names to the standard numbering system. } $i = 0; while ($i < MAX_PLAYERS) { // Push colours that are in the game to the start of the turn order. if ($GAME['PlayerExists'][$TurnOrder[$i]]) { $i++; } else { $doneshifting = true; for ($j = $i; $j < MAX_PLAYERS - 1; $j++) { $TurnOrder[$j] = $TurnOrder[$j + 1]; if ($GAME['PlayerExists'][$TurnOrder[$j]]) { $doneshifting = false; } } if ($doneshifting) { break; } } } $j = 0; for ($i = 0; $i < MAX_PLAYERS; $i++) { // After the previous operation, some colours are duplicated at the end of the turn order. // We replace them with the colours that aren't in the game. After we've done this, // $TurnOrder will be an array consisting of the integers 0, 1, 2, 3 and 4 in some order. if (!$GAME['PlayerExists'][$i]) { $TurnOrder[$GAME['CurrentPlayers'] + $j] = $i; $j++; } } $letters = 'ABCDE'; for ($i = 0; $i < MAX_PLAYERS; $i++) { $TurnOrderLetters[$i] = $letters[$TurnOrder[$i]]; } $PlayerToMove = $TurnOrder[0]; // Set the player whose turn it is, as the first player in the turn order. if ($AutoStart) { $GameTicker = 'A' . letter_end_number(time()); $GameTickerNames = ''; } else { $GameTicker = 'B' . letter_end_number(time()) . letter_end_number($_SESSION['MyUserID']) . letter_end_number($_SESSION['MyGenderCode']); $GameTickerNames = $_SESSION['MyUserName'] . '|'; } switch ($GAME['CreatorPronoun']) { case 'He': $ThePronoun = 'A'; break; case 'She': $ThePronoun = 'B'; break; case 'It': $ThePronoun = 'C'; break; } $GameTicker .= letter_end_number(strtotime($GAME['CreationTime'])) . letter_end_number($GAME['GameCreator']) . $ThePronoun; $GameTickerNames .= $GAME['GameCreatorName'] . '|'; $PEnum = 0; $playerdetails = ''; for ($i = 0; $i < MAX_PLAYERS; $i++) { if ($GAME['PlayerExists'][$i]) { switch ($GAME['Pronoun_Eng'][$i]) { case 'He': $ThePronoun = 'A'; break; case 'She': $ThePronoun = 'B'; break; case 'It': $ThePronoun = 'C'; break; } $playerdetails .= letter_end_number($GAME['PlayerUserID'][$i]) . $ThePronoun; if ($PEnum) { $GameTickerNames .= '|'; } $GameTickerNames .= $GAME['PlayerName'][$i]; $PEnum += pow(2, $i); } } $GameTicker .= letter_end_number($PEnum) . implode('', $TurnOrderLetters) . $playerdetails; // Now we have finished writing the initial details for the game log. $TurnOrder = implode('', $TurnOrder); // Convert $TurnOrder into a string. if ($GAME['CurrentPlayers'] == 2) { $ModularBoardParts = 0; if (($GAME['SpecialRules'] & 2) == 0) { $ModularBoardParts += 8; } $ShuffledTiles = '12222334'; $TwoPlayers = 1; } else { if ($GAME['GVersion'] == 1) { $ModularBoardParts = 7; } else { $ModularBoardParts = 0; } $ShuffledTiles = '001122223334'; $TwoPlayers = 0; } // Set up some things that depend on whether there are more than two players. $RandomLog = ''; $ShuffledDeck = array(); for ($i = 0; $i < count($GAME['carddetailarrayb']); $i++) { if ($GAME['CurrentPlayers'] > 2 or !in_array($i, $GAME['CardsToRemove'])) { $ShuffledDeck[] = $i; // Create the deck of cards to be used in the Canal Phase. } } shuffle($ShuffledDeck); // Shuffle the deck of cards. // $TranslationString = ''; // $TranslationSymbols = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXY'; // $TranslationSymbolsProgress = 0; // $LastTranslationNumber = $GAME['carddetailarrayb'][0]; // for ($i=0;$i<count($GAME['carddetailarrayb']);$i++) { // if ( $GAME['carddetailarrayb'][$i] == $LastTranslationNumber ) { // $TranslationString .= $TranslationSymbols[$TranslationSymbolsProgress]; // } else { // $LastTranslationNumber = $GAME['carddetailarrayb'][$i]; // $TranslationSymbolsProgress++; // $i--; // } // } // for ($i=0;$i<count($ShuffledDeck);$i++) { // $RandomLog .= $TranslationString[$ShuffledDeck[$i]]; // } // // The above commented-out section of code allows the ordering of the cards // // in the deck to be recorded. At present, it is not in use. The character // // 'Z' added to RandomLog (on the next line) stands for "card ordering not recorded". $RandomLog .= 'Z'; $ShuffledTiles = str_shuffle($ShuffledTiles); $RandomLog .= $ShuffledTiles; $RatingTotal = 0; for ($i = 0; $i < MAX_PLAYERS; $i++) { if ($GAME['PlayerExists'][$i]) { $RatingTotal += $GAME['PlayerRating'][$i]; for ($j = 0; $j < 8; $j++) { $Cards[$i][$j] = array_pop($ShuffledDeck); } sort($Cards[$i]); $Cards[$i] = implode('|', $Cards[$i]); // Deal 8 cards to each player, and sort them into the standard order. } else { $Cards[$i] = ''; } } $AverageRating = $RatingTotal / $GAME['CurrentPlayers']; $AppearancePriority = $AverageRating / 2 + 500; $AverageRating = (int) $AverageRating; $AppearancePriority = (int) $AppearancePriority; // Set up the variables that control how frequently the game appears on the Main Page. $Cards = implode(':', $Cards); $ShuffledDeck = implode('|', $ShuffledDeck); $MoneyAmount = 30 - 5 * $TwoPlayers; $Money = $MoneyAmount . '|' . $MoneyAmount . '|' . $MoneyAmount . '|' . $MoneyAmount . '|' . $MoneyAmount; if ($GAME['CurrentPlayers'] == 4) { $NumRounds = 8; } else { $NumRounds = 10; } $LinkStatus = ''; for ($i = 0; $i < $GAME['NumCanalLinks']; $i++) { $LinkStatus .= '9'; // Initialise the details of the canal links. } if (strlen($LinkStatus) % 2) { $LinkStatus .= 9; } $SpaceStatus = ''; $SpaceTile = ''; $TechLevels = ''; $SpaceCubes = ''; for ($i = 0; $i < $GAME['NumIndustrySpaces']; $i++) { $SpaceStatus .= '9'; $SpaceTile .= '0'; $TechLevels .= '0'; $SpaceCubes .= '1'; // Initialise the details of the industry spaces. } if (strlen($SpaceStatus) % 2) { $SpaceStatus .= '9'; $SpaceTile .= '0'; $TechLevels .= '0'; $SpaceCubes .= '1'; } $CoalNet = array(); for ($i = 0; $i < $GAME['NumTowns']; $i++) { $CoalNet[] = $i; } $CoalNet = implode('|', $CoalNet); $HasPort = implode('', $GAME['ExternalLocations']); // Initialise the data for the coal network (all locations are disconnected from one another), // and the data describing which locations have Ports (just the external locations). dbquery(DBQUERY_WRITE, 'UPDATE "Game" SET "LinkStatus" = UNHEX(:linkstatus:), "SpaceStatus" = UNHEX(:spacestatus:), "SpaceTile" = UNHEX(:spacetile:), "TechLevels" = UNHEX(:techlevels:), "SpaceCubes" = UNHEX(:spacecubes:), "GameStatus" = \'In Progress\', "TurnOrder" = :turnorder:, "Money" = :money:, "AmountSpent" = \'0|0|0|0|0\', "GameTicker" = :gameticker:, "GameTickerNames" = :gametickernames:, "NumRounds" = :numrounds:, "EffectiveNumPlayers" = :currentplayers:, "OriginalPlayers" = :currentplayers:, "ModularBoardParts" = :modularboardparts:, "LastMove" = UTC_TIMESTAMP(), "RandomLog" = :randomlog: WHERE "GameID" = :gameid:', 'linkstatus', $LinkStatus, 'spacestatus', $SpaceStatus, 'spacetile', $SpaceTile, 'techlevels', $TechLevels, 'spacecubes', $SpaceCubes, 'turnorder', $TurnOrder, 'money', $Money, 'gameticker', $GameTicker, 'gametickernames', $GameTickerNames, 'numrounds', $NumRounds, 'currentplayers', $GAME['CurrentPlayers'], 'modularboardparts', $ModularBoardParts, 'randomlog', $RandomLog, 'gameid', $GAME['GameID']); dbquery(DBQUERY_WRITE, 'INSERT INTO "GameInProgress" ("Game", "AverageRating", "AppearancePriority", "PlayerToMove", "LastEvent", "Cards", "HasPort", "CoalNet", "ShuffledDeck", "ShuffledTiles", "PlayerToMoveName", "PlayerToMoveID", "GIPTimeLimitA", "GIPTimeLimitB", "GIPLastMove") VALUES (:game:, :averagerating:, :appearancepriority:, :playertomove:, UTC_TIMESTAMP(), :cards:, :hasport:, :coalnet:, :shuffleddeck:, :shuffledtiles:, :playertomovename:, :playertomoveid:, :timelimita:, :timelimitb:, UTC_TIMESTAMP())', 'game', $GAME['GameID'], 'averagerating', $AverageRating, 'appearancepriority', $AppearancePriority, 'playertomove', $PlayerToMove, 'cards', $Cards, 'hasport', $HasPort, 'coalnet', $CoalNet, 'shuffleddeck', $ShuffledDeck, 'shuffledtiles', $ShuffledTiles, 'playertomovename', $GAME['PlayerName'][$PlayerToMove], 'playertomoveid', $GAME['PlayerUserID'][$PlayerToMove], 'timelimita', $GAME['TimeLimitA_Minutes'], 'timelimitb', $GAME['TimeLimitB_Minutes']); dbquery(DBQUERY_WRITE, 'DELETE FROM "LobbySettings" WHERE "Game" = :game:', 'game', $GAME['GameID']); dbquery(DBQUERY_COMMIT); file_put_contents(NUM_MOVES_MADE_DIR . 'g' . $GAME['GameID'] . '.txt', 0); // Set up the number-of-moves file for AJAX requests. $MetadatumNames = array('Games-InProgress', 'Games-Total', 'Games-Players' . $GAME['CurrentPlayers']); if (!$GAME['Friendly']) { $MetadatumNames[] = 'Games-Competitive'; $MetadatumNames[] = 'Games-Competitive-Players' . $GAME['CurrentPlayers']; } dbquery(DBQUERY_WRITE, 'UPDATE "Metadatum" SET "MetadatumValue" = "MetadatumValue" + 1 WHERE "MetadatumName" IN (\'' . implode('\', \'', $MetadatumNames) . '\')'); // Update some statistics in the Metadatum table. if ($GAME['Email'][$PlayerToMove] != '' and $GAME['EmailPrompt'][$PlayerToMove] and ($GAME['EmailPromptAgain'][$PlayerToMove] or !$GAME['HasBeenEmailed'][$PlayerToMove])) { // Email the player who is first to move. $subject = 'You\'re first up to make a move'; $body = '<p>This is an automated message. Game number ' . $GAME['GameID'] . ' has been started, and it\'s you to move first. Here is the URL to the game page:</p><p><a href="' . SITE_ADDRESS . 'board.php?GameID=' . $GAME['GameID'] . '">' . SITE_ADDRESS . 'board.php?GameID=' . $GAME['GameID'] . '</a></p>' . EMAIL_FOOTER; send_email($subject, $body, $GAME['Email'][$PlayerToMove], null); dbquery(DBQUERY_WRITE, 'UPDATE "User" SET "HasBeenEmailed" = 1 WHERE "UserID" = :userid:', 'userid', $GAME['PlayerUserID'][$PlayerToMove]); } }
function DoTurnOrder($dodebtcheck) { global $GAME; for ($i = 0; $i < MAX_PLAYERS; $i++) { if (!$GAME['PlayerExists'][$i]) { $GAME['AmountSpent'][$i] = 1000; } } $FlippedTurnOrder = array_flip(str_split($GAME['TurnOrder'], 1)); for ($i = 0; $i < MAX_PLAYERS; $i++) { $ReindexedFlippedTurnOrder[$i] = $FlippedTurnOrder[$i]; // Without this step, $FlippedTurnOrder has the correct key-value pairs, but they may // appear in the wrong order. This results in the call to array_multisort going wrong. } $whoarray = array(0, 1, 2, 3, 4); array_multisort($GAME['AmountSpent'], SORT_ASC, $ReindexedFlippedTurnOrder, SORT_ASC, $whoarray); $GAME['AmountSpent'] = array(0, 0, 0, 0, 0); $GAME['TurnOrder'] = implode('', $whoarray); if ($dodebtcheck) { $GAME['Round']++; for ($i = 0; $i < MAX_PLAYERS; $i++) { if ($GAME['PlayerExists'][$i]) { $GAME['Money'][$i] += $GAME['incomeamounts'][$GAME['IncomeSpace'][$i]]; } } $TheDebtors = array(); for ($i = 0; $i < MAX_PLAYERS; $i++) { if ($GAME['PlayerExists'][$i] and $GAME['Money'][$i] < 0) { $mytilesarray = array(); for ($j = 0; $j < $GAME['NumIndustrySpaces']; $j++) { if ($GAME['SpaceStatus'][$j] == $i) { $repayamount = $GAME['TileCosts'][$GAME['SpaceTile'][$j]][$GAME['TechLevels'][$j] - 1] / 2; $repayamount = (int) $repayamount; $mytilesarray[] = array($j, $repayamount, 0); } } $numberoftiles = count($mytilesarray); if ($numberoftiles < 5) { $bitsarray = array(array(1, 0, 0, 0), array(0, 1, 0, 0), array(1, 1, 0, 0), array(0, 0, 1, 0), array(1, 0, 1, 0), array(0, 1, 1, 0), array(1, 1, 1, 0), array(0, 0, 0, 1), array(1, 0, 0, 1), array(0, 1, 0, 1), array(1, 1, 0, 1), array(0, 0, 1, 1), array(1, 0, 1, 1), array(0, 1, 1, 1), array(1, 1, 1, 1)); for ($j = 0; $j < pow(2, $numberoftiles) - 1; $j++) { $resultmoney = $GAME['Money'][$i]; for ($k = 0; $k < $numberoftiles; $k++) { $resultmoney += $bitsarray[$j][$k] * $mytilesarray[$k][1]; } if ($resultmoney >= 0) { for ($k = 0; $k < $numberoftiles; $k++) { if (!$bitsarray[$j][$k]) { $mytilesarray[$k][2] = 1; } } } } for ($j = 0; $j < $numberoftiles; $j++) { if (!$mytilesarray[$j][2]) { destroytile($mytilesarray[$j][0], 0, 1); $GAME['Money'][$i] += $mytilesarray[$j][1]; $GAME['AltGameTicker'] .= letter_end_number($mytilesarray[$j][0]); $numberoftiles--; } } } if ($GAME['Money'][$i] < 0 and $numberoftiles > 0) { $TheDebtors[] = $i; } } } if (count($TheDebtors)) { $GAME['DebtMode'] = 1; for ($i = MAX_PLAYERS - 1; $i >= 0; $i--) { if (in_array($GAME['TurnOrder'][$i], $TheDebtors)) { $GAME['PlayerToMove'] = $GAME['TurnOrder'][$i]; } } } else { $GAME['PlayerToMove'] = $GAME['TurnOrder'][0]; } $GAME['AltGameTicker'] .= '9G'; } }