src/ai/ai.cpp
author truebrain
Fri, 13 Jun 2008 20:19:00 +0000
branchnoai
changeset 10958 65088d587094
parent 10891 5ebb6f9068d0
child 11098 37d15a8951b8
permissions -rw-r--r--
(svn r13512) [NoAI] -Fix: don't load a library over and over, but keep track of which libraries we have loaded (per AI) and re-use it where possible (reduces memory-footprint)
[NoAI] -Fix: change the fake-library-name-counter to a per AI value, not global
[NoAI] -Fix: Load the script inside the thread, not in the main thread. This avoids unneeded error-handling
2395
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
     1
/* $Id$ */
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
     2
10455
22c441f5adf9 (svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents: 10412
diff changeset
     3
/** @file ai.cpp Handles the communication between the AI layer and the OpenTTD core */
9360
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents: 9359
diff changeset
     4
9429
25b7d020a3a9 (svn r9232) [NoAI] -Fix r9230: incode update about file/dir moving
truelight
parents: 9427
diff changeset
     5
#include "../stdafx.h"
25b7d020a3a9 (svn r9232) [NoAI] -Fix r9230: incode update about file/dir moving
truelight
parents: 9427
diff changeset
     6
#include "../openttd.h"
25b7d020a3a9 (svn r9232) [NoAI] -Fix r9230: incode update about file/dir moving
truelight
parents: 9427
diff changeset
     7
#include "../variables.h"
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9682
diff changeset
     8
#include "../command_func.h"
9429
25b7d020a3a9 (svn r9232) [NoAI] -Fix r9230: incode update about file/dir moving
truelight
parents: 9427
diff changeset
     9
#include "../network/network.h"
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9682
diff changeset
    10
#include "../core/alloc_func.hpp"
9724
b39bc69bb2f2 (svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents: 9723
diff changeset
    11
#include "../settings_type.h"
b39bc69bb2f2 (svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents: 9723
diff changeset
    12
#include "../player_base.h"
b39bc69bb2f2 (svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents: 9723
diff changeset
    13
#include "../player_func.h"
9429
25b7d020a3a9 (svn r9232) [NoAI] -Fix r9230: incode update about file/dir moving
truelight
parents: 9427
diff changeset
    14
#include "../debug.h"
9621
7654501cf02d (svn r9821) [NoAI] -Fix: support compilation without threads.
rubidium
parents: 9467
diff changeset
    15
7654501cf02d (svn r9821) [NoAI] -Fix: support compilation without threads.
rubidium
parents: 9467
diff changeset
    16
#ifndef NO_THREADS
10643
970417eef395 (svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents: 10455
diff changeset
    17
#include <squirrel.h>
970417eef395 (svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents: 10455
diff changeset
    18
#include "../squirrel.hpp"
970417eef395 (svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents: 10455
diff changeset
    19
#include "../squirrel_helper.hpp"
970417eef395 (svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents: 10455
diff changeset
    20
#include "../squirrel_class.hpp"
970417eef395 (svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents: 10455
diff changeset
    21
#include "../squirrel_std.hpp"
970417eef395 (svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents: 10455
diff changeset
    22
#include "api/ai_controller.hpp"
970417eef395 (svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents: 10455
diff changeset
    23
#include "ai_squirrel.hpp"
970417eef395 (svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents: 10455
diff changeset
    24
#include "ai_info.hpp"
2395
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
    25
#include "ai.h"
9444
fd27df7ca2a0 (svn r9260) [NoAI] -Codechange: do the AI threading properly using a mutex and condition signalling.
rubidium
parents: 9441
diff changeset
    26
#include "ai_threads.h"
9429
25b7d020a3a9 (svn r9232) [NoAI] -Fix r9230: incode update about file/dir moving
truelight
parents: 9427
diff changeset
    27
#include "api/ai_base.hpp"
9724
b39bc69bb2f2 (svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents: 9723
diff changeset
    28
#include "../signal_func.h"
10739
0d70706cf183 (svn r13289) [NoAI] -Codechange: better refreshing of AIDebug window
glx
parents: 10718
diff changeset
    29
#include "../window_func.h"
9360
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents: 9359
diff changeset
    30
9361
7bb2bd22b16e (svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
truelight
parents: 9360
diff changeset
    31
static AIController *_ai_player[MAX_PLAYERS];
10643
970417eef395 (svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents: 10455
diff changeset
    32
static AIInfo *_ai_info[MAX_PLAYERS];
10649
9034b80fdbdb (svn r13193) [NoAI] -Add: allow AIs to be packed in a .tar. one AI per tar, always in a subdir. It looks for main.nut in the first dir it finds in the archive
truebrain
parents: 10643
diff changeset
    33
static AISquirrel *_ai_squirrel = NULL;
9360
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents: 9359
diff changeset
    34
static uint _ai_frame_counter;
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents: 9359
diff changeset
    35
static bool _ai_enabled;
9467
730cae121ae3 (svn r9305) [NoAI] -Add: option to force-select an AI from the console.
rubidium
parents: 9454
diff changeset
    36
static char *_forced_ai_name = NULL;
2715
0ad451d9264b (svn r3260) -Add: add events for AIs to check if a command execution failed or succeeded
truelight
parents: 2707
diff changeset
    37
2395
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
    38
/**
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
    39
 * The gameloop for AIs.
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
    40
 *  Handles one tick for all the AIs.
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
    41
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 5860
diff changeset
    42
void AI_RunGameLoop()
2395
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
    43
{
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
    44
	/* Don't do anything if ai is disabled */
9360
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents: 9359
diff changeset
    45
	if (!_ai_enabled) return;
2395
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
    46
5332
ffb2e98b961e (svn r7494) -Fix: Really disable AI's in Multiplayer if you tell it so. In loaded games with
Darkvater
parents: 4854
diff changeset
    47
	/* Don't do anything if we are a network-client, or the AI has been disabled */
10776
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10740
diff changeset
    48
	if (_networking && (!_network_server || !_settings_game.ai.ai_in_multiplayer)) return;
2682
94ca0b4dc53f (svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents: 2639
diff changeset
    49
2395
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
    50
	/* New tick */
9360
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents: 9359
diff changeset
    51
	_ai_frame_counter++;
2395
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
    52
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
    53
	/* Make sure the AI follows the difficulty rule.. */
10776
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10740
diff changeset
    54
	assert(_settings_game.difficulty.competitor_speed <= 4);
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10740
diff changeset
    55
	if ((_ai_frame_counter & ((1 << (4 - _settings_game.difficulty.competitor_speed)) - 1)) != 0) return;
2395
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
    56
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
    57
	/* Check for AI-client (so joining a network with an AI) */
4854
383ef523793f (svn r6780) -Codechange: Remove GPMI leftovers (-b impersonisation of AI in MP).
Darkvater
parents: 4850
diff changeset
    58
	if (!_networking || _network_server) {
2395
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
    59
		/* Check if we want to run AIs (server or SP only) */
9822
e2f83940bc52 (svn r12430) [NoAI] -Fix: safeguard, don't allow AI_Event calls to players that are not AIs
truebrain
parents: 9770
diff changeset
    60
		const Player *p;
2395
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
    61
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
    62
		FOR_ALL_PLAYERS(p) {
2767
3282c77ffc27 (svn r3313) Remove GPMI related changes from trunk
tron
parents: 2761
diff changeset
    63
			if (p->is_active && p->is_ai) {
2395
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
    64
				/* Run the script */
9444
fd27df7ca2a0 (svn r9260) [NoAI] -Codechange: do the AI threading properly using a mutex and condition signalling.
rubidium
parents: 9441
diff changeset
    65
				if (_ai_player[p->index] == NULL) continue;
fd27df7ca2a0 (svn r9260) [NoAI] -Codechange: do the AI threading properly using a mutex and condition signalling.
rubidium
parents: 9441
diff changeset
    66
				_current_player = p->index;
2395
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
    67
				AI_RunTick(p->index);
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
    68
			}
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
    69
		}
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
    70
	}
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
    71
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
    72
	_current_player = OWNER_NONE;
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
    73
}
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
    74
9682
d031eb183733 (svn r10631) [NoAI] -Add: AIEvent, to take care of events; for now it only reports when vehicles are crashed
truelight
parents: 9643
diff changeset
    75
void AI_Event(PlayerID player, AIEvent *event)
d031eb183733 (svn r10631) [NoAI] -Add: AIEvent, to take care of events; for now it only reports when vehicles are crashed
truelight
parents: 9643
diff changeset
    76
{
9822
e2f83940bc52 (svn r12430) [NoAI] -Fix: safeguard, don't allow AI_Event calls to players that are not AIs
truebrain
parents: 9770
diff changeset
    77
	if (player >= MAX_PLAYERS || !GetPlayer(player)->is_active || !GetPlayer(player)->is_ai) return;
10412
ef44f62cb8b9 (svn r12954) [NoAI] -Fix: move the DEBUG level of non-essential debug statements up a few levels, so it doesn't show up at least before lvl 5
truebrain
parents: 9850
diff changeset
    78
	DEBUG(ai, 5, "Event (%d) for player %d\n", event->GetEventType(), player);
9682
d031eb183733 (svn r10631) [NoAI] -Add: AIEvent, to take care of events; for now it only reports when vehicles are crashed
truelight
parents: 9643
diff changeset
    79
d031eb183733 (svn r10631) [NoAI] -Add: AIEvent, to take care of events; for now it only reports when vehicles are crashed
truelight
parents: 9643
diff changeset
    80
	PlayerID old_player = _current_player;
d031eb183733 (svn r10631) [NoAI] -Add: AIEvent, to take care of events; for now it only reports when vehicles are crashed
truelight
parents: 9643
diff changeset
    81
	_current_player = player;
d031eb183733 (svn r10631) [NoAI] -Add: AIEvent, to take care of events; for now it only reports when vehicles are crashed
truelight
parents: 9643
diff changeset
    82
	AIEventController::InsertEvent(event);
d031eb183733 (svn r10631) [NoAI] -Add: AIEvent, to take care of events; for now it only reports when vehicles are crashed
truelight
parents: 9643
diff changeset
    83
	_current_player = old_player;
d031eb183733 (svn r10631) [NoAI] -Add: AIEvent, to take care of events; for now it only reports when vehicles are crashed
truelight
parents: 9643
diff changeset
    84
}
d031eb183733 (svn r10631) [NoAI] -Add: AIEvent, to take care of events; for now it only reports when vehicles are crashed
truelight
parents: 9643
diff changeset
    85
2395
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
    86
/**
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
    87
 * A new AI sees the day of light. You can do here what ever you think is needed.
10740
325e94c419ac (svn r13290) [NoAI] -Fix: do not activate a new player when no suitable AI can be found to start it. Also, when loading a savegame, do not consider a player as AI if no suitable AI can be found for it.
glx
parents: 10739
diff changeset
    88
 * @return True if the AI is started.
2395
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
    89
 */
10740
325e94c419ac (svn r13290) [NoAI] -Fix: do not activate a new player when no suitable AI can be found to start it. Also, when loading a savegame, do not consider a player as AI if no suitable AI can be found for it.
glx
parents: 10739
diff changeset
    90
bool AI_StartNewAI(PlayerID player)
2395
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
    91
{
4850
b4e9be22945f (svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents: 4848
diff changeset
    92
	assert(IsValidPlayer(player));
10740
325e94c419ac (svn r13290) [NoAI] -Fix: do not activate a new player when no suitable AI can be found to start it. Also, when loading a savegame, do not consider a player as AI if no suitable AI can be found for it.
glx
parents: 10739
diff changeset
    93
	if (!_ai_enabled) return false;
325e94c419ac (svn r13290) [NoAI] -Fix: do not activate a new player when no suitable AI can be found to start it. Also, when loading a savegame, do not consider a player as AI if no suitable AI can be found for it.
glx
parents: 10739
diff changeset
    94
	if (_networking && !_network_server) return false;
2702
e4663e88c530 (svn r3246) -Fix: small glitch in ai_network_client code (network_client.c)
truelight
parents: 2701
diff changeset
    95
10643
970417eef395 (svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents: 10455
diff changeset
    96
	AIInfo *info;
9467
730cae121ae3 (svn r9305) [NoAI] -Add: option to force-select an AI from the console.
rubidium
parents: 9454
diff changeset
    97
	if (_forced_ai_name == NULL) {
10643
970417eef395 (svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents: 10455
diff changeset
    98
		info = _ai_squirrel->SelectRandomAI();
9467
730cae121ae3 (svn r9305) [NoAI] -Add: option to force-select an AI from the console.
rubidium
parents: 9454
diff changeset
    99
	} else {
10643
970417eef395 (svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents: 10455
diff changeset
   100
		info = _ai_squirrel->SelectAI(_forced_ai_name);
9467
730cae121ae3 (svn r9305) [NoAI] -Add: option to force-select an AI from the console.
rubidium
parents: 9454
diff changeset
   101
	}
10643
970417eef395 (svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents: 10455
diff changeset
   102
	if (info == NULL) {
9467
730cae121ae3 (svn r9305) [NoAI] -Add: option to force-select an AI from the console.
rubidium
parents: 9454
diff changeset
   103
		if (_forced_ai_name == NULL) {
730cae121ae3 (svn r9305) [NoAI] -Add: option to force-select an AI from the console.
rubidium
parents: 9454
diff changeset
   104
			DEBUG(ai, 0, "Couldn't find a suitable AI to start for company '%d'", player);
730cae121ae3 (svn r9305) [NoAI] -Add: option to force-select an AI from the console.
rubidium
parents: 9454
diff changeset
   105
		} else {
730cae121ae3 (svn r9305) [NoAI] -Add: option to force-select an AI from the console.
rubidium
parents: 9454
diff changeset
   106
			DEBUG(ai, 0, "The AI named \"%s\" is unknown or not suitable", _forced_ai_name);
730cae121ae3 (svn r9305) [NoAI] -Add: option to force-select an AI from the console.
rubidium
parents: 9454
diff changeset
   107
		}
10740
325e94c419ac (svn r13290) [NoAI] -Fix: do not activate a new player when no suitable AI can be found to start it. Also, when loading a savegame, do not consider a player as AI if no suitable AI can be found for it.
glx
parents: 10739
diff changeset
   108
		return false;
9383
817b07079052 (svn r9173) [NoAI] -Codechange: start both AIs when the game starts more than one.
rubidium
parents: 9365
diff changeset
   109
	}
9770
ad3c5f807d7c (svn r12260) [NoAI] -Change: make SelectAI return the factory, so some GUI might read how the AI is called, and who wrote it, etc etc
truebrain
parents: 9724
diff changeset
   110
10650
30fc5395b1b8 (svn r13194) [NoAI] -Change [API CHANGE]: split 'main.nut' in 'info.nut' and 'main.nut'. The first contains the information about the AI, the second the AI. This avoid several problems we had. It also speeds up OpenTTD start-up.
truebrain
parents: 10649
diff changeset
   111
	_current_player = player;
10643
970417eef395 (svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents: 10455
diff changeset
   112
	_ai_info[player] = info;
10650
30fc5395b1b8 (svn r13194) [NoAI] -Change [API CHANGE]: split 'main.nut' in 'info.nut' and 'main.nut'. The first contains the information about the AI, the second the AI. This avoid several problems we had. It also speeds up OpenTTD start-up.
truebrain
parents: 10649
diff changeset
   113
	AIObject::ResetInternalPlayerData();
10643
970417eef395 (svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents: 10455
diff changeset
   114
	_ai_player[player] = info->CreateInstance();
9441
03da911c8d5f (svn r9255) [NoAI] -Add: each AI now runs in a seperate thread. The main thread is suspended if any AI thread is running, only one AI thread runs at the time.
truelight
parents: 9433
diff changeset
   115
	AI_StartPlayer(player, _ai_player[player]);
10739
0d70706cf183 (svn r13289) [NoAI] -Codechange: better refreshing of AIDebug window
glx
parents: 10718
diff changeset
   116
	InvalidateWindowData(WC_AI_DEBUG, 0, -1);
10740
325e94c419ac (svn r13290) [NoAI] -Fix: do not activate a new player when no suitable AI can be found to start it. Also, when loading a savegame, do not consider a player as AI if no suitable AI can be found for it.
glx
parents: 10739
diff changeset
   117
	return true;
2395
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
   118
}
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
   119
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
   120
/**
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
   121
 * This AI player died. Give it some chance to make a final puf.
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
   122
 */
2551
436aaaa22ba5 (svn r3080) byte -> PlayerID, int -> EngineID, -1 -> INVALID_ENGINE
tron
parents: 2548
diff changeset
   123
void AI_PlayerDied(PlayerID player)
2395
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
   124
{
9360
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents: 9359
diff changeset
   125
	if (!_ai_enabled) return;
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents: 9359
diff changeset
   126
9643
413e30aed44e (svn r10535) [NoAI] -Fix: set _current_player also for dying AI (tnx Rubidium for the help!!)
truelight
parents: 9621
diff changeset
   127
	_current_player = player;
9444
fd27df7ca2a0 (svn r9260) [NoAI] -Codechange: do the AI threading properly using a mutex and condition signalling.
rubidium
parents: 9441
diff changeset
   128
	AI_StopPlayer(player);
2395
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
   129
	/* Called if this AI died */
9361
7bb2bd22b16e (svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
truelight
parents: 9360
diff changeset
   130
	delete _ai_player[player];
9444
fd27df7ca2a0 (svn r9260) [NoAI] -Codechange: do the AI threading properly using a mutex and condition signalling.
rubidium
parents: 9441
diff changeset
   131
	_ai_player[player] = NULL;
10643
970417eef395 (svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents: 10455
diff changeset
   132
	_ai_info[player] = NULL;
10739
0d70706cf183 (svn r13289) [NoAI] -Codechange: better refreshing of AIDebug window
glx
parents: 10718
diff changeset
   133
	InvalidateWindowData(WC_AI_DEBUG, 0, -1);
2395
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
   134
}
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
   135
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
   136
/**
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
   137
 * Initialize some AI-related stuff.
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
   138
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 5860
diff changeset
   139
void AI_Initialize()
2395
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
   140
{
2706
d31bd0aa0096 (svn r3250) -Fix: AIs weren't uninitialized when a new game was loaded
truelight
parents: 2702
diff changeset
   141
	/* First, make sure all AIs are DEAD! */
d31bd0aa0096 (svn r3250) -Fix: AIs weren't uninitialized when a new game was loaded
truelight
parents: 2702
diff changeset
   142
	AI_Uninitialize();
d31bd0aa0096 (svn r3250) -Fix: AIs weren't uninitialized when a new game was loaded
truelight
parents: 2702
diff changeset
   143
2767
3282c77ffc27 (svn r3313) Remove GPMI related changes from trunk
tron
parents: 2761
diff changeset
   144
	memset(&_ai_player, 0, sizeof(_ai_player));
10643
970417eef395 (svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents: 10455
diff changeset
   145
	memset(&_ai_info, 0, sizeof(_ai_info));
9360
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents: 9359
diff changeset
   146
	_ai_frame_counter = 0;
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents: 9359
diff changeset
   147
	_ai_enabled = true;
9400
6da42d57fda2 (svn r9195) [NoAI] -Fix: move GetName to AIFactory template, as otherwise GetName()
truelight
parents: 9390
diff changeset
   148
10643
970417eef395 (svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents: 10455
diff changeset
   149
	/* Create the Squirrel collector, which scans for all AIs available */
10649
9034b80fdbdb (svn r13193) [NoAI] -Add: allow AIs to be packed in a .tar. one AI per tar, always in a subdir. It looks for main.nut in the first dir it finds in the archive
truebrain
parents: 10643
diff changeset
   150
	assert(_ai_squirrel == NULL);
10643
970417eef395 (svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents: 10455
diff changeset
   151
	_ai_squirrel = new AISquirrel();
2395
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
   152
}
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
   153
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
   154
/**
9467
730cae121ae3 (svn r9305) [NoAI] -Add: option to force-select an AI from the console.
rubidium
parents: 9454
diff changeset
   155
 * Forces the given AI to be used for all players.
730cae121ae3 (svn r9305) [NoAI] -Add: option to force-select an AI from the console.
rubidium
parents: 9454
diff changeset
   156
 * Pass NULL to use a random AI.
730cae121ae3 (svn r9305) [NoAI] -Add: option to force-select an AI from the console.
rubidium
parents: 9454
diff changeset
   157
 * @param forced_ai the AI to force.
730cae121ae3 (svn r9305) [NoAI] -Add: option to force-select an AI from the console.
rubidium
parents: 9454
diff changeset
   158
 */
730cae121ae3 (svn r9305) [NoAI] -Add: option to force-select an AI from the console.
rubidium
parents: 9454
diff changeset
   159
void AI_ForceAI(const char *forced_ai)
730cae121ae3 (svn r9305) [NoAI] -Add: option to force-select an AI from the console.
rubidium
parents: 9454
diff changeset
   160
{
730cae121ae3 (svn r9305) [NoAI] -Add: option to force-select an AI from the console.
rubidium
parents: 9454
diff changeset
   161
	free(_forced_ai_name);
730cae121ae3 (svn r9305) [NoAI] -Add: option to force-select an AI from the console.
rubidium
parents: 9454
diff changeset
   162
	_forced_ai_name = (forced_ai == NULL) ? NULL : strdup(forced_ai);
730cae121ae3 (svn r9305) [NoAI] -Add: option to force-select an AI from the console.
rubidium
parents: 9454
diff changeset
   163
}
730cae121ae3 (svn r9305) [NoAI] -Add: option to force-select an AI from the console.
rubidium
parents: 9454
diff changeset
   164
10643
970417eef395 (svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents: 10455
diff changeset
   165
char *AI_GetConsoleList(char *p, const char *last)
9770
ad3c5f807d7c (svn r12260) [NoAI] -Change: make SelectAI return the factory, so some GUI might read how the AI is called, and who wrote it, etc etc
truebrain
parents: 9724
diff changeset
   166
{
10643
970417eef395 (svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents: 10455
diff changeset
   167
	return _ai_squirrel->GetAIConsoleList(p, last);
970417eef395 (svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents: 10455
diff changeset
   168
}
970417eef395 (svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents: 10455
diff changeset
   169
970417eef395 (svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents: 10455
diff changeset
   170
AIInfo *AI_GetPlayerInfo(PlayerID player)
970417eef395 (svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents: 10455
diff changeset
   171
{
970417eef395 (svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents: 10455
diff changeset
   172
	return _ai_info[player];
9770
ad3c5f807d7c (svn r12260) [NoAI] -Change: make SelectAI return the factory, so some GUI might read how the AI is called, and who wrote it, etc etc
truebrain
parents: 9724
diff changeset
   173
}
9467
730cae121ae3 (svn r9305) [NoAI] -Add: option to force-select an AI from the console.
rubidium
parents: 9454
diff changeset
   174
730cae121ae3 (svn r9305) [NoAI] -Add: option to force-select an AI from the console.
rubidium
parents: 9454
diff changeset
   175
/**
10718
7e9d9e40e16f (svn r13268) [NoAI] -Fix: kill AIs on game abortion
glx
parents: 10715
diff changeset
   176
 * Kill all AIs.
2395
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
   177
 */
10718
7e9d9e40e16f (svn r13268) [NoAI] -Fix: kill AIs on game abortion
glx
parents: 10715
diff changeset
   178
void AI_KillAll()
2395
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
   179
{
4000
bab1ebc37da0 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3950
diff changeset
   180
	const Player* p;
2395
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
   181
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
   182
	FOR_ALL_PLAYERS(p) {
2767
3282c77ffc27 (svn r3313) Remove GPMI related changes from trunk
tron
parents: 2761
diff changeset
   183
		if (p->is_active && p->is_ai) AI_PlayerDied(p->index);
2395
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
   184
	}
10718
7e9d9e40e16f (svn r13268) [NoAI] -Fix: kill AIs on game abortion
glx
parents: 10715
diff changeset
   185
}
10643
970417eef395 (svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents: 10455
diff changeset
   186
10718
7e9d9e40e16f (svn r13268) [NoAI] -Fix: kill AIs on game abortion
glx
parents: 10715
diff changeset
   187
/**
7e9d9e40e16f (svn r13268) [NoAI] -Fix: kill AIs on game abortion
glx
parents: 10715
diff changeset
   188
 * Deinitializer for AI-related stuff.
7e9d9e40e16f (svn r13268) [NoAI] -Fix: kill AIs on game abortion
glx
parents: 10715
diff changeset
   189
 */
7e9d9e40e16f (svn r13268) [NoAI] -Fix: kill AIs on game abortion
glx
parents: 10715
diff changeset
   190
void AI_Uninitialize()
7e9d9e40e16f (svn r13268) [NoAI] -Fix: kill AIs on game abortion
glx
parents: 10715
diff changeset
   191
{
7e9d9e40e16f (svn r13268) [NoAI] -Fix: kill AIs on game abortion
glx
parents: 10715
diff changeset
   192
	AI_KillAll();
10643
970417eef395 (svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents: 10455
diff changeset
   193
	delete _ai_squirrel;
10649
9034b80fdbdb (svn r13193) [NoAI] -Add: allow AIs to be packed in a .tar. one AI per tar, always in a subdir. It looks for main.nut in the first dir it finds in the archive
truebrain
parents: 10643
diff changeset
   194
	_ai_squirrel = NULL;
2395
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents:
diff changeset
   195
}
9360
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents: 9359
diff changeset
   196
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents: 9359
diff changeset
   197
/**
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents: 9359
diff changeset
   198
 * Is it allowed to start a new AI.
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents: 9359
diff changeset
   199
 * This function checks some boundries to see if we should launch a new AI.
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents: 9359
diff changeset
   200
 * @return True if we can start a new AI.
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents: 9359
diff changeset
   201
 */
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents: 9359
diff changeset
   202
bool AI_AllowNewAI()
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents: 9359
diff changeset
   203
{
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents: 9359
diff changeset
   204
	/* If disabled, no AI */
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents: 9359
diff changeset
   205
	if (!_ai_enabled) return false;
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents: 9359
diff changeset
   206
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents: 9359
diff changeset
   207
	/* If in network, but no server, no AI */
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents: 9359
diff changeset
   208
	if (_networking && !_network_server) return false;
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents: 9359
diff changeset
   209
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents: 9359
diff changeset
   210
	/* If in network, and server, possible AI */
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents: 9359
diff changeset
   211
	if (_networking && _network_server) {
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents: 9359
diff changeset
   212
		/* Do we want AIs in multiplayer? */
10776
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10740
diff changeset
   213
		if (!_settings_game.ai.ai_in_multiplayer) return false;
9360
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents: 9359
diff changeset
   214
	}
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents: 9359
diff changeset
   215
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents: 9359
diff changeset
   216
	return true;
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents: 9359
diff changeset
   217
}
9621
7654501cf02d (svn r9821) [NoAI] -Fix: support compilation without threads.
rubidium
parents: 9467
diff changeset
   218
10889
ecb77cfc4a10 (svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents: 10776
diff changeset
   219
bool AI_ImportLibrary(const char *library, const char *class_name, int version, HSQUIRRELVM vm)
ecb77cfc4a10 (svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents: 10776
diff changeset
   220
{
10958
65088d587094 (svn r13512) [NoAI] -Fix: don't load a library over and over, but keep track of which libraries we have loaded (per AI) and re-use it where possible (reduces memory-footprint)
truebrain
parents: 10891
diff changeset
   221
	return _ai_squirrel->ImportLibrary(library, class_name, version, vm, _ai_player[_current_player]);
10889
ecb77cfc4a10 (svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents: 10776
diff changeset
   222
}
ecb77cfc4a10 (svn r13440) [NoAI] -Add: introducing ai/library, a method to load libraries into your AI.
truebrain
parents: 10776
diff changeset
   223
10891
5ebb6f9068d0 (svn r13442) [NoAI] -Add: added 'rescan_ai' console command. Use it to rescan the ai dir when you add AIs or libraries without needing to exit and restart openttd.
glx
parents: 10890
diff changeset
   224
void AI_Rescan()
5ebb6f9068d0 (svn r13442) [NoAI] -Add: added 'rescan_ai' console command. Use it to rescan the ai dir when you add AIs or libraries without needing to exit and restart openttd.
glx
parents: 10890
diff changeset
   225
{
5ebb6f9068d0 (svn r13442) [NoAI] -Add: added 'rescan_ai' console command. Use it to rescan the ai dir when you add AIs or libraries without needing to exit and restart openttd.
glx
parents: 10890
diff changeset
   226
	_ai_squirrel->RescanAIDir();
5ebb6f9068d0 (svn r13442) [NoAI] -Add: added 'rescan_ai' console command. Use it to rescan the ai dir when you add AIs or libraries without needing to exit and restart openttd.
glx
parents: 10890
diff changeset
   227
}
5ebb6f9068d0 (svn r13442) [NoAI] -Add: added 'rescan_ai' console command. Use it to rescan the ai dir when you add AIs or libraries without needing to exit and restart openttd.
glx
parents: 10890
diff changeset
   228
9621
7654501cf02d (svn r9821) [NoAI] -Fix: support compilation without threads.
rubidium
parents: 9467
diff changeset
   229
#else /* NO_THREADS */
7654501cf02d (svn r9821) [NoAI] -Fix: support compilation without threads.
rubidium
parents: 9467
diff changeset
   230
/* Stub functions for when we do not have threads. */
7654501cf02d (svn r9821) [NoAI] -Fix: support compilation without threads.
rubidium
parents: 9467
diff changeset
   231
void AI_StartNewAI(PlayerID player) { DEBUG(ai, 0, "Threading is disabled and therefor the AI too."); }
7654501cf02d (svn r9821) [NoAI] -Fix: support compilation without threads.
rubidium
parents: 9467
diff changeset
   232
void AI_PlayerDied(PlayerID player) {}
7654501cf02d (svn r9821) [NoAI] -Fix: support compilation without threads.
rubidium
parents: 9467
diff changeset
   233
void AI_RunGameLoop() {}
9682
d031eb183733 (svn r10631) [NoAI] -Add: AIEvent, to take care of events; for now it only reports when vehicles are crashed
truelight
parents: 9643
diff changeset
   234
void AI_Event(PlayerID player, AIEvent *event) {}
9621
7654501cf02d (svn r9821) [NoAI] -Fix: support compilation without threads.
rubidium
parents: 9467
diff changeset
   235
void AI_Initialize() {}
7654501cf02d (svn r9821) [NoAI] -Fix: support compilation without threads.
rubidium
parents: 9467
diff changeset
   236
void AI_Uninitialize() {}
7654501cf02d (svn r9821) [NoAI] -Fix: support compilation without threads.
rubidium
parents: 9467
diff changeset
   237
bool AI_AllowNewAI() { return false; }
7654501cf02d (svn r9821) [NoAI] -Fix: support compilation without threads.
rubidium
parents: 9467
diff changeset
   238
void AI_ForceAI(const char *forced_ai) {}
10643
970417eef395 (svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents: 10455
diff changeset
   239
char *AI_GetConsoleList(char *p, const char *last) { return p; }
970417eef395 (svn r13187) [NoAI] -Codechange: rewrote the AI register part; C++ AIs are completely impossible now, and registration happens directly via AISquirrel. This cleans up the registration flow, and makes everything readable again, as sure I made a mess out of it :)
truebrain
parents: 10455
diff changeset
   240
AIInfo *AI_GetPlayerInfo(PlayerID player) { return NULL; }
10890
1d8f2baff829 (svn r13441) [NoAI] -Fix (r13440): NO_THREADS compilation
glx
parents: 10889
diff changeset
   241
bool AI_ImportLibrary(const char *library, const char *class_name, int version, HSQUIRRELVM vm) { return false; }
9621
7654501cf02d (svn r9821) [NoAI] -Fix: support compilation without threads.
rubidium
parents: 9467
diff changeset
   242
void CcAI(bool success, TileIndex tile, uint32 p1, uint32 p2) {}
10891
5ebb6f9068d0 (svn r13442) [NoAI] -Add: added 'rescan_ai' console command. Use it to rescan the ai dir when you add AIs or libraries without needing to exit and restart openttd.
glx
parents: 10890
diff changeset
   243
void AI_Rescan() {}
9621
7654501cf02d (svn r9821) [NoAI] -Fix: support compilation without threads.
rubidium
parents: 9467
diff changeset
   244
#endif /* NO_THREADS */