(svn r12719) [NoAI] -Add: finished the Reload AI button in AIDebug Window.
-Note: Now there is no longer need for you to ever shut down OpenTTD while creating an AI.
Just hit Reload when you made a code change, the company is killed and restarted with your latest code.
--- a/src/ai/ai_gui.cpp Tue Apr 15 14:49:20 2008 +0000
+++ b/src/ai/ai_gui.cpp Tue Apr 15 15:05:30 2008 +0000
@@ -18,6 +18,8 @@
#include "../date_func.h"
#include "../gfx_func.h"
#include "../debug.h"
+#include "../command_func.h"
+#include "ai.h"
#include "ai_factory.hpp"
#include "api/ai_object.hpp"
#include "api/ai_log.hpp"
@@ -161,8 +163,13 @@
}
}
if (e->we.click.widget == AID_WIDGET_RELOAD_TOGGLE && !w->IsWidgetDisabled(e->we.click.widget)) {
- /* Reload the AI */
- DEBUG(ai, 0, "Reloading not yet supported");
+ /* Set the current AI as forced next AI */
+ AIFactoryBase *factory = AI_GetPlayerFactory(_ai_debug_player);
+ AI_ForceAI(factory->GetAIName());
+
+ /* First kill the company of the AI, then start a new one. This should start the current AI again */
+ DoCommandP(0, 2, _ai_debug_player, NULL, CMD_PLAYER_CTRL);
+ DoCommandP(0, 1, 0, NULL, CMD_PLAYER_CTRL);
}
break;
--- a/src/players.cpp Tue Apr 15 14:49:20 2008 +0000
+++ b/src/players.cpp Tue Apr 15 15:05:30 2008 +0000
@@ -890,19 +890,18 @@
p = GetPlayer((PlayerID)p2);
- /* Only allow removal of HUMAN companies */
- if (IsHumanPlayer(p->index)) {
- /* Delete any open window of the company */
- DeletePlayerWindows(p->index);
+ /* Delete any open window of the company */
+ DeletePlayerWindows(p->index);
- /* Show the bankrupt news */
- SetDParam(0, p->index);
- AddNewsItem((StringID)(p->index | NB_BBANKRUPT), NM_CALLBACK, NF_NONE, NT_COMPANY_INFO, DNC_BANKRUPCY, 0, 0);
+ /* Show the bankrupt news */
+ SetDParam(0, p->index);
+ AddNewsItem((StringID)(p->index | NB_BBANKRUPT), NM_CALLBACK, NF_NONE, NT_COMPANY_INFO, DNC_BANKRUPCY, 0, 0);
- /* Remove the company */
- ChangeOwnershipOfPlayerItems(p->index, PLAYER_SPECTATOR);
- p->is_active = false;
- }
+ /* Remove the company */
+ ChangeOwnershipOfPlayerItems(p->index, PLAYER_SPECTATOR);
+ p->is_active = false;
+ if (!IsHumanPlayer(p->index)) AI_PlayerDied(p->index);
+
RemoveAllEngineReplacementForPlayer(p);
RemoveAllGroupsForPlayer(p->index);