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_addIDs($getIDs, $getBuilding) { $info = array(); $info = AM_farmGold_getIDs(); if ($info == 0) { save_array(array('building' => $getBuilding, 'IDs' => (array) $getIDs), AnimalMover_farmGold_IDs); } else { $IDs = $info['IDs']; $building = $info['building']; if ($building['id'] == $getBuilding['id']) { $IDs = array_merge($IDs, (array) $getIDs); } save_array(array('building' => $building, 'IDs' => $IDs), AnimalMover_farmGold_IDs); } }