--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ai/ai_gui.cpp Mon Mar 31 11:31:44 2008 +0000
@@ -0,0 +1,193 @@
+/* $Id$ */
+
+/** @file ai_gui.cpp */
+
+#include "../stdafx.h"
+#include "../openttd.h"
+#include "../gui.h"
+#include "../window_gui.h"
+#include "../player_base.h"
+#include "../player_gui.h"
+#include "../economy_func.h"
+#include "../variables.h"
+#include "../cargotype.h"
+#include "../strings_func.h"
+#include "../core/alloc_func.hpp"
+#include "../window_func.h"
+#include "../date_func.h"
+#include "../gfx_func.h"
+#include "../debug.h"
+#include "ai_factory.hpp"
+
+#include "table/strings.h"
+#include "../table/sprites.h"
+
+extern AIFactoryBase *AI_GetPlayerFactory(PlayerID player);
+
+static void AIDebugWndProc(Window *w, WindowEvent *e)
+{
+ static PlayerID _ai_debug_player = INVALID_PLAYER;
+
+ switch (e->event) {
+ case WE_PAINT: {
+ byte x;
+
+ /* Draw standard stuff */
+ DrawWindowWidgets(w);
+
+ /* Check if the currently selected player is still active. */
+ if (_ai_debug_player == INVALID_PLAYER || !GetPlayer(_ai_debug_player)->is_active) {
+ if (_ai_debug_player != INVALID_PLAYER) {
+ /* Raise and disable the widget for the previous selection. */
+ w->RaiseWidget(_ai_debug_player + 13);
+ w->DisableWidget(_ai_debug_player + 13);
+ SetWindowDirty(w);
+
+ _ai_debug_player = INVALID_PLAYER;
+ }
+
+ for (PlayerID i = PLAYER_FIRST; i < MAX_PLAYERS; i++) {
+ if (GetPlayer(i)->is_active && GetPlayer(i)->is_ai) {
+ /* Lower the widget corresponding to this player. */
+ w->LowerWidget(i + 13);
+ w->EnableWidget(4);
+ SetWindowDirty(w);
+
+ _ai_debug_player = i;
+ break;
+ }
+ }
+ }
+
+ /* If there are no active players, don't display anything else. */
+ if (_ai_debug_player == INVALID_PLAYER) break;
+
+ /* Paint the player icons */
+ for (PlayerID i = PLAYER_FIRST; i < MAX_PLAYERS; i++) {
+ if (!GetPlayer(i)->is_active || !GetPlayer(i)->is_ai) {
+ /* Check if we have the player as an active player */
+ if (!w->IsWidgetDisabled(i + 13)) {
+ /* Bah, player gone :( */
+ w->DisableWidget(i + 13);
+ w->DisableWidget(4);
+
+ /* We need a repaint */
+ SetWindowDirty(w);
+ }
+ continue;
+ }
+
+ /* Check if we have the player marked as inactive */
+ if (w->IsWidgetDisabled(i + 13)) {
+ /* New AI! Yippie :p */
+ w->EnableWidget(i + 13);
+ w->EnableWidget(4);
+ /* We need a repaint */
+ SetWindowDirty(w);
+ }
+
+ x = (i == _ai_debug_player) ? 1 : 0;
+ DrawPlayerIcon(i, i * 37 + 13 + x, 16 + x);
+ }
+
+ AIFactoryBase *factory = AI_GetPlayerFactory(_ai_debug_player);
+ DoDrawString(factory->GetAIName(), 7, 34, TC_BLACK);
+
+ break;
+ }
+
+ case WE_CLICK:
+ /* Check which button is clicked */
+ if (IsInsideMM(e->we.click.widget, 13, 21)) {
+ /* Is it no on disable? */
+ if (!w->IsWidgetDisabled(e->we.click.widget)) {
+ w->RaiseWidget(_ai_debug_player + 13);
+ _ai_debug_player = (PlayerID)(e->we.click.widget - 13);
+ w->LowerWidget(_ai_debug_player + 13);
+ SetWindowDirty(w);
+ }
+ }
+ if (e->we.click.widget == 4 && !w->IsWidgetDisabled(e->we.click.widget)) {
+ /* Reload the AI */
+ DEBUG(ai, 0, "Reloading not yet supported");
+ }
+ break;
+
+ case WE_CREATE: {
+ /* Disable the players who are not active or not an AI */
+ for (PlayerID i = PLAYER_FIRST; i < MAX_PLAYERS; i++) {
+ w->SetWidgetDisabledState(i + 13, !GetPlayer(i)->is_active || !GetPlayer(i)->is_ai);
+ }
+ w->DisableWidget(4);
+
+ w->custom[0] = DAY_TICKS;
+ w->custom[1] = 5;
+
+ if (_ai_debug_player != INVALID_PLAYER) w->LowerWidget(_ai_debug_player + 13);
+ SetWindowDirty(w);
+
+ break;
+ }
+
+ case WE_TICK:
+ if (_pause_game != 0) break;
+
+ /* Update the AI logs every 5 days */
+ if (--w->custom[0] == 0) {
+ w->custom[0] = DAY_TICKS;
+ if (--w->custom[1] == 0) {
+ w->custom[1] = 5;
+
+ SetWindowDirty(w);
+ }
+ }
+
+ break;
+
+ case WE_TIMEOUT:
+ w->RaiseWidget(4);
+ SetWindowDirty(w);
+ break;
+ }
+}
+
+static const Widget _ai_debug_widgets[] = {
+{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
+{ WWT_CAPTION, RESIZE_NONE, 14, 11, 298, 0, 13, STR_AI_DEBUG, STR_018C_WINDOW_TITLE_DRAG_THIS},
+{ WWT_PANEL, RESIZE_NONE, 14, 0, 298, 14, 27, 0x0, STR_NULL},
+
+{ WWT_PANEL, RESIZE_NONE, 14, 0, 149, 28, 47, 0x0, STR_AI_DEBUG_NAME_TIP},
+{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 150, 298, 28, 47, STR_AI_DEBUG_RELOAD, STR_AI_DEBUG_RELOAD_TIP},
+{ WWT_PANEL, RESIZE_NONE, 14, 0, 298, 48, 227, 0x0, STR_NULL},
+/* As this is WIP, leave the next few so we can work a bit with the GUI */
+{ WWT_EMPTY, RESIZE_NONE, 14, 0, 298, 88, 107, 0x0, STR_NULL},
+{ WWT_EMPTY, RESIZE_NONE, 14, 0, 298, 108, 127, 0x0, STR_NULL},
+{ WWT_EMPTY, RESIZE_NONE, 14, 0, 298, 128, 147, 0x0, STR_NULL},
+{ WWT_EMPTY, RESIZE_NONE, 14, 0, 298, 148, 167, 0x0, STR_NULL},
+{ WWT_EMPTY, RESIZE_NONE, 14, 0, 298, 168, 187, 0x0, STR_NULL},
+{ WWT_EMPTY, RESIZE_NONE, 14, 0, 298, 188, 207, 0x0, STR_NULL},
+{ WWT_EMPTY, RESIZE_NONE, 14, 0, 298, 208, 227, 0x0, STR_NULL},
+
+{ WWT_PANEL, RESIZE_NONE, 14, 2, 38, 14, 26, 0x0, STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
+{ WWT_PANEL, RESIZE_NONE, 14, 39, 75, 14, 26, 0x0, STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
+{ WWT_PANEL, RESIZE_NONE, 14, 76, 112, 14, 26, 0x0, STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
+{ WWT_PANEL, RESIZE_NONE, 14, 113, 149, 14, 26, 0x0, STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
+{ WWT_PANEL, RESIZE_NONE, 14, 150, 186, 14, 26, 0x0, STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
+{ WWT_PANEL, RESIZE_NONE, 14, 187, 223, 14, 26, 0x0, STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
+{ WWT_PANEL, RESIZE_NONE, 14, 224, 260, 14, 26, 0x0, STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
+{ WWT_PANEL, RESIZE_NONE, 14, 261, 297, 14, 26, 0x0, STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
+{ WIDGETS_END},
+};
+
+static const WindowDesc _ai_debug_desc = {
+ WDP_AUTO, WDP_AUTO, 299, 228, 299, 228,
+ WC_PERFORMANCE_DETAIL, WC_NONE,
+ WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
+ _ai_debug_widgets,
+ AIDebugWndProc
+};
+
+void ShowAIDebugWindow()
+{
+ AllocateWindowDescFront(&_ai_debug_desc, 0);
+}