if ($trgUnit->get('armyID') > 0) { $army = loadUnit($trgUnit->get('armyID'), $unitFile, 40); if ($army->get('commander') > 0) { $commander = loadUnit($army->get('commander'), $unitFile, 40); $commandTraits = new itemSlot($commander->get('traitSlot'), $slotFile, 40); for ($i=1; $i<=sizeof($commandTraits->slotData); $i++) { $totalBuff += $charBuffMask[$commandTraits->slotData]; } } } // Check for city boosts */ // Calculate actionpoints used in transporting to the city $parentCity = loadUnit($trgPoint->get('parentCity'), $unitFile, 400); $xDist = $trgPoint->get('xLoc') - $parentCity->get('xLoc'); $yDist = $trgPoint->get('yLoc') - $parentCity->get('yLoc'); $parentDst = floor(sqrt($xDist * $xDist + $yDist * $yDist)); // Calculate amount of resources produced $usedPoints = min($trgUnit->actionPoints(), $postVals[3]); $productionPoints = max(0, $usedPoints - $trgDst - $parentDst); echo 'Production Points = min(' . $trgUnit->actionPoints() . ', ' . $postVals[3] . ') - ' . $trgDst . ' - ' . $parentDst; $useTime = time(); $currentCondition = min($trgPoint->get('maxCondition'), floor($trgPoint->get('conditionPoints') + $trgPoint->get('recoveryRate') * ($useTime - $trgPoint->get('updateTime')) / 3600)); $maxCond = max($trgPoint->get('maxCondition'), 1); $rscProd = $totalBuff * $productionPoints * $trgPoint->get('baseProd') * $currentCondition / ($maxCond * 100); echo 'Production = ' . $totalBuff . ' * ' . $productionPoints . ' * ' . $trgPoint->get('baseProd') . ' * ' . $currentCondition . ' / (' . $maxCond . ' * 100)'; $currentCondition -= $productionPoints; // Record the new condition for the site $trgPoint->save('updateTime', $useTime);
//Load the unit $selectedUnit = loadUnit($postVals[1], $unitFile, 400); print_R($selectedUnit); echo '<script>//var selectHead = selectionHead("rtPnl"); var selectHead = addDiv("abcded", "stdContainer", "rtPnl"); '; // Look for nearby settlements that you can drop resources in $mapSlot = floor($selectedUnit->get('yLoc') / 120) * 120 + floor($selectedUnit->get('xLoc') / 120); //echo 'Mapslot is '.$mapSlot.' from '.$selectedUnit->get('xLoc').', '.$selectedUnit->get('yLoc'); $mapSlotFile = fopen($gamePath . '/mapSlotFile.slt', 'rb'); $gridList = new itemSlot($mapSlot, $mapSlotFile, 404); //print_r($gridList->slotData); for ($i = 1; $i <= sizeof($gridList->slotData); $i += 2) { if ($gridList->slotData[$i] > 0) { //echo 'Load unit ('.$gridList->slotData[$i].')'; $checkObj = loadUnit($gridList->slotData[$i], $unitFile, 400); // Check to see if unit is a city if ($checkObj->get('uType') == 1) { // Check to get city permissions $credList = array_filter(unpack("i*", readSlotData($slotFile, $checkObj->unitDat[19], 40))); $approved = checkCred($pGameID, $credList); if ($approved) { // display the place as an option to drop the stuff echo 'unitList.newUnit({unitType:"town", unitID:' . $gridList->slotData[$i] . ', unitName:"Town ' . $gridList->slotData[$i] . '", actionPoints:"0", strength:75, tNum:"0"}); var objContain = addDiv("", "selectContain", rtPnl); unitList.renderSum(' . $gridList->slotData[$i] . ', objContain); selectButton(objContain, "hai", ' . $gridList->slotData[$i] . ', [selectHead]);'; } } } }
<?php include './slotFunctions.php'; //include('./bldgObjects.php'); include './cityClass.php'; include './unitClass.php'; //echo 'Specific building information for building '.$postVals[1].' <br> //This might include specific options for the selected building and type.'; // Get building information $unitFile = fopen($gamePath . '/unitDat.dat', 'rb'); $targetBuilding = loadUnit($postVals[1], $unitFile, 400); //fseek($unitFile, $postVals[1]*$defaultBlockSize); //$bldgDat = unpack('i*', fread($unitFile, $defaultBlockSize)); $bldgInfo = explode('<->', file_get_contents($scnPath . '/buildings.desc')); $typeInfo = explode('<-->', $bldgInfo[$targetBuilding->unitDat[10]]); echo '<script> useDeskTop.newPane("bldgInfo"); thisDiv = useDeskTop.getPane("bldgInfo"); thisDiv.innerHTML = ""; '; //print_r($targetBuilding); switch ($targetBuilding->unitDat[7]) { case 0: echo 'textBlob("descriptiveBlob", thisDiv, "This building is still under construction."); textBlob("descriptiveBlob", thisDiv, "This building is still under construction.");'; break; case 1: // Show upgrade options for this building echo ' unitList.renderSum(' . $postVals[1] . ', thisDiv); var bldg_' . $postVals[1] . ' = makeTabMenu("bldg_' . $postVals[1] . '", thisDiv);
$availablePoints = min($postVals[3], $workUnit->actionPoints()); // Check for buffs/nerfs for the city $parentCity = loadUnit($trgTask->taskDat[10], $unitFile, 400); $neededPts = $trgTask->taskDat[5] - $trgTask->taskDat[6]; $usedPoints = min($availablePoints, $neededPts); echo 'Use ' . $usedPoints . ' Points'; // Record new stats for unit production if ($usedPoints > 0) { // Updadate stats for producing building $workUnit->unitDat[16] = $workUnit->actionPoints() - $usedPoints; $workUnit->unitDat[27] = time(); if ($trgTask->taskDat[6] + $usedPoints >= $trgTask->taskDat[5]) { // Process completion of building construction // create a new building echo 'Task complete (' . $trgTask->taskDat[6] . ' + ' . $usedPoints . ' >= ' . $trgTask->taskDat[5] . ')'; $newBuilding = loadUnit($trgTask->taskDat[11], $unitFile, 400); //$newBuilding = new building($trgTask->taskDat[11], $unitFile); //$newBuilding->unitDat = array_fill(1, 100, 0); $newBuilding->unitDat[1] = $workUnit->unitDat[1]; // Building X $newBuilding->unitDat[2] = $workUnit->unitDat[2]; // Building Y $newBuilding->unitDat[7] = 1; // Set Status to complete $newBuilding->unitDat[10] = $trgTask->taskDat[12]; // Building Type $newBuilding->unitDat[16] = 0; // Energy $newBuilding->unitDat[17] = 4167; // Energy Regen Rate $newBuilding->unitDat[27] = time();
// Load the unit dat from the parameters file $unitDesc = explode('<->', file_get_contents($scnPath . '/units.desc')); $uTypeDesc = explode('<-->', $unitDesc[$unitType]); print_r($uTypeDesc); // Verify that the building can create this unit type // Verify that the building prerequisites for this unit are met // Verify that the resource prerequisites for this unit are met // Get player information for slot fseek($unitFile, $pGameID * $defaultBlockSize); $playerDat = unpack('i*', fread($unitFile, 200)); // Get city information for where the unit is being trained fseek($unitFile, $_SESSION['selectedItem'] * $defaultBlockSize); $cityDat = unpack('i*', fread($unitFile, 400)); // create a unit from template dat $templateFile = fopen($scnPath . '/charTemplates.dat', 'r+b'); $newUnit = loadUnit($unitType * 4, $templateFile, 400); fclose($templateFile); // Record specifics for this unit $typeDetails = explode(",", $uTypeDesc[1]); $newUnit->set("xLoc", $cityDat[1]); $newUnit->set("yLoc", $cityDat[2]); $newUnit->set("owner", $pGameID); $newUnit->set("controller", $pGameID); $newUnit->set("updateTime", time()); $newUnit->set("troopType", $postVals[2]); $newUnit->unitDat[4] = $typeDetails[3]; $newUnit->unitDat[19] = $uTypeDesc[2]; // Need to get a new unit ID and save to that unit ID in the unit file if (flock($unitFile, LOCK_EX)) { // acquire an exclusive lock fseek($unitFile, 396, SEEK_END);
$slotFile = fopen($gamePath . '/gameSlots.slt', 'r+b'); // postvas - > 1 is army ID // verify that player controls the army in question // Commander of army can drop and add units // Owner of units can pull the units from the army echo '<script> useDeskTop.newPane("selUnits"); thisDiv = useDeskTop.getPane("selUnits"); var thisGroup = groupSort(thisDiv, ' . $postVals[1] . ', 1108);'; $trgArmy = loadUnit($postVals[1], $unitFile, 400); // Can add/remove units from this army $armyUnits = new itemSlot($trgArmy->get('unitListSlot'), $slotFile, 40); for ($i = 1; $i <= sizeof($armyUnits->slotData); $i++) { if ($armyUnits->slotData[$i] > 0) { $unitObj = loadUnit($armyUnits->slotData[$i], $unitFile, 400); if ($trgArmy->get('owner') == $pGameID || $trgArmy->get('controller') == $pGameID || $unitObj->get('controller') == $pGameID) { echo 'var objContain = addDiv("", "selectContain", thisGroup.left); unitList.newUnit({unitType:"warband", unitID:' . $armyUnits->slotData[$i] . ', unitName:"unit Name", actionPoints:0, strength:75, tNum:' . $unitObj->get('uType') . '}); unitList.renderSum(' . $armyUnits->slotData[$i] . ', objContain); groupButton(objContain, ' . $armyUnits->slotData[$i] . ');'; } else { echo 'var objContain = addDiv("", "selectContain", armyDiv); unitList.newUnit({unitType:"warband", unitID:' . $armyUnits->slotData[$i] . ', unitName:"unit Name", actionPoints:0, strength:75, tNum:' . $unitObj->get('uType') . '}); unitList.renderSum(' . $armyUnits->slotData[$i] . ', thisGroup.left); groupButton(objContain, ' . $armyUnits->slotData[$i] . ');'; } } } // Verify that the player controls the units in question fclose($unitFile);
<?php include './slotFunctions.php'; include './unitClass.php'; // Get slot for units for this group $unitFile = fopen($gamePath . '/unitDat.dat', 'rb'); //fseek($unitFile, $postVals[1]*$defaultBlockSize); //$groupDat = unpack('i*', fread($unitFile, $unitBlockSize)); $thisGroup = loadUnit($postVals[1], $unitFile, 400); // Read all units in this group $slotFile = fopen($gamePath . '/gameSlots.slt', 'rb'); //readSlotData($file, $slot_num, $slot_size) //$unitList = array_filter(unpack("N*", readSlotData($slotFile, $groupDat[14], 40))); $unitList = new itemSlot($thisGroup->get('unitListSlot'), $slotFile, 40); foreach ($unitList->slotData as $listUnitID) { fseek($unitFile, $listUnitID * $defaultBlockSize); $unitDat = unpack('i*', fread($unitFile, $unitBlockSize)); } // Show orders available for this army group based on the unit types present // Load resources carried by this army if ($thisGroup->get('carrySlot') > 0) { $rscSlot = new blockSlot($thisGroup->get('carrySlot'), $slotFile, 40); print_r($rscSlot->slotData); } else { echo 'Carrying nothing'; } echo '<script> dropOpt = textBlob("", "rtPnl", "Drop Resources"); dropOpt.addEventListener("click", function() {scrMod("1105,' . $postVals[1] . '")}); addOpt = textBlob("", "rtPnl", "Add/Drop Units"); addOpt.addEventListener("click", function() {scrMod("1107,' . $postVals[1] . '")});
<?php include './unitClass.php'; //print_r($postVals); $unitID = $postVals[2] * 255 + $postVals[3]; $unitFile = fopen($gamePath . '/unitDat.dat', 'rb'); /* fseek($unitFile, $unitID*$defaultBlockSize); $unitDat = unpack('i*', fread($unitFile, $unitBlockSize)); */ $thisUnit = loadUnit($unitID, $unitFile, 400); //print_r($thisUnit->); $_SESSION['selectedItem'] = $unitID; if ($thisUnit->get('controller') == $pGameID || $thisUnit->get('controller') == 0) { include '../gameScripts/objects/obj_' . $thisUnit->get('uType') . '.php'; } else { if ($thisUnit->get('owner') == $pGameID) { include '../gameScripts/objects/obj_' . $thisUnit->get('uType') . 'b.php'; } else { //include('../gameScripts/objects/obj_'.$thisUnit->get('uType').'c.php'); include '../gameScripts/1096.php'; } } fclose($unitFile);
$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!'; } fclose($unitFile); fclose($slotFile);
<?php require_once './slotFunctions.php'; require_once './unitClass.php'; $unitFile = fopen($gamePath . '/unitDat.dat', 'r+b'); $thisPlayer = loadPlayer($pGameID, $unitFile, 400); // Verify that the unit is indeed a city $playerCity = loadUnit($postVals[1], $unitFile, 400); echo 'Loaded city (' . $postVals[1] . ') type:' . get_class($playerCity); // save as players primary if (get_class($playerCity) == "settlement") { $thisPlayer->save('homeCity', $postVals[1]); } else { echo 'Not a city'; } fclose($unitFile);
$thisOffer = unpack('i*', fread($mercFile, 100)); // Load unit information $trgUnit = loadUnit($thisOffer[2], $unitFile, 400); echo 'var objContain = addDiv("", "selectContain", rtPnl); unitList.newUnit({unitType:"warband", unitID:' . $thisOffer[2] . ', unitName:"unit Name", actionPoints:0, strength:75, tNum:' . $trgUnit->get('uType') . '}); unitList.renderSum(' . $thisOffer[2] . ', objContain); var newButton = addDiv("button", "button", objContain); newButton.addEventListener("click", function () {passClick("1117,' . $mercOffers->slotData[$i] . '")});'; } } // Show list of player controlled units that can be sold $thisPlayer = loadPlayer($pGameID, $unitFile, 400); $playerUnits = new itemSlot($thisPlayer->get('unitSlot'), $slotFile, 40); for ($i = 1; $i <= sizeof($playerUnits->slotData); $i++) { if ($playerUnits->slotData[$i] > 0) { $checkUnit = loadUnit($playerUnits->slotData[$i], $unitFile, 400); if ($checkUnit->mercApproved) { if ($checkUnit->get('armyID') == 0) { echo 'var objContain = addDiv("units to sell", "selectContain", rtPnl); unitList.newUnit({unitType:"warband", unitID:' . $playerUnits->slotData[$i] . ', unitName:"unit Name", actionPoints:0, strength:75, tNum:' . $checkUnit->get('uType') . '}); unitList.renderSum(' . $playerUnits->slotData[$i] . ', objContain); var newButton = addDiv("", "button", objContain); newButton.innerHTML = "Pimp Unit"; newButton.addEventListener("click", function() {scrMod("1118,' . $playerUnits->slotData[$i] . '")});'; } } } } echo '</script>'; fclose($mercFile); fclose($unitFile);
<?php include './slotFunctions.php'; include './unitClass.php'; include './cityClass.php'; /* Process work on a building production item Post Vals 1 = Building ID, 2 = Production Slot #, 3 = % */ echo 'Work at building ' . $postVals[1]; $unitFile = fopen($gamePath . '/unitDat.dat', 'r+b'); // Get data for building producing the item $useBldg = loadUnit($postVals[1], $unitFile, 400); $trgUnit = loadUnit($useBldg->unitDat[$postVals[2] + 18], $unitFile, 400); $trgTown = loadUnit($useBldg->get('parentCity'), $unitFile, 400); // Load applicable building and character boosts /*/// Run through list of city offices/characters and apply relevant boosts $numTraits = 100; $numBuildings = 100; // Load buff mask for this production item $buffFile = fopen($scnPath.'/type2buffs.bdf', 'r+b'); fseek($buffFile, $trgUnit->get('uType')*($numTraits+$numBuildings)*2); $buffDat = fread($buffFile, ($numTraits+$numBuildings)*2); $charBuffMask = unpack('s*', substr($buffDat, 0, $numTraits*2); $bldgBuffMask = unpack('s*', substr($buffDat, $numTraits*2); $totalBuff = 0; if ($trgTown->get($townerLeaders) > 0 ) { // Load list of city characters $townLeaders = new itemSlot($trgTown->get('townLeaders'), $slotFile, 40);
<?php include './unitClass.php'; $_SESSION['selectedItem'] = $postVals[1]; $unitFile = fopen($gamePath . '/unitDat.dat', 'rb'); $thisChar = loadUnit($postVals[1], $unitFile, 400); if ($thisChar->get('owner') == $pGameID) { include '../gameScripts/1074a.php'; } else { if ($thisChar->get('controller') == $pGameID) { include '../gameScripts/1074b.php'; } else { //include('../gameScripts/1074c.php'); include '../gameScripts/1096.php'; } }
useDeskTop.newPane("characters"); thisDiv = useDeskTop.getPane("characters"); taskList.newUnit({unitType:"task", unitID:' . $postVals[1] . ', unitName:"Task #' . $postVals[1] . ' on ' . $taskDat[11] . '", actionPoints:' . $taskDat[6] . ', reqPts:' . $taskDat[5] . ', strength:75}); taskList.renderSum(' . $postVals[1] . ', thisDiv) var thisTask = makeTabMenu("newChars", thisDiv); var taskDesc = newTab("newChars", 1, "Description"); var taskWork = newTab("newChars", 2, "Workers available"); tabSelect("newChars", 1);'; //print_r($unitList->slotData); foreach ($unitList->slotData as $unitID) { //echo 'CHeck '.$unitID; //fseek($unitFile, $unitID*$defaultBlockSize); //$unitDat = unpack('i*', fread($unitFile, $unitBlockSize)); $unitDetail = loadUnit($unitID, $unitFile, 400); if ($unitDetail->get('uType') == 8) { // this is an elligable civilian unit if ($unitDetail->get('xLoc') == $taskDat[1] && $unitDetail->get('yLoc') == $taskDat[2]) { // this unit is at the task location and can add points $noUnitsHere = false; $actionPoints = $unitDetail->actionPoints(); // Get total number of production points available for this unit // Show option to add production points to this task /* echo ' unitList.newUnit({unitType:"warband", unitID:'.$unitID.', unitName:"unit name", actionPoints:'.$actionPoints.', strength:75, tNum:'.$unitDat[4].'}); var objContain = addDiv("", "selectContain", taskWork); unitList.renderSum('.$unitID.', objContain); var newButton = optionButton("", objContain, "25%"); newButton.objectID = "'.$postVals[1].','.$unitID.',1";
<?php /* Post Vals: 1 = spy ID, 2 = target ID, 3 = actionpoints Used */ include './unitClass.php'; include './slotFunctions.php'; $unitFile = fopen($gamePath . '/unitDat.dat', 'rb'); $intelFile = fopen($gamePath . '/intel.slt', 'rb'); $slotFile = fopen($gamePath . '/gameSlots.slt', 'rb'); // Load the source object gathering the intel $spyUnit = loadUnit($postVals[1], $unitFile, 400); echo 'Spy unit is a ' . get_class($spyUnit); // verify source has enough action points to perform the observation $usePoints = min($spyUnit->actionPoints(), $postVals[3]); if ($usePoints < 1) { exit("No action points to use"); } // Deduct the observation points used $spyUnit->adjustEnergy(-$usePoints); // Load the target object $trgUnit = loadUnit($postVals[2], $unitFile, 400); // Compare source and target skills to determine outcome $spySkills = new itemSlot($spyUnit->get('traitSlot'), $slotFile, 40); $trgSkills = new itemSlot($trgUnit->get('traitSlot'), $slotFile, 40); // Produce a report of the info gathered fclose($intelFile); fclose($unitFile); fclose($slotFile);
<?php /* Process sending a message to something - this script determines the object type and players that should receive the message. Send the message to this script in the following form form: */ include "./slotFunctions.php"; include "./unitClass.php"; $slotFile = fopen($gamePath . '/msgSlots.slt', 'r+b'); $unitSlotFile = fopen($gamePath . '/gameSlots.slt', 'rb'); $msg = explode('<!*!>', substr($_POST['val1'], 5)); print_r($msg); // look up player information to get slot IDS $unitFile = fopen($gamePath . '/unitDat.dat', 'r+b'); // Determine which players should receive the message $trgObject = loadUnit($msg[0], $unitFile, 400); //$trgObject = new unit($msg[0], $unitFile, 400); //fseek($unitFile, $msg[0]*$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];
newTab("bldg", 3, "Player Buildings"); tabSelect("bldg", 1); ';*/ echo '<script> useDeskTop.newPane("cityBldg"); thisDiv = useDeskTop.getPane("cityBldg"); thisDiv.innerHTML = ""; var bldgTabs = makeTabMenu("bldgMenu", thisDiv); var bldgTabs_1 = newTab("bldgMenu", 1, "Buildings"); var bldgTabs_2 = newTab("bldgMenu", 2, "Construct"); var bldgTabs_3 = newTab("bldgMenu", 3, "Town Buildings");'; $bldgList = array_filter(unpack("i*", readSlotData($slotFile, $cityDat[17], 40))); foreach ($bldgList as $bldgID) { //fseek($unitFile, $bldgID*$defaultBlockSize); //$bldgDat = unpack('i*', fread($unitFile, 400)); $checkBldg = loadUnit($bldgID, $unitFile, 400); $buildingInfo = explode('<-->', $buildingTypes[$checkBldg->unitDat[10]]); //print_r($bldgDat); //$actionPoints = min(1000, $checkBldg->unitDat[16] + floor((time()-$checkBldg->unitDat[27])*4167/360000)); //$actionPoints = min(1000, $bldgDat[16] + floor((time()-$bldgDat[27])/$bldgDat[17])); echo 'unitList.newUnit({unitType:"building", unitID:' . $bldgID . ', unitName:"' . $buildingInfo[0] . '", actionPoints:' . $checkBldg->actionPoints() . '}); unitList.renderSum(' . $bldgID . ', bldgTabs_1);'; //echo 'newBldgSum("'.$bldgID.'", "bldg_tab1", .5, '.$bldgDat[7].');'; } // Generate a list of common buildings that can be built at this location for ($i = 1; $i < sizeof($buildingTypes); $i++) { $bldgTypeInfo = explode('<-->', $buildingTypes[$i]); $bldgClass = explode(',', $bldgTypeInfo[1]); if ($bldgClass[2] == 1) { $cultureList = explode(',', $bldgTypeInfo[9]); for ($j = 0; $j < sizeof($bldgTypeInfo[9]); $j++) {
$mapSlot = floor($thisUnit->get('yLoc') / 120) * 120 + floor($thisUnit->get('xLoc') / 120); $gridList = new itemSlot($mapSlot, $mapSlotFile, 404); $matchCount = 0; echo '<script> var indieList = [];'; for ($i = 1; $i <= sizeof($gridList->slotData); $i += 2) { $mapUnit = loadUnit($gridList->slotData[$i], $unitFile, 400); if ($thisUnit->get('xLoc') == $mapUnit->get('xLoc') && $thisUnit->get('yLoc') == $mapUnit->get('yLoc')) { // units are at the same spot - can they be put together? if ($mapUnit->get('uType') == 2) { // Load army units for display $armyUnitList = new itemSlot($mapUnit->get('unitListSlot'), $slotFile, 40); echo 'armyBox = addDiv("", "stdContain", rtPnl);'; for ($j = 1; $j <= sizeof($armyUnitList->slotData); $j++) { $matchCount++; $armyUnit = loadUnit($armyUnitList->slotData[$j], $untiFile, 400); echo 'unitList.newUnit({unitType:"warband", unitID:' . $armyUnitList->slotData[$j] . ', unitName:"some unit", actionPoints:100, strength:75, tNum:' . $armyUnit->get('uType') . '}); unitList.renderSum(' . $armyUnitList->slotData[$j] . ', armyBox);'; } } else { if ($mapUnit->get('uType') == 6 || $mapUnit->get('uType') == 8) { $matchCount++; echo 'unitList.newUnit({unitType:"warband", unitID:' . $gridList->slotData[$i] . ', unitName:"some unit", actionPoints:100, strength:75, tNum:' . $mapUnit->get('uType') . '}); indieList.push(' . $gridList->slotData[$i] . ');'; } } } } if ($matchCount > 0) { echo 'indieBox = addDiv("", "stdContain", rtPnl); for (var i=0; i<indieList.length; i++) {
$objList[] = $postVals[$check + 1]; } $offerStrings[$offers] = pack('i*', 2, $postVals[$check + 1]); $check += 2; break; default: $offerStrings[$offers] = pack('i*', 0, 0, 0); break; } $offers++; } $neededRsc = []; if ($rscCheck) { // Verify that requested resources are available and place them in "escrow" $thisPlayer = loadPlayer($pGameID, $unitFile, 400); $playerCity = loadUnit($thisPlayer->get('homeCity'), $unitFile, 400); $rscList = new itemSlot($playerCity->get('carrySlot'), $slotFile, 40); for ($i = 1; $i < sizeof($rscList->slotData); $i += 2) { $rscStores[$rscList->slotData[$i]] = $rscList->slotData[$i + 1]; } print_r($rscStores); foreach ($resources as $rscID => $rscAmt) { echo 'Need ' . $rscAmt . ' of ' . $rscID; if (array_key_exists($rscID, $rscStores)) { if ($rscStores[$rscID] < $rscAmt) { $rscPass = false; $neededRsc = $rscID; } else { echo 'Have ' . $rscStores[$rscID] . ' Need ' . $rscAmt; } } else {
$slotFile = fopen($gamePath . '/gameSlots.slt', 'rb'); $mapSlotFile = fopen($gamePath . '/mapSlotFile.slt', 'rb'); echo '<script> useDeskTop.newPane("spyMenu"); thisDiv = useDeskTop.getPane("spyMenu");'; // Look for player units around the target $trgUnit = loadUnit($postVals[1], $unitFile, 400); $mapSlot = floor($trgUnit->unitDat[2] / 120) * 120 + floor($trgUnit->unitDat[1] / 120); $mapItems = new itemSlot($mapSlot, $mapSlotFile, 404); // start, file, slot size $orderRadius = 5; $oRadiusSq = $orderRadius * $orderRadius; // out put list of units that can spy on the target echo 'textBlob("", thisDiv, "Select a unit to spy with");'; for ($i = 1; $i <= sizeof($mapItems->slotData); $i++) { $checkUnit = loadUnit($mapItems->slotData[$i], $unitFile, 400); if ($checkUnit->get('uType') == 4) { $xDiff = $checkUnit->unitDat[1] - $trgUnit->unitDat[1]; $yDiff = $checkUnit->unitDat[2] - $trgUnit->unitDat[2]; if ($xDiff * $xDiff + $yDiff * $yDiff < $oRadiusSq) { // output option box for this unit echo 'unitList.newUnit({unitID : ' . $mapItems->slotData[$i] . ', unitType : "character", rating : 50, status : 1, unitName : "char ' . $mapItems->slotData[$i] . '", cost: 90}); objBox = actionBox(thisDiv, "1120,' . $mapItems->slotData[$i] . ',' . $postVals[1] . '", ' . $checkUnit->actionPoints() . '); unitList.renderSum(' . $mapItems->slotData[$i] . ', objBox.unitSpace);'; } } } echo '</script>'; fclose($mapSlotFile); fclose($unitFile); fclose($slotFile);
<?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);
// Determine amount of resources collected -> compare the unit's gathering rate to the allowable amount for each terrain cell. $collected = 0; for ($i = 0; $i < sizeof($jobArray); $i++) { $collected += min($jobArray[$i], $magnitude); } echo 'Collected ' . $collected; // Make new data for this event and record to map events. $actionType = $rscPoint[10]; $eventData = pack('i*', $rscPoint[10], $postVals[2], $actionType, time(), $magnitude, $jobRadius); $mapEffects->addItem($meSlotFile, $eventData, 1); //($testFile, $sendData, $addTarget); // Save resources collected to unit slot $carried = 0; // Check to see if the unit is part of an army (if so, the rsc go to the army storage). if ($workingUnit->unitDat[15] > 0) { $trgArmy = loadUnit($workingUnit->unitDat[15], $unitFile, 400); //$trgArmy = new army($workingUnit->unitDat[15], $unitFile, 400); $capacity = $trgArmy->get('carryCap'); if ($trgArmy->get('carrySlot') == 0) { $newSlot = startASlot($unitSlotFile, "../users/userSlots.slt"); $trgArmy->set('carrySlot', $newSlot); $trgArmy->saveAll($unitFile); $useRscSlot = $newSlot; } else { $useRscSlot = $trgArmy->get('carrySlot'); } } else { $capacity = $workingUnit->get('carryCap'); echo 'Working unit stuff:'; print_r($workingUnit->unitDat); if ($workingUnit->get('carrySlot') == 0) {
$rscCheck = false; } } if ($rscCheck) { // Create a building object if (flock($unitFile, LOCK_EX)) { clearstatcache(); $newID = max(1, filesize($gamePath . '/unitDat.dat') / $defaultBlockSize); fseek($unitFile, $newID * $defaultBlockSize + $unitBlockSize - 4); fwrite($unitFile, pack('i', 0)); flock($unitFile, LOCK_UN); } else { echo 'Major lock error'; } // Record information for new building $newBldg = loadUnit($newID, $unitFile, 400); $newBldg->unitDat[1] = intval($postVals[1] / 2) * 2; $newBldg->unitDat[2] = intval($postVals[2] / 2) * 2; $newBldg->unitDat[4] = 2; $newBldg->unitDat[8] = 1; $newBldg->unitDat[9] = 1; $newBldg->unitDat[10] = $bldgTypeInfo[11]; $newBldg->unitDat[15] = $cityID; $newBldg->unitDat[18] = 100; $newBldg->unitDat[19] = 1; $newBldg->unitDat[20] = 100; $newBldg->unitDat[22] = 10000; $newBldg->unitDat[23] = 10000; $newBldg->unitDat[24] = 100; $newBldg->unitDat[27] = time(); $newBldg->saveAll($unitFile);
<?php include './slotFunctions.php'; include './unitClass.php'; $unitFile = fopen($gamePath . '/unitDat.dat', 'rb'); $slotFile = fopen($gamePath . '/gameSlots.slt', 'rb'); // Gathering options for a resource point // Get data about this resource point $thisPoint = loadUnit($postVals[1], $unitFile, 400); // Check for nearby units that can work at this locaiton $thisPlayer = loadPlayer($pGameID, $unitFile, 400); $unitList = new itemSlot($thisPlayer->get('unitSlot'), $slotFile, 40); echo '<script>useDeskTop.newPane("somePane"); thisDiv = useDeskTop.getPane("somePane");'; for ($i = 1; $i <= sizeof($unitList->slotData); $i++) { $checkUnit = loadUnit($unitList->slotData[$i], $unitFile, 400); if ($checkUnit->get('uType') == 8) { $xDist = $checkUnit->get('xLoc') - $thisPoint->get('xLoc'); $yDist = $checkUnit->get('yLoc') - $thisPoint->get('yLoc'); if ($xDist * $xDist + $yDist * $yDist <= 400) { $actionPoints = $checkUnit->actionPoints(); // unit is close enough to gather -> show the unit as an option echo 'unitList.newUnit({unitType:"warband", unitID:' . $unitList->slotData[$i] . ', unitName:"unit name", actionPoints:' . $actionPoints . ', strength:75, tNum:' . $checkUnit->get('uType') . '}); var orderBox = actionBox(thisDiv, "1122,' . $postVals[1] . ',' . $unitList->slotData[$i] . '", ' . $actionPoints . '); unitList.renderSum(' . $unitList->slotData[$i] . ', orderBox.unitSpace);'; } } } echo '</script>'; fclose($unitFile); fclose($slotFile);
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); }
<?php /* This script gives a menu for transfering control of a unit to another player */ include './unitClass.php'; include './slotFunctions.php'; $unitFile = fopen($gamePath . '/unitDat.dat', 'rb'); $slotFile = fopen($gamePath . '/gameSlots.slt', 'rb'); // Confirm that you are the owner of the unit $thisUnit = loadUnit($postVals[1], $unitFile, 400); if ($thisUnit->get('owner') != $gGameID) { exit('error 1-5111'); } // Get a list of players to transfer the unit to (run the chain of player's lords) $thisPlayer = loadPlayer($pGameID, $unitFile, 400); $lordID = $thisPlayer->get('lordID'); while ($lordID > 0) { echo 'Assign to player #' . $lordID; $nextLord = loadPlayer($lordID, $unitFile, 400); $lordID = $nextLord('lordID'); } fclose($unitFile); fclose($slotFile);
function newUnit($type, $file) { global $defaultBlockSize; if (flock($file, LOCK_EX)) { fseek($file, 0, SEEK_END); $endPos = ftell($file); $newID = ceil($endPos / $defaultBlockSize); fseek($file, $newID * $defaultBlockSize + 396); fwrite($file, pack('i', 0)); $tmpDat = array_fill(1, 100, 0); $tmpDat[4] = $type; flock($file, LOCK_UN); return loadUnit($newID, $file, 400); } }