Exemplo n.º 1
0
function AM_animalMover($name, $getBuilding, $getFarm)
{
    global $TB_settings;
    global $AM_settings;
    $building = $getBuilding;
    $farm = $getFarm;
    $buildingID = $building['id'];
    $workToDo = false;
    $left = 0;
    foreach ($AM_settings[$name] as $animal) {
        if ($TB_settings[$buildingID]['AM_move_' . $animal] > 0) {
            $workToDo = true;
            $left += $TB_settings[$buildingID]['AM_move_' . $animal];
        }
    }
    if ($workToDo) {
        $maxAnimalInBuilding = AM_getMaxAnimalsInBuilding($building);
        $cBuilding = 0;
        foreach (AM_animalInBuilding($building) as $animal => $num) {
            $cBuilding += $num;
        }
        switch ($TB_settings[$buildingID]['AM_moveTo']) {
            case $name:
                AddLog2('moving animals to building (' . $name . ')');
                if ($name == 'OrchardBuilding') {
                    AddLog2('moving trees to building (' . $name . ')');
                } else {
                    AddLog2('moving animals to building (' . $name . ')');
                }
                if ($cBuilding >= $maxAnimalInBuilding) {
                    AddLog2('building is full (' . $name . ')');
                    return true;
                }
                $re = AM_moveAnimalsToBuilding($building, $left, $name, $cBuilding, $maxAnimalInBuilding, $farm);
                break;
            case 'farm':
                if ($name == 'OrchardBuilding') {
                    AddLog2('moving trees to farm (' . $name . ')');
                } else {
                    AddLog2('moving animals to farm (' . $name . ')');
                }
                if ($cBuilding == 0) {
                    AddLog2('building is empty (' . $name . ')');
                    return true;
                }
                $re = AM_moveAnimalsToFarm($building, $left, $farm);
                break;
            default:
                $re = null;
        }
    } else {
        AddLog2('-> no work');
        $re = $farm;
    }
    if (is_array($re)) {
        return $re;
    } else {
        return false;
    }
}
Exemplo n.º 2
0
function AM_buildAnimalMoverTable($name)
{
    global $TB_settings;
    global $AM_settings;
    if ($name == 'version') {
        return false;
    }
    if (!is_array($AM_settings[$name])) {
        echo 'please let the bot run one cycle';
        return false;
    }
    $output = array();
    $buildings = array();
    $building = array();
    $animalsInBuilding = array();
    $animals = array();
    $cBuilding = array();
    $cFarm = 0;
    $cShow = 0;
    //load infos
    $buildings = AM_loadBuildingObject($name, false);
    if (count($buildings) == 0) {
        echo 'You don\'t have that building (' . $name . ')!<br />';
        return false;
    }
    $animals = AM_loadAnimalOnFarmCount($name);
    $formName = $name;
    //animals on farm
    foreach ($animals as $animal => $num) {
        $output[$animal]['farm'] = $num;
        $cFarm += $num;
    }
    foreach ($AM_settings[$name] as $animal) {
        if (!isset($output[$animal]['farm'])) {
            $output[$animal]['farm'] = 0;
        }
    }
    //animals in building(s)
    foreach ($buildings as $buildingID => $building) {
        $animalsInBuilding[$buildingID] = AM_animalInBuilding($building);
        $maxAnimalsInBuilding[$buildingID] = AM_getMaxAnimalsInBuilding($building);
        $cBuilding[$buildingID] = 0;
        foreach ($AM_settings[$name] as $animal) {
            $output[$animal][$formName][$buildingID] = 0;
        }
        foreach ($animalsInBuilding[$buildingID] as $animal => $num) {
            $output[$animal][$formName][$buildingID] = $num;
            $cBuilding[$buildingID] += $num;
        }
    }
    //show what?
    $tmp = array();
    foreach ($AM_settings[$name] as $animal) {
        $output[$animal]['show'] = false;
        if ($output[$animal]['farm'] > 0) {
            $output[$animal]['show'] = true;
            if (!in_array($animal, $tmp)) {
                $cShow++;
                $tmp[] = $animal;
            }
        } else {
            foreach ($output[$animal][$formName] as $buildingID => $num) {
                if ($num > 0) {
                    $output[$animal]['show'] = true;
                    if (!in_array($animal, $tmp)) {
                        $cShow++;
                        $tmp[] = $animal;
                    }
                }
            }
        }
    }
    //show
    echo 'You have ' . count($buildings) . ' ' . $name . '(s) &nbsp; &nbsp;';
    echo '<input type="button" value="Save changes >>" onclick="this.form.submit();" >';
    echo '<br>';
    echo '<table width="100%" class="tableWhite">';
    //on farm
    //names
    echo '<tr>';
    echo '<td rowspan="2">';
    echo 'animals on<br> farm: ' . $cFarm;
    echo '</td>';
    foreach ($AM_settings[$name] as $animal) {
        if ($output[$animal]['show']) {
            echo '<td>';
            if ($cShow > 10) {
                echo '<small>';
            }
            echo '<small>' . GetNameByItem($animal) . '</small> ';
            if ($cShow > 10) {
                echo '</small>';
            }
            echo '</td>';
        }
    }
    //on farm
    //action
    echo '<td rowspan="2" valign="bottom">';
    echo 'move to:';
    echo '</td>';
    echo '</tr>';
    //on farm
    //numbers
    echo '<tr>';
    foreach ($AM_settings[$name] as $animal) {
        if ($output[$animal]['show']) {
            $class = $output[$animal]['farm'] == 0 ? 'zero' : 'not_zero';
            echo '<td class=' . $class . '>';
            echo $output[$animal]['farm'];
            echo '</td>';
        }
    }
    foreach ($buildings as $buildingID => $building) {
        echo '<tr>';
        //in building
        //numbers
        if ($cBuilding[$buildingID] == 0) {
            $class = 'zero';
        } elseif ($cBuilding[$buildingID] == $maxAnimalsInBuilding[$buildingID]) {
            $class = 'full';
        } else {
            $class = 'not_zero';
        }
        echo '<td valign="middle" rowspan="2" class=' . $class . ' width="10%">';
        //echo 'in ' . $name . ': <br>';
        echo 'ID:' . $buildingID . '<br>';
        echo '( ' . $cBuilding[$buildingID] . ' / ' . $maxAnimalsInBuilding[$buildingID] . ') <br>';
        echo '</td>';
        foreach ($AM_settings[$name] as $animal) {
            if ($output[$animal]['show']) {
                $class = $output[$animal][$formName][$buildingID] == 0 ? 'zero' : 'not_zero';
                echo '<td class=' . $class . '>';
                echo $output[$animal][$formName][$buildingID];
                echo '</td>';
            }
        }
        //in building
        //action
        echo '<td rowspan="2" width="11%" class="actionBox">';
        $str = "<input type='radio' name='" . $buildingID . "_moveTo' value='nothing'";
        if ($TB_settings[$buildingID]['AM_moveTo'] == 'nothing') {
            $str = $str . ' checked';
        }
        echo $str . '> nothing<br>';
        $str = "<input type='radio' name='" . $buildingID . "_moveTo' value='" . $name . "'";
        if ($TB_settings[$buildingID]['AM_moveTo'] == $name) {
            $str = $str . ' checked';
        }
        echo $str . '> building<br>';
        $str = "<input type='radio' name='" . $buildingID . "_moveTo' value='farm'";
        if ($TB_settings[$buildingID]['AM_moveTo'] == 'farm') {
            $str = $str . ' checked';
        }
        echo $str . "> farm";
        echo '</td>';
        echo '</tr>';
        echo '<tr>';
        //in building
        //move
        foreach ($AM_settings[$name] as $animal) {
            if ($output[$animal]['show']) {
                $name2 = 'move_' . $buildingID . '_' . $animal;
                $state = $TB_settings[$buildingID]['AM_move_' . $animal];
                $class = $output[$animal][$formName][$buildingID] == 0 && $output[$animal]['farm'] == 0 ? 'zero' : 'not_zero';
                echo '<td class=' . $class . '>';
                if ($cShow > 10) {
                    echo '<small>';
                }
                echo 'move<br><input type="text" name=' . $name2 . ' size="1" value=' . $state . '>';
                if ($cShow > 10) {
                    echo '</small>';
                }
                echo '</td>';
            }
        }
        echo '</tr>';
    }
    echo '</tr>';
    echo '</table>';
}