function AM_farmGold_moveAnimalsToFarm($building, $left, $getFarm) { global $TB_settings; global $AM_settings; $tmpNames = array(); $tmpPositions = array(); $return = array(); $farm = array(); $farm = $getFarm; $position = array(); $i = 0; $u = 0; foreach (AM_animalInBuilding($building) as $animal => $num) { while ($left > 0 && $num > 0) { $position = TB_findEmptySpotSection($animal, $farm, 2, 2); if ($position == false) { //AddLog2('can\'t find position in section -> will use whole farm'); $position = TB_findEmptySpot($TB_settings['TB_getEmptyPositionUseRandom'], $farm, 2, 2); } if (empty($animal)) { continue; } $amf = CreateMultAMFRequest($amf, $i, 'place', 'WorldService.performAction'); $amf->_bodys[0]->_value[1][$i]['params'][1]['className'] = 'Animal'; $amf->_bodys[0]->_value[1][$i]['params'][1]['itemName'] = $animal; $tmpNames[$i] = $animal; $amf->_bodys[0]->_value[1][$i]['params'][1]['direction'] = 1; $amf->_bodys[0]->_value[1][$i]['params'][1]['position']['x'] = $position['x']; $amf->_bodys[0]->_value[1][$i]['params'][1]['position']['y'] = $position['y']; $tmpPositions[$i]['x'] = $position['x']; $tmpPositions[$i]['y'] = $position['y']; $amf->_bodys[0]->_value[1][$i]['params'][1]['position']['z'] = 0; $amf->_bodys[0]->_value[1][$i]['params'][1]['deleted'] = false; $amf->_bodys[0]->_value[1][$i]['params'][1]['state'] = $building['state']; $amf->_bodys[0]->_value[1][$i]['params'][1]['tempId'] = -1; $amf->_bodys[0]->_value[1][$i]['params'][1]['plantTime'] = time() - 82800 - 1; $amf->_bodys[0]->_value[1][$i]['params'][2][0]['isStorageWithdrawal'] = $building['id']; $amf->_bodys[0]->_value[1][$i]['params'][2][0]['isGift'] = false; $farm[$position['x']][$position['y']] = false; if ($building['className'] != 'ChickenCoopBuilding') { $farm[$position['x'] + 1][$position['y']] = false; $farm[$position['x']][$position['y'] + 1] = false; $farm[$position['x'] + 1][$position['y'] + 1] = false; } $num--; $left--; $i++; if ($i >= $TB_settings['TB_speedAction']) { $tmp = TB_sendRequest($amf); $amf2 = $tmp['amf2']; $res = $tmp['res']; $i2 = 0; while ($i2 < $i) { $return['IDs'][$u] = $amf2->_bodys[0]->_value['data'][$i2]['data']['id']; $return['itemName'][$u] = $tmpNames[$i2]; $return['positions'][$u]['x'] = $tmpPositions[$i2]['x']; $return['positions'][$u]['y'] = $tmpPositions[$i2]['y']; AM_farmGold_addIDs($return['IDs'][$u], $building); $i2++; $u++; } if ($res == 'OK') { AddLog2('-> ' . $res . ' ' . $left . ' left'); $i = 0; } else { AddLog2("ERROR - {$res}"); return false; } } } } $return['farm'] = $farm; if ($i > 0) { $tmp = TB_sendRequest($amf); $amf2 = $tmp['amf2']; $res = $tmp['res']; $i2 = 0; while ($i2 < $i) { $return['IDs'][$u] = $amf2->_bodys[0]->_value['data'][$i2]['data']['id']; $return['itemName'][$u] = $tmpNames[$i2]; $return['positions'][$u]['x'] = $tmpPositions[$i2]['x']; $return['positions'][$u]['y'] = $tmpPositions[$i2]['y']; AM_farmGold_addIDs($return['IDs'][$u], $building); $i2++; $u++; } if ($res == 'OK') { AddLog2('-> ' . $res); return $return; } else { AddLog2("ERROR - {$res}"); AddLog2(print_r($amf2, true)); return false; } } else { return $return; } }
function SM_place($getFarm) { global $TB_settings; $units = array(); $units = TB_loadUnits(); $farm = array(); $farm = $getFarm; $itemName = ''; $sizeX = 0; $sizeY = 0; $toPlace = 0; $position = array(); if (is_array($TB_settings['SM_action']['place'])) { foreach ($TB_settings['SM_action']['place'] as $itemName => $num) { $toPlace = $num; while ($toPlace > 0) { $sizeX = $units[$itemName]['sizeX']; $sizeY = $units[$itemName]['sizeY']; $position = TB_findEmptySpot(false, $farm, $sizeX, $sizeY); if ($position == false) { AddLog2('unable to place ' . $units[$itemName]['realname'] . ' - no free space'); break; } if (SM_doPlace($itemName, $units[$itemName], $position['x'], $position['y'])) { for ($x = $position['x']; $x <= $position['x'] + $sizeX; $x++) { for ($y = $position['y']; $y <= $position['y'] + $sizeY; $y++) { $farm[$x][$y] = false; } } } $toPlace--; } } } unset($TB_settings['SM_action']['place']); return $farm; }