function TB_run_animalmanager_farmGold($getFarm = null) { global $TB_settings; global $AM_settings; echo "FarmGold\r\n"; //######################################################################## // animalmanager_farmGold functions //######################################################################## $farm = $getFarm; $tmp_skip_fg = false; if (AM_farmGold_getIDs() != 0 && $TB_settings['AM_farmGoldRestore']) { if (!isset($farm)) { AddLog2('ToolBox: Reloading Farm'); DoInit(); $farm = TB_buildFarmArray(); } $info = AM_farmGold_getIDs(); $re = AM_farmGold_restore($info, $farm); if (is_array($re)) { $farm = $re; } AM_farmGold_deletIDs(); //reloding farm AddLog2('ToolBox: Animals Restored'); AddLog2('ToolBox: Reloding Farm'); DoInit(); $farm = TB_buildFarmArray(); $TB_settings['TB_needReload'] = false; } foreach ($AM_settings as $className => $animals) { if ($TB_settings['AM_farmGold_' . $className] > 0 && !$tmp_skip_fg) { //================================================================= // n0m mod: to skip stables harvesting (if 1 cycle set in FarmGold) $harvestBuilding = $TB_settings['AM_farmGold_' . $className] > 1 ? true : false; //================================================================= $buildings = AM_loadBuildingObject($className, false); $tmp = 0; while ($tmp < $TB_settings['AM_farmGold_' . $className] && !$tmp_skip_fg) { if (!isset($farm)) { AddLog2('ToolBox: Reloading Farm'); DoInit(); $farm = TB_buildFarmArray(); } foreach ($buildings as $building) { // n0m: $harvestBuilding param added $re = AM_farmGold($className, $building, $farm, $harvestBuilding); if (is_array($re)) { $farm = $re; } elseif ($re == false) { Addlog2('ToolBox: ERROR'); AddLog2('ToolBox: Reloading Farm'); DoInit(); $farm = TB_buildFarmArray(); $info = AM_farmGold_getIDs(); $re = AM_farmGold_restore($info, $farm); if (is_array($re)) { AM_farmGold_deletIDs(); $farm = $re; AddLog2('ToolBox: Animals Restored'); } elseif ($re == false) { DoInit(); AddLog2('error while restoring!'); AddLog2('skipping other buildings'); AddLog2('set cycle to 0 for ' . $className); AddLog2('you may check you farm'); $tmp_skip_fg = true; $TB_settings['AM_farmGold_' . $className] = 0; } } } $tmp++; //================================================================= // n0m mod: output cycle # in FarmGold AddLog2("~~~~~ [ {$tmp} / " . $TB_settings['AM_farmGold_' . $className] . " ] done ~~~~~"); //================================================================= } $TB_settings['TB_needReload'] = true; } } return $farm; }
function AM_farmGold_restore($getInfo, $getFarm) { $IDs = $getInfo['IDs']; $building = $getInfo['building']; $farm = $getFarm; $objects = array(); $objects = TB_loadObjects(); $itemName = array(); $newIDs = array(); $positions = array(); Addlog2('ToolBox: Restoring Farm'); foreach ($objects as $object) { if (in_array($object['id'], $IDs)) { $itemName[] = $object['itemName']; $newIDs[] = $object['id']; $positions[] = $object['position']; } } $re = AM_farmGold_moveAnimalsToBuilding($building, count($IDs), $farm, $newIDs, $itemName, $positions); if (is_array($re)) { $farm = $re; } else { return false; } AM_farmGold_deletIDs(); //Addlog2('-> OK'); return $farm; }