jhaagsma / ee_npc

Earth Empires Non-Player-Country Project!
6 stars 7 forks source link

FFA bot got stuck in infinite loop #16

Open jobbish-sql opened 3 years ago

jobbish-sql commented 3 years ago

Unexpected Result for 'pm': ERROR:OWNED

PHP Notice: Trying to get property of non-object in /home/eenpc/ffa_test/PrivateMarket.class.php on line 136 PHP Warning: Invalid argument supplied for foreach() in /home/eenpc/ffa_test/PrivateMarket.class.php on line 141

[17:41:57] --- SELL Private Market: [17:41:57] We have stored turns or can't sell on public; sell 1/10 of military.

Unexpected Result for 'pm': ERROR:OWNED

PHP Notice: Trying to get property of non-object in /home/eenpc/ffa_test/PrivateMarket.class.php on line 136 PHP Warning: Invalid argument supplied for foreach() in /home/eenpc/ffa_test/PrivateMarket.class.php on line 141

[17:41:57] --- SELL Private Market: [17:41:57] We have stored turns or can't sell on public; sell 1/10 of military. [17:41:57]

Unexpected Result for 'pm': ERROR:OWNED

PHP Notice: Trying to get property of non-object in /home/eenpc/ffa_test/PrivateMarket.class.php on line 136 PHP Notice: Trying to get property of non-object in /home/eenpc/ffa_test/PrivateMarket.class.php on line 141 PHP Warning: Invalid argument supplied for foreach() in /home/eenpc/ffa_test/PrivateMarket.class.php on line 141

jobbish-sql commented 3 years ago

The problem is in money management. If one of the object values for military is somehow wrong (a bot gets attacked or spied?), then it can get stuck in an infinite loop because selling on PM fails. We should catch a PM error and update main if we get one (and log an error).

The new logging will be helpful here as well. I couldn't even identify the cnum of the bot that got stuck.

function money_management(&$c, $server_max_possible_market_sell) { while (turns_of_money($c) < 4) { //$foodloss = -1 * $c->foodnet;

    if ($c->turns_stored <= 30 && total_cansell_military($c, $server_max_possible_market_sell) > 7500) {
        log_country_message($c->cnum, "Selling max military, and holding turns.");
        sell_max_military($c, $server_max_possible_market_sell);
        return true;
    } elseif ($c->turns_stored > 30 && total_military($c) > 1000) {
        log_country_message($c->cnum, "We have stored turns or can't sell on public; sell 1/10 of military.");   //Text for screen
        sell_all_military($c, 1 / 10);
    } else {
        log_country_message($c->cnum, "Low stored turns ({$c->turns_stored}); can't sell? (".total_cansell_military($c, $server_max_possible_market_sell).')');
        return true;
    }
}

return false;

}//end money_management()