for ($i = 2; $i < $pvSize; $i++) { echo 'Check for unit ' . $postVals[$i]; if (array_search($postVals[$i], $armyUnits->slotData)) { $outList[] = $postVals[$i]; } else { $inList[] = $postVals[$i]; } } // Review units being removed from the army - process all if player controls the army or only the ones that player controls. for ($i = 0; $i < sizeof($outList); $i++) { $outUnit = loadUnit($outList[$i], $unitFile, 400); if ($outUnit->get('controller') == $pGameID || $trgArmy->get('controller') == $pGameID) { echo 'Remove unit ' . $outList[$i]; // Process this unit out of the army $outUnit->save('armyID', 0); $armyUnits->deleteByValue($outList[$i], $slotFile); } } // Review units being added to the army - process all that the player controls if he also controls the army if ($trgArmy->get('controller') == $pGameID) { for ($i = 0; $i < sizeof($inList); $i++) { $inUnit = loadUnit($inList[$i], $unitFile, 400); if ($inUnit->get('controller') == $pGameID) { // Update unit to be in army $inUnit->save('armyID', $postVals[1]); // Add to army unit list $armyUnits->addItem($inList[$i], $slotFile); } } } else { echo 'Can\'t add to an army you don\'t control!';
<?php /* This script processes disbanding an army*/ include './slotFunctions.php'; include './unitClass.php'; $unitFile = fopen($gamePath . '/unitDat.dat', 'rb'); $slotFile = fopen($gamePath . '/gameSlots.slt', 'rb'); // Load army data $trgArmy = loadUnit($postVals[1], $unitFile, 400); // Confirm that the player can disband the army if ($trgArmy->get('controller') != $pGameID) { exit('error 1-2111'); } // Load list of units in army $armyList = new itemSlot($trgArmy->get('unitListSlot'), $slotFile, 400); // Set the units to not be in any army for ($i = 1; $i <= sizeof($armyList->slotData); $i++) { if ($armyList->slotData[$i] > 0) { $trgUnit = loadUnit($armyList->slotData[$i], $unitFile, 400); $trgUnit->save('armyID', 0); } } // Remove the army from the list of player's units $playerObj = loadPlayer($pGameID, $unitFile, 400); $unitList = new itemSlot($playerObj->get('unitSlot'), $slotFile, 400); $unitList->deleteByValue($postVals[1], $slotFile); fclose($unitFile); fclose($slotFile);
fwrite($unitFile, pack('i', $newCityId)); // Remove the unit cart / other items from the map and change the mapslot to display the new city $mapSlotFile = fopen($gamePath . '/mapSlotFile.slt', 'r+b'); $mapSlotNum = floor($unitDat[2] / 120) * 120 + floor($unitDat[1] / 120); echo 'Mapo slot number is ' . $mapSlotNum . '<br>'; $mapSlot = new itemSlot($mapSlotNum, $mapSlotFile, 404); print_r($mapSlot->slotData); $currentPos = array_search($_SESSION['selectedItem'], $mapSlot->slotData); echo 'Current Pos: ' . $currentPos . '<br>'; if ($currentPos) { $mapSlot->deleteItem($currentPos, $mapSlotFile); } echo 'Add new city to map item List<br>'; $mapSlot->addItem($newCityId, $mapSlotFile); // Add this player to the credential list for the city echo 'Open city ' . $newCityId . '<br>'; $thisCity = new city($newCityId, $unitFile); $cityCredentials = new blockSlot($thisCity->cityData[19], $slotFile, 40); $addLoc = array_search(0, $cityCredentials->slotData); echo 'Add credintials to slot (' . $thisCity->cityData[19] . ')'; print_r($cityCredentials->slotData); $cityCredentials->addItem($slotFile, pack('i*', -9, $pGameID), $addLoc); // Change this cart object to a city object fseek($unitFile, $_SESSION['selectedItem'] * $defaultBlockSize + 12); fwrite($unitFile, pack('i', 1)); // Remove the cart from the list of military units the player controls $playerObj = new player($pGameID, $unitFile, 400); $unitList = new itemSlot($playerObj->get('unitSlot'), $slotFile, 40); $unitList->deleteByValue($_SESSION['selectedItem'], $slotFile); fclose($unitFile); fclose($slotFile);