$useRscSlot = $trgArmy->get('carrySlot'); } } else { $capacity = $workingUnit->get('carryCap'); echo 'Working unit stuff:'; print_r($workingUnit->unitDat); if ($workingUnit->get('carrySlot') == 0) { $newSlot = startASlot($unitSlotFile, "../users/userSlots.slt"); $workingUnit->set('carrySlot', $newSlot); $workingUnit->saveAll($unitFile); $useRscSlot = $newSlot; } else { $useRscSlot = $workingUnit->get('carrySlot'); } } $unitRSC = new blockSlot($useRscSlot, $unitSlotFile, 40); echo 'List of carried resources (Slot ' . $useRscSlot . ')'; print_r($unitRSC->slotData); $rscStart = [0, 0, 0]; for ($i = 1; $i < sizeof($unitRSC->slotData); $i += 2) { if ($unitRSC->slotData[$i] == $rscPoint[10]) { $rscStart[0] = $i; $rscStart[1] = $unitRSC->slotData[$i + 1]; } else { if ($unitRSC->slotData[$i] == 0) { $rscStart[2] = $i; } } $carried += $unitRSC->slotData[$i + 1]; } $capacity = $typeDesc[12];
function sendMessage($target, $subject, $msgContent, $replyTo, $msgType, $unitFile, $unitSlotFile) { global $gamePath, $pGameID; $msgSlotFile = fopen($gamePath . '/msgSlots.slt', 'r+b'); $trgObject = loadUnit($target, $unitFile, 400); //$trgObject = new unit($target, $unitFile, 400); //fseek($unitFile, $target*$defaultBlockSize); //$trgDat = unpack('i*', fread($unitFile, 400)); print_r($trgObject->unitDat); //Determine who all to send it to based on target type $toList = []; switch ($trgObject->unitDat[4]) { case 1: // a town object echo 'Send to all members of a town'; $townDat = new itemSlot($trgObject->unitDat[19], $unitSlotFile, 40); print_r($townDat->slotData); for ($i = 1; $i < sizeof($townDat->slotData); $i += 2) { if ($townDat->slotData[$i] < -1) { $toList[] = $townDat->slotData[$i + 1]; } } break; case 10: // a tribe object echo 'This is a tribe... send to ' . $trgObject->unitDat[6]; $toList[] = $trgObject->unitDat[6]; break; case 13: // a player object echo 'Send to player ' . $target; $toList[] = $target; } $sendList = array_unique($toList); if (sizeof($sendList) > 0) { for ($i = 0; $i < sizeof($sendList); $i++) { echo 'Record message for player ' . $sendList[$i]; $trgPlayer = loadPlayer($sendList[$i], $unitFile, 400); if ($trgPlayer->unitDat[25] == 0) { if (flock($msgSlotFile, LOCK_EX)) { fseek($msgSlotFile, 0, SEEK_END); $use_slot = max(1, ftell($msgSlotFile) / 40); fseek($msgSlotFile, $use_slot * 40 + 39); fwrite($msgSlotFile, pack("C", 0)); fflush($msgSlotFile); flock($msgSlotFile, LOCK_UN); // release the lock $trgPlayer->unitDat[25] = $use_slot; } echo 'Createa new message slot at ' . $trgPlayer->unitDat[25]; } $msgSlot = new blockSlot($trgPlayer->unitDat[25], $msgSlotFile, 40); // Set unread flag $trgPlayer->unitDat[5] = 1; $trgPlayer->saveAll($unitFile); // Record message contents in message file and message index $messageContentFile = fopen($gamePath . '/messages.dat', 'r+b'); // if message is a reply, get pvs info. if ($replyTo > 0) { fseek($messageContentFile, $replyTo); $pvsDat = explode('<-!->', fread($messageContentFile, 100)); $subject = substr($pvsDat[0], 16); } if (flock($messageContentFile, LOCK_EX)) { fseek($messageContentFile, 0, SEEK_END); $msgSpot = ftell($messageContentFile); //fwrite($subject); $blockLength = strlen($subject) + strlen($msgContent) + 5 + 4 + 4 + 4 + 4 + 4; // total length is subject length + message length + separator length + total length integer + time integer + sender ID + message ID in reply to + message type echo 'Message length is ' . $blockLength . ' (' . strlen($subject) . ') + (' . strlen($msgContent) . ') + 9 written at spot ' . $msgSpot . '<br> Subject: ' . $subject . '<br> Content: ' . $msgContent . '<br>'; fwrite($messageContentFile, pack('i*', $blockLength, time(), $pGameID, $replyTo, $msgType) . $subject . '<-!->' . $msgContent); $msgSlot->addItem($msgSlotFile, pack('i*', $msgSpot, 1, 1), $msgSlot->findLoc(0, 3)); // message start loc, message file num, read/unread } } } fclose($msgSlotFile); }
echo 'Record message for player ' . $sendList[$i]; $trgPlayer = loadPlayer($sendList[$i], $unitFile, 400); if ($trgPlayer->unitDat[25] == 0) { if (flock($slotFile, LOCK_EX)) { fseek($slotFile, 0, SEEK_END); $use_slot = max(1, ftell($slotFile) / 40); fseek($slotFile, $use_slot * 40 + 39); fwrite($slotFile, pack("C", 0)); fflush($slotFile); flock($slotFile, LOCK_UN); // release the lock $trgPlayer->unitDat[25] = $use_slot; } echo 'Createa new message slot at ' . $trgPlayer->unitDat[25]; } $msgSlot = new blockSlot($trgPlayer->unitDat[25], $slotFile, 40); // Set unread flag $trgPlayer->unitDat[5] = 1; $trgPlayer->saveAll($unitFile); // Record message contents in message file and message index $messageContentFile = fopen($gamePath . '/messages.dat', 'r+b'); // if message is a reply, get pvs info. if ($postVals[2] > 0) { fseek($messageContentFile, $postVals[2]); $pvsDat = explode('<-!->', fread($messageContentFile, 100)); $msg[1] = substr($pvsDat[0], 16); } if (flock($messageContentFile, LOCK_EX)) { fseek($messageContentFile, 0, SEEK_END); $msgSpot = ftell($messageContentFile); //fwrite($msg[1]);
// 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); //addtoSlotGen($gamePath.'/mapSlotFile.slt', $mapSlot, pack('i', $newID), $mapSlotFile, 404); fclose($mapSlotFile); } else { echo 'Not enough resources<br>'; foreach ($reqdRsc as $rscID => $rscQty) { echo 'Resource ' . $rscID . ': ' . ($cityRsc[$rscID] - $rscQty) . '<br>';
<?php include 'c:/websites/ib3/public_html/slotFunctions.php'; $testFile = fopen('testslot.slt', 'r+b'); fseek($testFile, 404 * 10 - 4); fwrite($testFile, pack('i', 0)); $sendData = pack('i*', 1, 2000); print_r(unpack('i*', $sendData)); $testSlot = new blockSlot(5, $testFile, 40); $addTarget = sizeof($testSlot->slotData); echo 'Add target os ' . $addTarget . '<br>'; $testSlot->addItem($testFile, $sendData, $addTarget); print_r($testSlot->slotData); fclose($testFile);
// Verify that the player can end the war fseek($warFile, $postVals[1] * $defaultBlockSize); $warDat = unpack('i*', fread($warFile, $warBlockSize)); if ($warDat[5] != $pGameID && $warDat[6] != $pGameID) { exit('erorr 1312-1'); } $sideSwitch = 1; $playerSide = 1; $oppside = 2; if ($warDat[6] == $pGameID) { // player is the defender $sideSwitch = -1; $playerSide = 2; $oppside = 1; } $requiredScore = [0, 0, 0, 0]; // Verify that the warscore is high enough to enforce the demand if ($warDat[8] < $requiredScore[$warDat[1]]) { exit('You cannot enforce these conditions'); } $aPlayer = loadPlayer($warDat[5], $unitFile, 400); $dPlayer = loadPlayer($warDat[6], $unitFile, 400); // update the diplomacy for both players to put in a truce $aDipSlot = new blockSlot($aPlayer->get('dipSlot'), $slotFile, 40); $dDipSlot = new blockSlot($dPlayer->get('dipSlot'), $slotFile, 40); $aDipSlot->addItem($slotFile, pack('i*', $warDat[6], 3, time(), 3 * 24 * 3600)); $dDipSlot->addItem($slotFile, pack('i*', $warDat[5], 3, time(), 3 * 24 * 3600)); // Make the demanded changes on the defender fclose($warFile); fclose($unitFile); fclose($slotFile);
$plotDat = unpack('i*', fread($taskFile, 200)); // check if character is already in the plot if ($plotDat[11] != 0) { $plotChars = new blockSlot($plotDat[11], $slotFile, 40); if (array_search($_SESSION['selectedItem'], $plotChars->slotData)) { echo 'Already in the plot'; exit; } } if ($plotDat[11] == 0) { $plotDat[11] = startASlot($slotFile, $gamePath . '/gameSlots.slt'); fseek($taskFile, $postVals[1] * 200 + 40); fwrite($taskFile, pack('i', $plotDat[11])); } echo 'Char slot for plot is ' . $plotDat[11] . '<br>'; $plotChars = new blockSlot($plotDat[11], $slotFile, 40); $loc = sizeof($plotChars->slotData); for ($i = 1; $i <= $plotChars->slotData; $i += 2) { if ($plotChars->slotData[$i] == 0) { $loc = $i; break; } } // Record plot in list of plaayer plots fseek($unitFile, $_SESSION['selectedItem'] * $defaultBlockSize); $unitDat = unpack('i*', fread($unitFile, 200)); //$plotChars->addItem($slotFile, pack('i*', $_SESSION['selectedItem'], 1), $loc); $plotChars->addItem($slotFile, pack('i*', $pGameID, 1), $loc); //echo 'Added character to plot at slot '.$plotDat[11]; fseek($unitFile, $unitDat[6] * $defaultBlockSize); $controllerDat = unpack('i*', fread($unitFile, 200));
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"); echo 'Unit slot is ' . $unitSlot . '<br>'; $unitList = new itemSlot($unitSlot, $gameSlot, 40); // Create a new town $townID = 0; $armyID = 0; $townSlot = 0; if ($startTown) { $townID = $unitIndex; $unitIndex += 4; $townDtls = [$startLocation[1], $startLocation[2], $pGameID, $postVals[1]]; $townData = newTown($townID, $unitFile, $gameSlot, $townDtls); // Record first city location in a new settlments slot
break; case 8: // made a new warband // Record in player unit list echo 'Add to slot ' . $playerDat[22]; $unitList = new itemSlot($playerDat[22], $slotFile, 40); $unitList->addItem($useBldg->unitDat[$postVals[2] + 18], $slotFile); break; } // Release building production slot $useBldg->unitDat[$postVals[2] + 18] = 0; // Add unit to map location slot $mapSlotNum = floor($trgUnit->unitDat[2] / 120) * 120 + floor($trgUnit->unitDat[1] / 120); $mapSlotFile = fopen($gamePath . '/mapSlotFile.slt', 'r+b'); if (flock($mapSlotFile, LOCK_EX)) { $mapSlot = new blockSlot($mapSlotNum, $mapSlotFile, 404); /// start, file, size $loc = sizeof($mapSlot->slotData); for ($m = 1; $m < sizeof($mapSlot->slotData); $m += 2) { if ($mapSlot->slotData[$m] == 0) { $loc = $m; break; } } $mapSlot->addItem($mapSlotFile, pack('i*', $useBldg->unitDat[$postVals[2] + 18], 0), $loc); // unit ID, not visible fflush($mapSlotFile); flock($mapSlotFile, LOCK_UN); } fclose($slotFile); fclose($mapSlotFile);
// Remove from old slot file and add to new slot file $oldSlotItem = new blockSlot($oldSlot, $mapSlotFile, 404); $loc = $oldSlotItem->findLoc($postVals[1], 2); $oldSlotItem->addItem($mapSlotFile, pack('i*', 0, 0), $loc); $newSlotItem = new blockSlot($newSlot, $mapSlotFile, 404); $loc = $newSlotItem->findloc(0, 2); $newSlotItem->addItem($mapSlotFile, pack('i*', $postVals[1], $showOnMap), $loc); fseek($unitFile, $postVals[1] * $defaultBlockSize + 100); fwrite($unitFile, pack('i', $newSlot)); echo 'Old Slot:<br>'; print_r($oldSlotItem->slotData); echo '<p>New Slot<br>'; print_r($newSlotItem->slotData); } else { // Adjust to show or not show the unit depending upon the showOnMap value $newSlotItem = new blockSlot($newSlot, $mapSlotFile, 404); $loc = $newSlotItem->findloc(0, 2); $newSlotItem->addItem($mapSlotFile, pack('i*', $postVals[1], $showOnMap), $loc); } // Record new location of unit fseek($unitFile, $postVals[1] * $defaultBlockSize); fwrite($unitFile, pack('i*', $newLoc[1], $newLoc[2])); // Record new energy level of unit fseek($unitFile, $postVals[1] * $defaultBlockSize + 60); fwrite($unitFile, pack('i', $actionPoints)); // Record Current Slot and last update time for unit fseek($unitFile, $postVals[1] * $defaultBlockSize + 100); fwrite($unitFile, pack('i*', $newSlot, time())); // Output results to browser echo '<script> setUnitAction(' . $postVals[1] . ', ' . $actionPoints / 1000 . ');
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);
function adjustRsc($rscID, $qty, $slotFile) { $location = 0; $townRsc = new blockSlot($this->get('carrySlot'), $slotFile, 40); $data = pack('i*', $rscID, $qty); for ($i = 1; $i <= sizeof($townRsc->slotData); $i += 2) { if ($townRsc->slotData[$i] == $rscID) { $location = $i; $data = pack('i*', $rscID, $townRsc->slotData[$i + 1] + $qty); break; } else { if ($townRsc->slotData[$i] == 0) { $location = $i; } } } if ($location > 0) { $townRsc->addItem($slotFile, $data, $location); } else { $townRsc->addItem($slotFile, $data); } }