0) { do { if ($value == 1) { $throw = 1; } else { $throw = rand(1, $value); } $res = $res + $throw; } while ($throw == $value); } return $res; } # opens the character's story and update it function AddToStory($id, $report) { $fn = "story".$id.".txt"; $fn = Incref($fn, "zzzdirstories.txt"); # this section purposely put in comment but NOT deleted # section's objective = open the story and place the new report BEFORE the existing text # bug : although this code works 95% of the time, it sometimes delete a few characters at the end of the file !? ... # no reasonable explanation could be found # if (file_exists ($fn)) { # $fp = fopen ($fn, "r"); # "r" is used to open a file in read mode # $oldreport = fread($fp, filesize($fn)); # fclose($fp); # $report = $report.$oldreport; # } # echo "report=".$report."
"; $report = "
".$report; $fp = fopen ($fn, "a"); # "a" is used to open a file in write mode and place the pointer at the end fwrite($fp, $report); fclose($fp); $perm = 33279; # change file access so that anyone can read and write it chmod($fn, $perm); $result = mysql_query("UPDATE Characters SET Report='News' WHERE Id=$id"); } # add activity to the server log function AddToServerLog($report) { $fn = "serverlog.txt"; $fn = Incref($fn, "zzzdirlogs.txt"); $fp = fopen ($fn, "a"); fwrite($fp, $report); fclose($fp); $perm = 33279; chmod($fn, $perm); } # recrunch the equipment function RecrunchEquipment() { global $equipment, $charitemsW, $charitemsA, $charitemsF, $charitemsO; global $Twnb, $Tanb, $Tfnb, $Tonb; $equipment = ""; for ($ti=1; $ti <= $Twnb; $ti++) { if ($charitemsW[$ti] > 0) { $equipment = $equipment."W".$ti.".".$charitemsW[$ti].".0,"; } } for ($ti=1; $ti <= $Tanb; $ti++) { if ($charitemsA[$ti] > 0) { $equipment = $equipment."A".$ti.".".$charitemsA[$ti].".0,"; } } for ($ti=1; $ti <= $Tfnb; $ti++) { if ($charitemsF[$ti] > 0) { $equipment = $equipment."F".$ti.".".$charitemsF[$ti].".0,"; } } for ($ti=1; $ti <= $Tonb; $ti++) { if ($charitemsO[$ti] > 0) { $equipment = $equipment."O".$ti.".".$charitemsO[$ti].".0,"; } } } # decrunch the equipment function DecrunchEquipment($equipment) { # total number of item types, and number of items for each category and type global $charitemsnb, $charitemsW, $charitemsA, $charitemsF, $charitemsO; $i = -1; $charitemsnb = 0; if (strlen($equipment) > 0) { do { $charitemsnb++; # item category, UCK style = WAFETOM, Weapon Armor Food Enlight Treasure Object Magic $quote = ""; $i++; $c = substr($equipment, $i, 1); $itemstype = $c; # type of item for this category $quote = ""; do { $i++; $c = substr($equipment, $i, 1); if (($c <> ",") and ($c <> ";") and ($c <> ".") and ($c <> "/")) { $quote = $quote.$c;} } while ($c <> "."); $val = $quote*1; # nb of items for this category $quote = ""; do { $i++; $c = substr($equipment, $i, 1); if (($c <> ",") and ($c <> ";") and ($c <> ".") and ($c <> "/")) { $quote = $quote.$c;} } while ($c <> "."); $nb = $quote*1; # parameters for these items $quote = ""; do { $i++; $c = substr($equipment, $i, 1); if (($c <> ",") and ($c <> ";") and ($c <> ".") and ($c <> "/")) { $quote = $quote.$c;} } while ($c <> ","); $paramtxt = $quote; # given the type currently stores one available item switch ($itemstype) { case "W" : $charitemsW[$val] = $nb; break; case "A" : $charitemsA[$val] = $nb; break; case "F" : $charitemsF[$val] = $nb; break; case "O" : $charitemsO[$val] = $nb; break; } } while ($i < strlen($equipment)-2); } } # recrunch the storage function RecrunchStorage() { global $storage, $itemsW, $itemsA, $itemsF, $itemsO; global $itemsWprice, $itemsAprice, $itemsFprice, $itemsOprice; global $Twnb, $Tanb, $Tfnb, $Tonb; $storage = ""; for ($ti=1; $ti <= $Twnb; $ti++) { if (($itemsW[$ti] > 0) or ($itemsWprice[$ti] <> 0)) { $storage .= "W".$ti.".".(int)($itemsW[$ti])."."; if ($itemsWprice[$ti] <> 0) { $storage .= $itemsWprice[$ti]."."; } else { $storage .= "0."; } $storage .= ( ($itemsW[$ti] - (int)($itemsW[$ti])) * 100 ).","; } } for ($ti=1; $ti <= $Tanb; $ti++) { if (($itemsA[$ti] > 0) or ($itemsAprice[$ti] <> 0)) { $storage .= "A".$ti.".".$itemsA[$ti]."."; if ($itemsAprice[$ti] <> 0) { $storage .= $itemsAprice[$ti]."."; } else { $storage .= "0."; } $storage .= ( ($itemsA[$ti] - (int)($itemsA[$ti])) * 100 ).","; } } for ($ti=1; $ti <= $Tfnb; $ti++) { if (($itemsF[$ti] > 0) or ($itemsFprice[$ti] <> 0)) { $storage .= "F".$ti.".".$itemsF[$ti]."."; if ($itemsFprice[$ti] <> 0) { $storage .= $itemsFprice[$ti]."."; } else { $storage .= "0."; } $storage .= ( ($itemsF[$ti] - (int)($itemsF[$ti])) * 100 ).","; } } for ($ti=1; $ti <= $Tonb; $ti++) { if (($itemsO[$ti] > 0) or ($itemsOprice[$ti] <> 0)) { $storage .= "O".$ti.".".$itemsO[$ti]."."; if ($itemsOprice[$ti] <> 0) { $storage .= $itemsOprice[$ti]."."; } else { $storage .= "0."; } $storage .= ( ($itemsO[$ti] - (int)($itemsO[$ti])) * 100 ).","; } } } # decrunch the string storing the available items in a store, TO BE MODIFIED, add number of items in a precise type function DecrunchStorage($storage) { # total number of item types, and number of items for each category and type global $itemsnb, $itemsW, $itemsA, $itemsF, $itemsO; global $itemsWprice, $itemsAprice, $itemsFprice, $itemsOprice; global $Twcost, $Tacost, $Tfcost, $Tocost; $i = -1; $itemsnb = 0; if (strlen($storage) > 0) { do { $itemsnb++; # item category, UCK style = WAFETOM, Weapon Armor Food Enlight Treasure Object Magic $quote = ""; $i++; $c = substr($storage, $i, 1); $itemstype = $c; # type of item for this category $quote = ""; do { $i++; $c = substr($storage, $i, 1); if (($c <> ",") and ($c <> ";") and ($c <> ".") and ($c <> "/")) { $quote = $quote.$c;} } while ($c <> "."); $val = $quote*1; # nb of items for this category $quote = ""; do { $i++; $c = substr($storage, $i, 1); if (($c <> ",") and ($c <> ";") and ($c <> ".") and ($c <> "/")) { $quote = $quote.$c;} } while ($c <> "."); $nb = $quote*1; # parameters for these items $quote = ""; do { $i++; $c = substr($storage, $i, 1); if (($c <> ",") and ($c <> ";") and ($c <> ".") and ($c <> "/")) { $quote = $quote.$c;} } while (($c <> ",") and ($c <> ".")); $paramtxt = $quote; # parts for these items $part = 0; if ($c == ".") { $quote = ""; do { $i++; $c = substr($storage, $i, 1); if (($c <> ",") and ($c <> ";") and ($c <> ".") and ($c <> "/")) { $quote = $quote.$c;} } while ($c <> ","); $part = $quote*1; } # given the type currently stores one available item switch ($itemstype) { case "W" : $itemsW[$val] = $nb + $part/100; $itemsWprice[$val] = $paramtxt*1; if ($itemsWprice[$val] == 0) { $itemsWprice[$val] = $Twcost[$val]; } break; case "A" : $itemsA[$val] = $nb + $part/100; $itemsAprice[$val] = $paramtxt*1; if ($itemsAprice[$val] == 0) { $itemsAprice[$val] = $Tacost[$val]; } break; case "F" : $itemsF[$val] = $nb + $part/100; $itemsFprice[$val] = $paramtxt*1; if ($itemsFprice[$val] == 0) { $itemsFprice[$val] = $Tfcost[$val]; } break; case "O" : $itemsO[$val] = $nb + $part/100; $itemsOprice[$val] = $paramtxt*1; if ($itemsOprice[$val] == 0) { $itemsOprice[$val] = $Tocost[$val]; } break; } } while ($i < strlen($storage)-2); } } # function DecrunchBuildingActions($buildaction) { # global $buildactionnb, $buildactionlist, $buildactiontype; $i = -1; $buildactionnb = 0; if (strlen($buildaction) > 0) { do { $buildactionnb++; # $quote = ""; do { $i++; $c = substr($buildaction, $i, 1); if (($c <> ",") and ($c <> ";") and ($c <> ".") and ($c <> "/")) { $quote = $quote.$c;} } while ($c <> ","); $buildactionlist[$buildactionnb] = $quote*1; $buildactiontype[$quote*1] = 1; } while ($i < strlen($buildaction)-2); } } # decrunch the string for text parsing function DecrunchParseText($parsetext) { # number of reactions, keywords and linked answer for each set global $parsenb, $parsethis, $parseanswer; $i = -1; $parsenb = 0; if (strlen($parsetext) > 0) { do { $parsenb++; # decrunch the keyword list $quote = ""; do { $i++; $c = substr($parsetext, $i, 1); if ($c <> "|") { $quote = $quote.$c; } } while ($c <> "|"); $parsethis[$parsenb] = $quote; # decrunch the answer $quote = ""; do { $i++; $c = substr($parsetext, $i, 1); if ($c <> "|") { $quote = $quote.$c; } } while ($c <> "|"); $parseanswer[$parsenb] = $quote; } while ($i < strlen($parsetext)-2); } } # decrunch coordinates function DecrunchCoordinates($cood) { global $xgoing, $ygoing; $i = 0; if (strlen($cood) > 0) { do { # decrunch x $quote = ""; do { $i++; $c = substr($cood, $i, 1); if ($c <> "y") { $quote = $quote.$c; } } while ($c <> "y"); $xgoing = $quote*1; # decrunch the answer $quote = ""; do { $i++; $c = substr($cood, $i, 1); if ($c <> "z") { $quote = $quote.$c; } } while ($c <> "z"); $ygoing = $quote*1; } while ($i < strlen($cood)-2); } } # receives a planning LCP text, and decrunch it in the appropriate arrays function DecrunchPlanning($planning) { # actions are stored in a planning kind of array : each cell is one turn global $actionsnb, $actiondelay, $actiontype, $actionparam, $actionparamtxt, $actiontable, $actioncoord, $actionparam2; $i = -1; $actionsnb = 0; DestroyPlanning(); # erases any previous values in the global arrays if (strlen($planning) > 0) { do { # extracts the turn of the action $quote = ""; do { $i++; $c = substr($planning, $i, 1); if (($c <> ",") and ($c <> ";") and ($c <> ".") and ($c <> "/")) { $quote = $quote.$c;} } while ($c <> "/"); $actionturnfound = $quote*1; $actionsnb++; # extracts the delay of the action $quote = ""; do { $i++; $c = substr($planning, $i, 1); if (($c <> ",") and ($c <> ";") and ($c <> ".") and ($c <> "/")) { $quote = $quote.$c;} } while ($c <> ","); $actiondelay[$actionturnfound] = $quote*1; # extracts the type of the action $quote = ""; do { $i++; $c = substr($planning, $i, 1); if (($c <> ",") and ($c <> ";") and ($c <> ".") and ($c <> "/")) { $quote = $quote.$c;} } while ($c <> "/"); $actiontype[$actionturnfound] = $quote*1; # extracts the parameter of the action $quote = ""; do { $i++; $c = substr($planning, $i, 1); if (($c <> ",") and ($c <> ";") and ($c <> ".") and ($c <> "/")) { $quote = $quote.$c;} } while ($c <> ","); $actionparam[$actionturnfound] = $quote*1; $actionparamtxt[$actionturnfound] = $quote; # extracts the coordinates of the action $quote = ""; do { $i++; $c = substr($planning, $i, 1); if (($c <> ",") and ($c <> ";") and ($c <> ".") and ($c <> "/")) { $quote = $quote.$c;} } while ($c <> ","); $actioncoord[$actionturnfound] = $quote; # extracts the second parameter of the action $quote = ""; do { $i++; $c = substr($planning, $i, 1); if (($c <> ",") and ($c <> ";") and ($c <> ".") and ($c <> "/")) { $quote = $quote.$c;} } while (($c <> ";") and ($c <> ".")); $actionparam2[$actionturnfound] = $quote; } while ($i < strlen($planning)-2); # inverts the actions storage in another array : list them one by one $i = 0; $t = 0; do { $t++; if ($actiontype[$t] <> 0) { $i++; $actiontable[$i] = $t; } } while ($i < $actionsnb); } } # erases the global planning arrays # there should be a global PHP command to destroy an array ?! didnt find it function DestroyPlanning() { global $actionsnb, $actiondelay, $actiontype, $actionparam, $actionparamtxt; global $turn, $maxturns; $actionsnb = 0; for ($i=0; $i <= $maxturns; $i++) { $actiontype[$turn + $i] = 0; $actiondelay[$turn + $i] = 0; $actionparam[$turn + $i] = 0; $actionparamtxt[$turn + $i] = 0; $actioncoord[$turn + $i] = 0; $actionparam2[$turn + $i] = 0; } } # specifically erase *one* action from a LCP planning text and stores it function EraseFromPlanning($searchedturn, $id) { global $planning; $i = -1; $newplanning = ""; if (strlen($planning) > 0) { do { $quote = ""; $quote2 = ""; # decrunch the action turn do { $i++; $c = substr($planning, $i, 1); if (($c <> ",") and ($c <> ";") and ($c <> ".") and ($c <> "/")) { $quote = $quote.$c; } $quote2 = $quote2.$c; } while ($c <> "/"); $actionturndec = $quote*1; # if this is not the action to suppress, then stores again if ($actionturndec <> $searchedturn) { $newplanning = $newplanning.$quote2; } # decrunch the action details $quote2 = ""; do { $i++; $c = substr($planning, $i, 1); $quote2 = $quote2.$c; } while (($c <> ";") and ($c <> ".")); # if this is not the action to suppress, then stores again if ($actionturndec <> $searchedturn) { $newplanning = $newplanning.$quote2; } } while ($i < strlen($planning)-2); # replaces the current planning and stores it $planning = $newplanning; # replace the last char by a point (handles special case of erasing the last action of the planning if (strlen($planning) > 0) { $planning = substr($planning, 0, strlen($planning)-1)."."; } $result = mysql_query("UPDATE Characters SET Planning='$planning' WHERE Id=$id"); } } # receives the talent LCP text, and decrunch it function DecrunchSkills($skilllist) { # total number of talents, which talent, talent rank global $skillsnb, $skillsid, $skillsrank; for ($i = 1; $i <= $Tskillnb; $i++) { $skillsrank[$i] = 0; } $i = -1; $skillsnb = 0; if (strlen($skilllist) > 0) { do { $skillsnb++; # extracts the skill number $quote = ""; do { $i++; $c = substr($skilllist, $i, 1); if (($c <> ",") and ($c <> ";") and ($c <> ".") and ($c <> "/")) { $quote = $quote.$c; } } while ($c <> ","); $skillsid = $quote*1; # extracts the skill rank $quote = ""; do { $i++; $c = substr($skilllist, $i, 1); if (($c <> ",") and ($c <> ";") and ($c <> ".") and ($c <> "/")) { $quote = $quote.$c; } } while ($c <> ";"); $skillsrank[$skillsid] = $quote*1; } while ($i < strlen($skilllist)-2); } } # decrunch the string containing building animation files and parameters function DecrunchBuildingAnims($animlist, $b) { # number of anims, gif file, offset X, offset Y, size X, size Y, for a given building, in a given situation global $animidnb, $animfile, $animoffsetX, $animoffsetY, $animsizeX, $animsizeY; $i = -1; if (strlen($animlist) > 0) { do { # decrunch in which situation the following values are to be used $quote = ""; do { $i++; $c = substr($animlist, $i, 1); if (($c <> ",") and ($c <> ";") and ($c <> "/")) { $quote = $quote.$c; } } while ($c <> ","); $animid = $quote*1; $animidnb[$b][$animid] = 0; do { $animidnb[$b][$animid]++; # decrunch the file name and the image size $quote = ""; do { $i++; $c = substr($animlist, $i, 1); if (($c <> ",") and ($c <> ";") and ($c <> "/")) { $quote = $quote.$c; } } while ($c <> ","); $animfile[$b][$animid][$animidnb[$b][$animid]] = $quote; $size = GetImageSize (Inc($animfile[$b][$animid][$animidnb[$b][$animid]])); $animsizeX[$b][$animid][$animidnb[$b][$animid]] = $size[0]; $animsizeY[$b][$animid][$animidnb[$b][$animid]] = $size[1]; # decrunch the animation offset by X $quote = ""; do { $i++; $c = substr($animlist, $i, 1); if (($c <> ",") and ($c <> ";") and ($c <> "/")) { $quote = $quote.$c; } } while ($c <> ","); $animoffsetX[$b][$animid][$animidnb[$b][$animid]] = $quote*1; # decrunch the animation offset by Y $quote = ""; do { $i++; $c = substr($animlist, $i, 1); if (($c <> ",") and ($c <> ";") and ($c <> "/")) { $quote = $quote.$c; } } while (($c <>",") and ($c <> ";")); $animoffsetY[$b][$animid][$animidnb[$b][$animid]] = $quote*1; } while ($c <> ";"); } while ($i < strlen($animlist)-2); } } # receives the talentsseen LCP text, and decrunch it function DecrunchTalentsSeen($talentsseen) { # number of talents seen, which talents global $talentsseennb, $talentsseenid; $i = -1; $talentsseennb = 0; if (strlen($talentsseen) > 0) { do { $talentsseennb++; $quote = ""; do { $i++; $c = substr($talentsseen, $i, 1); if (($c <> ",") and ($c <> ";") and ($c <> ".") and ($c <> "/")) { $quote = $quote.$c; } } while (($c <> ",") or ($c <> ".")); $talentsseenrank[$quote*1] = 1; } while ($c <> "."); } } # function DecrunchAgenda($agenda) { # global $bethere, $todo; for ($i=1; $i<=24; $i++) { $bethere[$i] = 0; $todo[$i] = 0; } $i = -1; $attime = 0; if (strlen($agenda) > 0) { do { $attime++; $quote = ""; do { $i++; $c = substr($agenda, $i, 1); if (($c <> ",") and ($c <> ";") and ($c <> ".") and ($c <> "/")) { $quote = $quote.$c; } } while ($c <> "."); $bethere[$attime] = $quote*1; $quote = ""; do { $i++; $c = substr($agenda, $i, 1); if (($c <> ",") and ($c <> ";") and ($c <> ".") and ($c <> "/")) { $quote = $quote.$c; } } while ($c <> ","); $todo[$attime] = $quote*1; } while ($i < strlen($agenda)-2); } } # receives the death penalty LCP text, and decrunch it function DecrunchDeathPenalty($death) { # number of penalties, xp to recover for each penalty global $deathpenalty, $deathrecover; $i = -1; $deathpenalty = 0; if (strlen($death) > 0) { do { $deathpenalty++; $quote = ""; do { $i++; $c = substr($death, $i, 1); if (($c <> ",") and ($c <> ";") and ($c <> ".") and ($c <> "/")) { $quote = $quote.$c; } } while ($c <> "."); $deathrecover[$deathpenalty] = $quote*1; } while ($i < strlen($death)-2); } } # function DecrunchSpells($spells) { # global $spell, $nbspell, $spellthread, $spellnb; global $Tspnb; for ($i=1; $i<=$Tspnb; $i++) { $spell[$i] = false; $spellthread[$i] = false; } $i = -1; $nbspell = 0; if (strlen($spells) > 0) { do { $nbspell++; $quote = ""; do { $i++; $c = substr($spells, $i, 1); if (($c <> ",") and ($c <> ";") and ($c <> ".") and ($c <> "/")) { $quote = $quote.$c; } } while ($c <> ","); $spell[$quote*1] = true; $quote = ""; do { $i++; $c = substr($spells, $i, 1); if (($c <> ",") and ($c <> ";") and ($c <> ".") and ($c <> "/")) { $quote = $quote.$c; } } while ($c <> ";"); $spellthread[$quote*1] = true; } while ($i < strlen($spells)-2); } } # receives a turn number and return the text value according to the kind of display needed function GiveDate($theturn, $kind) { global $turn; # the hour, day and month names are taken from Asheron's Call $Thour = array( "", "Darktide", "Darktide-and-One", "Chilling", "Chilling-and-One", "Foredawn", "Foredawn-and-One", "Dawnsong", "Dawnsong-and-One", "Dawnend", "Dawnend-and-One", "Morntide", "Morntide-and-One", "Midsong", "Midsong-and-One", "Resttide", "Resttide-and-One", "Warmtide", "Warmtide-and-One", "Evensong", "Evensong-and-One", "Gathering", "Gathering-and-One", "Gloaming", "Gloaming-and-One"); $Tday = array( "", "Firstday", "Starday", "Earthday", "Moonsday", "Elderday", "Freeday"); $Tmonth = array( "", "Morningthaw", "Solclaim", "Seedsow", "Leafdawning", "Verdantine", "Thistledown", "Harvestgain", "Leafcull", "Frostfell", "Snowreap", "Coldeve", "Wintersebb"); # calculate all values from the turn $daynb = (int)(($theturn-1) / 24) + 1; # number of days since start $day = $daynb - (int)(($daynb-1) / 6)*6; # number of the day in the week $monthnb = (int)(($daynb-1) / 30) + 1; # number of months since start $monthfirst = $daynb - (int)($daynb / 30)*30; # number of days in the month $hour = $theturn - (($daynb-1) * 24); # hour since start $week = (int)(($daynb-1) / 6) + 1 - ($monthnb-1)*5; # current week in the month # calculate current values $currentdaynb = (int)(($turn-1) / 24) + 1; # number of days since start $currentday = $currentdaynb - (int)(($currentdaynb-1) / 6)*6; # number of the day in the week $currentmonthnb = (int)(($currentdaynb-1) / 30) + 1; # number of months since start $currentmonthfirst = $currentdaynb - (int)($currentdaynb / 30)*30; # number of days in the month $currenthour = $turn - (($currentdaynb-1) * 24); # hour since start $currentweek = (int)(($currentdaynb-1) / 6) + 1 - ($currentmonthnb-1)*5; # current week in the month $string = ""; switch ($kind) { case "list" : switch ($hour) { case "1" : $string = $Tday[$day].", at "; break; case "7" : $string = "(6 a.m.) "; break; case "13" : $string = "(noon)  "; break; case "19" : $string = "(6 p.m.) "; break; default : $string = "   "; break; } $string = $string.$Thour[$hour]; if (($day == 1) and ($hour == 1)) { $string = $Tmonth[$monthnb]." week ".$week; } break; case "complete" : $string = $Thour[$hour].", ".$Tday[$day].", ".$Tmonth[$monthnb]." week ".$week; break; case "precise" : if ($currentmonthnb <> $monthnb) { $string = $Thour[$hour].", ".$Tday[$day].", ".$Tmonth[$monthnb]." week ".$week; } else { if ($currentweek <> $week) { $string = $Thour[$hour].", ".$Tday[$day].", ".$Tmonth[$monthnb]." week ".$week; } else { if ($currentday <> $day) { $string = $Thour[$hour].", ".$Tday[$day]; } else { $string = $Thour[$hour]; } } } break; case "hourandday" : $string = $Thour[$hour].", ".$Tday[$day]; break; case "dayandmonth" : $string = $Tday[$day].", ".$Tmonth[$monthnb]." week ".$week; break; case "month" : $string = $Tmonth[$monthnb]; break; case "week" : $string = $week; break; case "day" : $string = $Tday[$day]; break; case "hour" : $string = $Thour[$hour]; break; case "monthnb" : $string = $monthnb; break; case "weeknb" : $string = $week; break; case "daynb" : $string = $day; break; case "hournb" : $string = $hour; break; } return $string; } ?>