// Save new slot to city information fseek($unitFile, $cityID * $defaultBlockSize + 36); fwrite($unitFile, pack('i', $cityDat[10])); } addDataToSlot($gamePath . '/gameSlots.slt', $cityDat[10], pack('i', $newID), $slotFile); echo '<p>New unit ID is ' . $newID . '<br>'; // add a task to the town as an "in progress" task // Create a new task to be processed. $taskFile = fopen($gamePath . '/tasks.tdt', 'r+b'); $parameters = pack('i*', intval($postVals[1] / 2) * 2, intval($postVals[2] / 2) * 2, 1, time(), $buildPts[0], 0, 2, $cityID, 0, $cityID, $newID, $postVals[3]); $newTask = createTask($taskFile, $parameters); //createTask($taskFile, $taskIndex, $duration, $parameters, $gamePath, $slotFile) fclose($taskFile); echo '<p>Parameters:'; print_r(unpack('i*', $parameters)); addDataToSlot($gamePath . '/gameSlots.slt', $cityDat[21], pack('i', $newTask), $slotFile); // this is for adding to a map slot -> addtoSlotGen($gamePath.'/gameSlots.slt', $cityDat[21], pack('i', $taskIndex), $slot_file, 40) // function addtoSlotGen($slot_handle, $check_slot, $addData, $slot_file, $slotSize) // add the building to the map file at the specified location $mapSlot = floor($postVals[2] / 120) * 120 + floor($postVals[1] / 120); $mapSlotFile = fopen($gamePath . '/mapSlotFile.slt', 'r+b'); //$mapSlot->addItem($mapSlotFile, pack('i*', $townID, 1), $mLoc); // file, bin value, loc $mSlotItem = new blockSlot($mapSlot, $mapSlotFile, 404); //$mSlotItem->addItem($newID, $mapSlotFile); $mLoc = sizeof($mSlotItem->slotData); for ($i = 1; $i <= sizeof($mSlotItem->slotData); $i += 2) { if ($mSlotItem->slotData[$i] == 0) { $mLoc = $i; break; } } $mSlotItem->addItem($mapSlotFile, pack('i*', $newID, 1), $mLoc);
} $startLocation = [4800 + $pGameID, 5260 + $pGameID]; //$pGameID = $_SESSION['gameIDs'][$_GET['gid']]; $gameSlot = fopen($gamePath . "/gameSlots.slt", "r+b"); // Create player character $newCharID = $unitIndex; $unitIndex += 4; fseek($unitFile, $newCharID * $defaultBlockSize); fwrite($unitFile, pack("i*", $startLocation[0], $startLocation[1], 1, 4, $postVals[1], $postVals[1], 1, 0, 0, 1)); //fseek($unitFile, $newCharID*$defaultBlockSize+36); //fwrite($unitFile, pack("i*", , 1, 1, $pGameID, $pGameID, 1, 1, 1)); // first name, second name, honoriffic, A controller, R controller, x Loc, yLoc fseek($unitFile, $newCharID * $defaultBlockSize + $unitBlockSize - 1); fwrite($unitFile, pack("C", 0)); // Add character to player slot $charSlot = startASlot($gameSlot, $gamePath . "/gameSlots.slt"); addDataToSlot($gamePath . "/gameSlots.slt", $charSlot, pack("i", $newCharID), $gameSlot); echo 'Char slot is ' . $charSlot . '<br>'; // Make a position slot to hold this character's leadership position in the town $positionSlot = startASlot($gameSlot, $gamePath . "/gameSlots.slt"); fseek($unitFile, $newCharID * $defaultBlockSize + 48); fwrite($unitFile, pack('i', $positionSlot)); // Create map slot file IF it doesn't already exist $mapSlotFile = fopen($gamePath . '/mapSlotFile.slt', 'r+b'); //fseek($mapSlotFile, 120*90*404-4); //fwrite($mapSlotFile, pack('i', 0)); $mapSlotNum = floor($startLocation[1] / 120) * 120 + floor($startLocation[0] / 120); echo 'Record units at slot' . $mapSlotNum; $mapSlot = new blockSlot($mapSlotNum, $mapSlotFile, 404); /// start, file, size // Create a unit slot for the player $unitSlot = startASlot($gameSlot, $gamePath . "/gameSlots.slt");
fseek($gameSlotFile, 39); fwrite($gameSlotFile, pack("C", 0)); fseek($gameSlotFile, 0); //Create list of players in game $pGameID = 1; $newFile = fopen("../games/" . $newGameId . "/players.Dat", "wb"); fwrite($newFile, pack("i*", $_SESSION['playerId'], -1)); fclose($newFile); // Update parameters file $paramFile = fopen("../games/" . $newGameId . "/params.ini", "r+b"); fwrite($paramFile, pack("N", time())); fseek($paramFile, 199); fwrite($paramFile, pack("C", 0)); fclose($paramFile); // add Game ID to player game list if ($gameSlot[1] == 0) { echo "get new Slot"; $uSlot = fopen("../users/userSlots.slt", "r+b"); $newSlot = startASlot($uSlot, "../users/userSlots.slt"); fseek($uDatFile, $_SESSION['playerId'] * 500 + 8); fwrite($uDatFile, pack("N", $newSlot)); addDataToSlot("../users/userSlots.slt", $newSlot, pack("N", $newGameId), $uSlot); fclose($uSlot); } else { echo "Add game to slot"; $uSlot = fopen("../users/userSlots.slt", "r+b"); addDataToSlot("../users/userSlots.slt", $gameSlot[1], pack("N", $newGameId), $uSlot); fclose($uSlot); } fclose($gameSlotFile); fclose($uDatFile);
} else { echo 'Major lock error'; } fseek($unitFile, $newID * $defaultBlockSize); fwrite($unitFile, pack('i*', $cityDat[1], $cityDat[2], 0, 9, $cityID, $cityID, 0, 1, 1, $postVals[1], 0, 0, 0, 0, $cityID, 0, 0, 0, 1, 0, 0, 0, $bldgType[11])); // Verify that city building slot exists and create one if needed. if ($cityDat[17] == 0) { // Need to create a new slot echo 'Making a new slot'; $cityDat[17] = startASlot($slotFile, $gamePath . '/gameSlots.slt'); //startASlot($slot_file, $slot_handle) fseek($unitFile, $cityID * $defaultBlockSize + 64); fwrite($unitFile, pack('i', $cityDat[17])); } // Record new building in city buildign slot addDataToSlot($gamePath . '/gameSlots.slt', $cityDat[17], pack('i', $newID), $slotFile); //writeBlocktoSlot($gamePath.'/gameSlots.slt', $cityDat[17], pack('i*', 0, $newID), $slotFile, 40); // function writeBlocktoSlot($slotHandle, $checkSlot, $addData, $slotFile, $slotSize) echo '<p>New unit ID is ' . $newID . '<br>'; // add a task to the town as an "in progress" task // Create a new task to be processed. $buildingPoints = explode(',', $bldgType[2]); $taskFile = fopen($gamePath . '/tasks.tdt', 'r+b'); $parameters = pack('i*', $cityDat[1], $cityDat[2], 1, time(), $buildingPoints[0], 0, 2, $cityID, 0, $cityID, $newID, $postVals[1]); $newTask = createTask($taskFile, $parameters); //createTask($taskFile, $taskIndex, $duration, $parameters, $gamePath, $slotFile) fclose($taskFile); echo '<p>Parameters:'; print_r(unpack('i*', $parameters)); // Record task in city task list // Verify that slot exists and create one if needed. if ($cityDat[21] == 0) {