Esempio n. 1
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];
//NEED TO VERIFY THAT THE CORRECT PRODUCTION ID IS USED - POSTVALS 1 IS THE ID OF THE FARM OBJECT.  NEED TO LOAD RESORUCE TYPE AND USE THAT.
if ($carried < $capacity) {
    $space = $capacity - $carried;
    $location = sizeof($unitRSC->slotData);
    if ($rscStart[0] > 0) {
        $location = $rscStart[0];
    } else {
        if ($rscStart[2] > 0) {
            $location = $rscStart[2];
        }
    }
    echo 'Add new resoruces to locatoinb ' . $location;
    $unitRSC->addItem($unitSlotFile, pack('i*', $rscPoint[10], $rscStart[1] + min($space, $collected)), $location);
} else {
    echo 'Can not carry any more (Max: ' . $carried . '/' . $capacity . ')<br>';
}
fclose($unitSlotFile);
fclose($meSlotFile);
fclose($unitFile);
Esempio n. 2
0
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);
}
Esempio n. 3
0
File: 3001.php Progetto: rwruss/ib3
        }
        $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]);
            $blockLength = strlen($msg[1]) + strlen($msg[2]) + 5 + 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
            echo 'Message length is ' . $blockLength . ' (' . strlen($msg[1]) . ') + (' . strlen($msg[2]) . ') + 9 written at spot ' . $msgSpot . '<br>
      Subject: ' . $msg[1] . '<br>
      Content: ' . $msg[2] . '<br>';
            fwrite($messageContentFile, pack('i*', $blockLength, time(), $pGameID, $postVals[2]) . $msg[1] . '<-!->' . $msg[2]);
            $msgSlot->addItem($slotFile, pack('i*', $msgSpot, 1, 1), $msgSlot->findLoc(0, 3));
            // message start loc, message file num, read/unread
        }
    }
}
fclose($unitSlotFile);
fclose($unitFile);
fclose($slotFile);
Esempio n. 4
0
File: 1039.php Progetto: rwruss/ib3
        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>';
        }
    }
} else {
    $credLevel = 0;
    echo 'You do not have the authority required to issue this order. (' . $pGameID . ')';
}
Esempio n. 5
0
<?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);
Esempio n. 6
0
File: 1132.php Progetto: rwruss/ib3
// 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);
Esempio n. 7
0
File: 1082.php Progetto: rwruss/ib3
    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));
echo 'Record plot in slot ' . $unitDat[35] . ' for the unit';
if ($controllerDat[20] == 0) {
    $controllerDat[20] = startASlot($slotFile, $gamePath . '/gameSlots.slt');
    fseek($unitFile, $_SESSION['selectedItem'] * $defaultBlockSize + 136);
    fwrite($unitFile, pack('i', $controllerDat[20]));
}
$charPlots = new itemSlot($controllerDat[20], $slotFile, 40);
$charPlots->addItem($postVals[1], $slotFile);
// Send a message to the player that he has a char invited to a new plot
$trgList[] = $unitDat[6];
sendMessage([$pGameId, $unitDat[6], time(), 1, 0, $postVals[1], $_SESSION['selectedItem']], "", $trgList);
fclose($slotFile);
Esempio n. 8
0
File: 1004.php Progetto: rwruss/ib3
 $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
     $townSlot = startASlot($gameSlot, $gamePath . "/gameSlots.slt");
     $mLoc = sizeof($mapSlot->slotData);
     for ($i = 1; $i <= sizeof($mapSlot->slotData); $i += 2) {
         if ($mapSlot->slotData[$i] == 0) {
             $mLoc = $i;
             break;
         }
     }
     $mapSlot->addItem($mapSlotFile, pack('i*', $townID, 1), $mLoc);
     // file, bin value, loc
 } else {
     // Create a new army unit for the items to be grouped into
     $armyID = $unitIndex;
     $unitIndex += 4;
     $armySlot = startASlot($gameSlot, $gamePath . "/gameSlots.slt");
     fseek($unitFile, $armyID * $defaultBlockSize);
     fwrite($unitFile, pack('i*', $startLocation[0], $startLocation[1], 1, 3, $pGameID, $pGameID, 1, $postVals[1], 0));
     fseek($unitFile, $armyID * $defaultBlockSize + 52);
     fwrite($unitFile, pack('i', $armySlot));
     $mLoc = sizeof($mapSlot->slotData);
     for ($i = 1; $i <= sizeof($mapSlot->slotData); $i += 2) {
         if ($mapSlot->slotData[$i] == 0) {
             $mLoc = $i;
             break;
Esempio n. 9
0
File: 1092.php Progetto: rwruss/ib3
     // 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);
 } else {
     //echo 'Unit is not complete '.$trgUnit->unitDat[18].' + '.$usedPoints.' < '.$trgUnit->unitDat[19];
     // Update stats for unit in production
     $trgUnit->unitDat[18] += $usedPoints;
 }
 $useBldg->unitDat[27] = time();
 $useBldg->saveAll($unitFile);
 $trgUnit->saveAll($unitFile);
 echo '<script>unitList.newUnit({unitType:"trainingUnit", unitID:' . $useBldg->unitDat[$postVals[2] + 18] . ', unitName:"Training", trainPts:' . $trgUnit->unitDat[18] . ', trainReq:' . $trgUnit->unitDat[19] . '});</script>';
Esempio n. 10
0
File: 1045.php Progetto: rwruss/ib3
        $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 . ');
	updateUnitPosition(' . $postVals[1] . ', ' . $newLoc[1] . ', ' . $newLoc[2] . ');
	resetMove(' . $newLoc[1] . ', ' . $newLoc[2] . ');
Esempio n. 11
0
File: 1067.php Progetto: rwruss/ib3
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);
Esempio n. 12
0
 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);
     }
 }