mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-01-31 03:12:41 +00:00
(svn r3313) Remove GPMI related changes from trunk
Revisions in detail: 2542, 3226 (partial), 3229, 3231, 3232, 3238, 3242-3245, 3251, 3253, 3260, 3263, 3265, 3266, 3269, 3277, 3278, 3279, 3283 (partial), 3304, 3305, 3306
This commit is contained in:
parent
2956b119b2
commit
b06b3e2ca2
9
Makefile
9
Makefile
@ -372,15 +372,6 @@ endif
|
||||
|
||||
CFLAGS += $(BASECFLAGS)
|
||||
|
||||
# See if we want to enable GPMI
|
||||
ifdef GPMI
|
||||
CFLAGS += -DGPMI `gpmi-config --include`
|
||||
GPMI_STATIC_PATH = `gpmi-config --static`
|
||||
LDFLAGS += -rdynamic `gpmi-config --libs`
|
||||
# Static link paths into the game
|
||||
LDFLAGS += $(GPMI_STATIC_PATH)/paths-static.o
|
||||
endif
|
||||
|
||||
ifdef UNIX
|
||||
CDEFS += -DUNIX
|
||||
endif
|
||||
|
272
ai/ai.c
272
ai/ai.c
@ -5,22 +5,8 @@
|
||||
#include "../variables.h"
|
||||
#include "../command.h"
|
||||
#include "../network.h"
|
||||
#include "../debug.h"
|
||||
#include "ai.h"
|
||||
#include "default/default.h"
|
||||
#include "../string.h"
|
||||
|
||||
/* Here we define the events */
|
||||
#define DEF_EVENTS
|
||||
#include "ai_event.h"
|
||||
#undef DEF_EVENTS
|
||||
|
||||
/* Here we keep track of all commands that are called via AI_DoCommandChecked,
|
||||
* in special we save the unique_id here. Now this id is given back
|
||||
* when the command fails or succeeds and is detected as added in this storage. */
|
||||
static AICommand *command_uid[MAX_PLAYERS];
|
||||
static AICommand *command_uid_tail[MAX_PLAYERS];
|
||||
static uint uids[MAX_PLAYERS];
|
||||
|
||||
/**
|
||||
* Dequeues commands put in the queue via AI_PutCommandInQueue.
|
||||
@ -153,123 +139,23 @@ int32 AI_DoCommand(uint tile, uint32 p1, uint32 p2, uint32 flags, uint procc)
|
||||
return res;
|
||||
}
|
||||
|
||||
int32 AI_DoCommandChecked(uint tile, uint32 p1, uint32 p2, uint32 flags, uint procc)
|
||||
{
|
||||
AICommand *new;
|
||||
uint unique_id = uids[_current_player] + 1; // + 1, because 0 is reserved
|
||||
int32 res;
|
||||
|
||||
res = DoCommandByTile(tile, p1, p2, flags & ~DC_EXEC, procc);
|
||||
if (CmdFailed(res))
|
||||
return CMD_ERROR;
|
||||
if (!(flags & DC_EXEC))
|
||||
return res;
|
||||
|
||||
uids[_current_player]++;
|
||||
|
||||
/* Save the command and his things, together with the unique_id */
|
||||
new = malloc(sizeof(AICommand));
|
||||
new->tile = tile;
|
||||
new->p1 = p1;
|
||||
new->p2 = p2;
|
||||
new->procc = procc;
|
||||
new->next = NULL;
|
||||
new->uid = unique_id;
|
||||
|
||||
/* Add it to the back of the list */
|
||||
if (command_uid_tail[_current_player] == NULL)
|
||||
command_uid_tail[_current_player] = new;
|
||||
else {
|
||||
command_uid_tail[_current_player]->next = new;
|
||||
command_uid_tail[_current_player] = new;
|
||||
}
|
||||
|
||||
if (command_uid[_current_player] == NULL)
|
||||
command_uid[_current_player] = new;
|
||||
|
||||
AI_DoCommand(tile, p1, p2, flags, procc);
|
||||
return unique_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the right UID for this command.
|
||||
*/
|
||||
void AI_GetCommandUID(uint32 cmd, uint32 p1, uint32 p2, TileIndex tile)
|
||||
{
|
||||
AICommand *command = command_uid[_current_player];
|
||||
|
||||
/* Reset to 0, meaning no UID. Then we start detecting if we have an UID for this command */
|
||||
_ai_current_uid = 0;
|
||||
_ai_current_tile = INVALID_TILE;
|
||||
|
||||
if (command == NULL)
|
||||
return;
|
||||
|
||||
if (command->procc != (cmd & 0xFF) || command->p1 != p1 || command->p2 != p2 || command->tile != tile) {
|
||||
/* If we come here, we see a command that isn't at top in our list. This is okay, if the command isn't
|
||||
* anywhere else in our list, else we have a big problem.. so check for that. If it isn't in our list,
|
||||
* it is okay, else, drop the game.
|
||||
* Why do we have a big problem in the case it is in our list? Simply, we have a command sooner in
|
||||
* our list that wasn't triggered to be failed or succeeded, so it is sitting there without an
|
||||
* event, so the script will never know if it succeeded yes/no, so it can hang.. this is VERY bad
|
||||
* and should never ever happen. */
|
||||
while (command != NULL && (command->procc != (cmd & 0xFF) || command->p1 != p1 || command->p2 != p2 || command->tile != tile)) {
|
||||
command = command->next;
|
||||
}
|
||||
assert(command == NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Remove this command from the list */
|
||||
command_uid[_current_player] = command_uid[_current_player]->next;
|
||||
if (command_uid[_current_player] == NULL)
|
||||
command_uid_tail[_current_player] = NULL;
|
||||
|
||||
/* Broadcast our current UID and tile */
|
||||
_ai_current_uid = command->uid;
|
||||
_ai_current_tile = tile;
|
||||
free(command);
|
||||
}
|
||||
|
||||
/**
|
||||
* A command is executed for real, and is giving us his result (failed yes/no). Inform the AI with it via
|
||||
* an event.
|
||||
*/
|
||||
void AI_CommandResult(bool succeeded)
|
||||
{
|
||||
if (_ai_current_uid == 0)
|
||||
return;
|
||||
|
||||
ai_event(_current_player, succeeded ? ttai_Event_CommandSucceeded : ttai_Event_CommandFailed, _ai_current_tile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run 1 tick of the AI. Don't overdo it, keep it realistic.
|
||||
*/
|
||||
static void AI_RunTick(PlayerID player)
|
||||
{
|
||||
extern void AiNewDoGameLoop(Player *p);
|
||||
|
||||
Player *p = GetPlayer(player);
|
||||
_current_player = player;
|
||||
|
||||
#ifdef GPMI
|
||||
if (_ai.gpmi) {
|
||||
gpmi_call_RunTick(_ai_player[player].module, _frame_counter);
|
||||
return;
|
||||
}
|
||||
#endif /* GPMI */
|
||||
|
||||
{
|
||||
extern void AiNewDoGameLoop(Player *p);
|
||||
|
||||
Player *p = GetPlayer(player);
|
||||
|
||||
if (_patches.ainew_active) {
|
||||
AiNewDoGameLoop(p);
|
||||
} else {
|
||||
/* Enable all kind of cheats the old AI needs in order to operate correctly... */
|
||||
_is_old_ai_player = true;
|
||||
AiDoGameLoop(p);
|
||||
_is_old_ai_player = false;
|
||||
}
|
||||
if (_patches.ainew_active) {
|
||||
AiNewDoGameLoop(p);
|
||||
} else {
|
||||
/* Enable all kind of cheats the old AI needs in order to operate correctly... */
|
||||
_is_old_ai_player = true;
|
||||
AiDoGameLoop(p);
|
||||
_is_old_ai_player = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -309,7 +195,10 @@ void AI_RunGameLoop(void)
|
||||
Player *p;
|
||||
|
||||
FOR_ALL_PLAYERS(p) {
|
||||
if (p->is_active && p->is_ai && _ai_player[p->index].active) {
|
||||
if (p->is_active && p->is_ai) {
|
||||
/* This should always be true, else something went wrong... */
|
||||
assert(_ai_player[p->index].active);
|
||||
|
||||
/* Run the script */
|
||||
AI_DequeueCommands(p->index);
|
||||
AI_RunTick(p->index);
|
||||
@ -320,61 +209,6 @@ void AI_RunGameLoop(void)
|
||||
_current_player = OWNER_NONE;
|
||||
}
|
||||
|
||||
#ifdef GPMI
|
||||
|
||||
void AI_ShutdownAIControl(bool with_error)
|
||||
{
|
||||
if (_ai.gpmi_mod != NULL)
|
||||
gpmi_mod_unload(_ai.gpmi_mod);
|
||||
if (_ai.gpmi_pkg != NULL)
|
||||
gpmi_pkg_unload(_ai.gpmi_pkg);
|
||||
|
||||
if (with_error) {
|
||||
DEBUG(ai, 0)("[AI] Failed to load AI Control, switching back to built-in AIs..");
|
||||
_ai.gpmi = false;
|
||||
}
|
||||
}
|
||||
|
||||
void (*ttai_GetNextAIData)(char **library, char **param);
|
||||
void (*ttai_SetAIParam)(char *param);
|
||||
|
||||
void AI_LoadAIControl(void)
|
||||
{
|
||||
/* Load module */
|
||||
_ai.gpmi_mod = gpmi_mod_load("ttai_control_mod", NULL);
|
||||
if (_ai.gpmi_mod == NULL) {
|
||||
AI_ShutdownAIControl(true);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Load package */
|
||||
if (gpmi_pkg_load("ttai_control_pkg", 0, NULL, NULL, &_ai.gpmi_pkg)) {
|
||||
AI_ShutdownAIControl(true);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Now link all the functions */
|
||||
{
|
||||
ttai_GetNextAIData = gpmi_pkg_resolve(_ai.gpmi_pkg, "ttai_GetNextAIData");
|
||||
ttai_SetAIParam = gpmi_pkg_resolve(_ai.gpmi_pkg, "ttai_SetAIParam");
|
||||
|
||||
if (ttai_GetNextAIData == NULL || ttai_SetAIParam == NULL)
|
||||
AI_ShutdownAIControl(true);
|
||||
}
|
||||
|
||||
ttai_SetAIParam(_ai.gpmi_param);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dump an entry of the GPMI error stack (callback routine). This helps the user to trace errors back to their roots.
|
||||
*/
|
||||
void AI_PrintErrorStack(gpmi_err_stack_t *entry, char *string)
|
||||
{
|
||||
DEBUG(ai, 0)("%s", string);
|
||||
}
|
||||
|
||||
#endif /* GPMI */
|
||||
|
||||
/**
|
||||
* A new AI sees the day of light. You can do here what ever you think is needed.
|
||||
*/
|
||||
@ -382,44 +216,6 @@ void AI_StartNewAI(PlayerID player)
|
||||
{
|
||||
assert(player < MAX_PLAYERS);
|
||||
|
||||
#ifdef GPMI
|
||||
/* Keep this in a different IF, because the function can turn _ai.gpmi off!! */
|
||||
if (_ai.gpmi && _ai.gpmi_mod == NULL)
|
||||
AI_LoadAIControl();
|
||||
|
||||
if (_ai.gpmi) {
|
||||
char *library = NULL;
|
||||
char *params = NULL;
|
||||
int old_cp = _current_player;
|
||||
|
||||
/* Switch to new player, so we can execute stuff */
|
||||
_current_player = player;
|
||||
|
||||
/* Get the library and param to load */
|
||||
ttai_GetNextAIData(&library, ¶ms);
|
||||
gpmi_error_stack_enable = 1;
|
||||
|
||||
/* Load the module */
|
||||
if (library != NULL) {
|
||||
_ai_player[player].module = gpmi_mod_load(library, params);
|
||||
free(library);
|
||||
}
|
||||
if (params != NULL)
|
||||
free(params);
|
||||
|
||||
/* Check for errors */
|
||||
if (_ai_player[player].module == NULL) {
|
||||
DEBUG(ai, 0)("[AI] Failed to load AI, aborting. GPMI error stack:");
|
||||
gpmi_err_stack_process_str(AI_PrintErrorStack);
|
||||
return;
|
||||
}
|
||||
gpmi_error_stack_enable = 0;
|
||||
|
||||
/* Switch back to last player */
|
||||
_current_player = old_cp;
|
||||
}
|
||||
#endif /* GPMI */
|
||||
|
||||
/* Called if a new AI is booted */
|
||||
_ai_player[player].active = true;
|
||||
}
|
||||
@ -434,22 +230,6 @@ void AI_PlayerDied(PlayerID player)
|
||||
|
||||
/* Called if this AI died */
|
||||
_ai_player[player].active = false;
|
||||
|
||||
if (command_uid[player] != NULL) {
|
||||
while (command_uid[player] != NULL) {
|
||||
AICommand *command = command_uid[player];
|
||||
command_uid[player] = command->next;
|
||||
free(command);
|
||||
}
|
||||
|
||||
command_uid[player] = NULL;
|
||||
command_uid_tail[player] = NULL;
|
||||
}
|
||||
|
||||
#ifdef GPMI
|
||||
if (_ai_player[player].module != NULL)
|
||||
gpmi_mod_unload(_ai_player[player].module);
|
||||
#endif /* GPMI */
|
||||
}
|
||||
|
||||
/**
|
||||
@ -457,29 +237,17 @@ void AI_PlayerDied(PlayerID player)
|
||||
*/
|
||||
void AI_Initialize(void)
|
||||
{
|
||||
bool tmp_ai_network_client = _ai.network_client;
|
||||
bool tmp_ai_gpmi = _ai.gpmi;
|
||||
#ifdef GPMI
|
||||
char *tmp_ai_gpmi_param = strdup(_ai.gpmi_param);
|
||||
#endif /* GPMI */
|
||||
bool ai_network_client = _ai.network_client;
|
||||
|
||||
/* First, make sure all AIs are DEAD! */
|
||||
AI_Uninitialize();
|
||||
|
||||
memset(&_ai, 0, sizeof(_ai));
|
||||
memset(_ai_player, 0, sizeof(_ai_player));
|
||||
memset(uids, 0, sizeof(uids));
|
||||
memset(command_uid, 0, sizeof(command_uid));
|
||||
memset(command_uid_tail, 0, sizeof(command_uid_tail));
|
||||
memset(&_ai_player, 0, sizeof(_ai_player));
|
||||
|
||||
_ai.network_client = tmp_ai_network_client;
|
||||
_ai.network_client = ai_network_client;
|
||||
_ai.network_playas = OWNER_SPECTATOR;
|
||||
_ai.enabled = true;
|
||||
_ai.gpmi = tmp_ai_gpmi;
|
||||
#ifdef GPMI
|
||||
ttd_strlcpy(_ai.gpmi_param, tmp_ai_gpmi_param, sizeof(_ai.gpmi_param));
|
||||
free(tmp_ai_gpmi_param);
|
||||
#endif /* GPMI */
|
||||
}
|
||||
|
||||
/**
|
||||
@ -490,10 +258,6 @@ void AI_Uninitialize(void)
|
||||
Player* p;
|
||||
|
||||
FOR_ALL_PLAYERS(p) {
|
||||
if (p->is_active && p->is_ai && _ai_player[p->index].active) AI_PlayerDied(p->index);
|
||||
if (p->is_active && p->is_ai) AI_PlayerDied(p->index);
|
||||
}
|
||||
|
||||
#ifdef GPMI
|
||||
AI_ShutdownAIControl(false);
|
||||
#endif /* GPMI */
|
||||
}
|
||||
|
20
ai/ai.h
20
ai/ai.h
@ -4,9 +4,6 @@
|
||||
#include "../functions.h"
|
||||
#include "../network.h"
|
||||
#include "../player.h"
|
||||
#ifdef GPMI
|
||||
#include <gpmi.h>
|
||||
#endif /* GPMI */
|
||||
|
||||
/* How DoCommands look like for an AI */
|
||||
typedef struct AICommand {
|
||||
@ -26,9 +23,6 @@ typedef struct AIPlayer {
|
||||
bool active; //! Is this AI active?
|
||||
AICommand *queue; //! The commands that he has in his queue
|
||||
AICommand *queue_tail; //! The tail of this queue
|
||||
#ifdef GPMI
|
||||
gpmi_module *module; //! The link to the GPMI module
|
||||
#endif /* GPMI */
|
||||
} AIPlayer;
|
||||
|
||||
/* The struct to keep some data about the AI in general */
|
||||
@ -40,19 +34,10 @@ typedef struct AIStruct {
|
||||
/* For network-clients (a OpenTTD client who acts as an AI connected to a server) */
|
||||
bool network_client; //! Are we a network_client?
|
||||
uint8 network_playas; //! The current network player we are connected as
|
||||
|
||||
bool gpmi; //! True if we want GPMI AIs
|
||||
#ifdef GPMI
|
||||
gpmi_module *gpmi_mod; //! The module controller for GPMI based AIs (Event-handling)
|
||||
gpmi_package *gpmi_pkg; //! The package controller for GPMI based AIs (Functions)
|
||||
char gpmi_param[128]; //! The params given to the gpmi_mod
|
||||
#endif /* GPMI */
|
||||
} AIStruct;
|
||||
|
||||
VARDEF AIStruct _ai;
|
||||
VARDEF AIPlayer _ai_player[MAX_PLAYERS];
|
||||
VARDEF uint _ai_current_uid; //! Keeps track of the current UID, if any (0 means none)
|
||||
VARDEF TileIndex _ai_current_tile; //! Keeps track of the current Tile.
|
||||
|
||||
// ai.c
|
||||
void AI_StartNewAI(PlayerID player);
|
||||
@ -61,9 +46,6 @@ void AI_RunGameLoop(void);
|
||||
void AI_Initialize(void);
|
||||
void AI_Uninitialize(void);
|
||||
int32 AI_DoCommand(uint tile, uint32 p1, uint32 p2, uint32 flags, uint procc);
|
||||
int32 AI_DoCommandChecked(uint tile, uint32 p1, uint32 p2, uint32 flags, uint procc);
|
||||
void AI_GetCommandUID(uint32 cmd, uint32 p1, uint32 p2, TileIndex tile);
|
||||
void AI_CommandResult(bool failed);
|
||||
|
||||
/** Is it allowed to start a new AI.
|
||||
* This function checks some boundries to see if we should launch a new AI.
|
||||
@ -89,7 +71,7 @@ static inline bool AI_AllowNewAI(void)
|
||||
* system, because all commands are delayed by at least 1 tick, which causes
|
||||
* a big problem, because it uses variables that are only set AFTER the command
|
||||
* is really executed... */
|
||||
if (!_patches.ainew_active && !_ai.gpmi)
|
||||
if (!_patches.ainew_active)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1,64 +0,0 @@
|
||||
#ifndef AI_EVENT
|
||||
#define AI_EVENT
|
||||
|
||||
/* Make the ai_event macro set correctly */
|
||||
#ifdef GPMI
|
||||
# include <gpmi.h>
|
||||
# include "ai.h"
|
||||
|
||||
/* This is how we call events (with safety-check) to GPMI */
|
||||
/* XXX -- This macro works only for some compilers (all GCCs for example).
|
||||
* Some compilers on the other hand (MSCV!!) doesn't support variadic macros
|
||||
* causing this to fail. There is no known solution. If you know any, please
|
||||
* tell us ASAP! */
|
||||
# define ai_event(player, event, ...) \
|
||||
if ((player) < MAX_PLAYERS && _ai_player[(player)].module != NULL) \
|
||||
gpmi_event(_ai_player[(player)].module, (event), _ai_current_uid, ##__VA_ARGS__)
|
||||
|
||||
#else /* GPMI */
|
||||
|
||||
/* XXX -- Some compilers (like MSVC :() doesn't support variadic macros,
|
||||
* which means we have to go to a lot of trouble to get the ai_event() ignored
|
||||
* in case GPMI is disabled... KILL KILL KILL!
|
||||
*/
|
||||
# ifdef DEF_EVENTS
|
||||
void CDECL empty_function(PlayerID player, int event, ...) {}
|
||||
# else
|
||||
extern void CDECL empty_function(PlayerID player, int event, ...);
|
||||
# endif
|
||||
# define ai_event empty_function
|
||||
#endif /* GPMI */
|
||||
|
||||
/* To make our life a bit easier; you now only have to define new
|
||||
* events here, and automaticly they work in OpenTTD without including
|
||||
* the ttai_event package. Just because of some lovely macro-shit ;) */
|
||||
#ifdef DEF_EVENTS
|
||||
# define DEF_EVENTS
|
||||
# define INITIAL_SET = -1
|
||||
#else
|
||||
# define DEF_EVENTS extern
|
||||
# define INITIAL_SET
|
||||
#endif /* DEF_EVENTS */
|
||||
|
||||
/* ------------ All available events -------------- */
|
||||
DEF_EVENTS int ttai_Event_CommandFailed INITIAL_SET; // (tile, unique_id)
|
||||
DEF_EVENTS int ttai_Event_CommandSucceeded INITIAL_SET; // (tile, unique_id)
|
||||
|
||||
DEF_EVENTS int ttai_Event_BuildStation INITIAL_SET; // (station_index, station_tile)
|
||||
DEF_EVENTS int ttai_Event_BuildRoadStation INITIAL_SET; // (station_index, station_tile)
|
||||
|
||||
DEF_EVENTS int ttai_Event_BuildDepot INITIAL_SET; // (depot_index, depot_tile)
|
||||
DEF_EVENTS int ttai_Event_BuildRoadDepot INITIAL_SET; // (depot_index, depot_tile)
|
||||
|
||||
DEF_EVENTS int ttai_Event_BuildVehicle INITIAL_SET; // (vehicle_index, depot_tile)
|
||||
DEF_EVENTS int ttai_Event_BuildRoadVehicle INITIAL_SET; // (vehicle_index, depot_tile)
|
||||
|
||||
DEF_EVENTS int ttai_Event_VehicleEnterDepot INITIAL_SET; // (vehicle_index, depot_tile)
|
||||
DEF_EVENTS int ttai_Event_RoadVehicleEnterDepot INITIAL_SET; // (vehicle_index, depot_tile)
|
||||
|
||||
DEF_EVENTS int ttai_Event_GiveOrder INITIAL_SET; // (vehicle_index)
|
||||
|
||||
DEF_EVENTS int ttai_Event_BuildRoad INITIAL_SET; // (road_tile, road_pieces)
|
||||
/* ----------------- End of list ------------------ */
|
||||
|
||||
#endif /* AI_EVENT */
|
14
command.c
14
command.c
@ -10,7 +10,6 @@
|
||||
#include "player.h"
|
||||
#include "network.h"
|
||||
#include "variables.h"
|
||||
#include "ai/ai.h"
|
||||
|
||||
const char* _cmd_text = NULL;
|
||||
|
||||
@ -403,8 +402,6 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback,
|
||||
int x = TileX(tile) * 16;
|
||||
int y = TileY(tile) * 16;
|
||||
|
||||
AI_GetCommandUID(cmd, p1, p2, tile);
|
||||
|
||||
/* Do not even think about executing out-of-bounds tile-commands */
|
||||
if (tile > MapSize()) {
|
||||
_cmd_text = NULL;
|
||||
@ -477,16 +474,10 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback,
|
||||
res = proc(x,y, flags, p1, p2);
|
||||
if (CmdFailed(res)) {
|
||||
if (res & 0xFFFF) _error_message = res & 0xFFFF;
|
||||
/* Trigger an event special for the AI, so it knows the build has failed
|
||||
* Because the commands are always delayed, this is the only way. */
|
||||
AI_CommandResult(false);
|
||||
goto show_error;
|
||||
}
|
||||
// no money? Only check if notest is off
|
||||
if (!notest && res != 0 && !CheckPlayerHasMoney(res)) {
|
||||
AI_CommandResult(false);
|
||||
goto show_error;
|
||||
}
|
||||
if (!notest && res != 0 && !CheckPlayerHasMoney(res)) goto show_error;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_NETWORK
|
||||
@ -521,13 +512,10 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback,
|
||||
} else {
|
||||
if (CmdFailed(res2)) {
|
||||
if (res2 & 0xFFFF) _error_message = res2 & 0xFFFF;
|
||||
AI_CommandResult(false);
|
||||
goto show_error;
|
||||
}
|
||||
}
|
||||
|
||||
AI_CommandResult(true);
|
||||
|
||||
SubtractMoneyFromPlayer(res2);
|
||||
|
||||
if (IsLocalPlayer() && _game_mode != GM_EDITOR) {
|
||||
|
13
debug.c
13
debug.c
@ -20,9 +20,6 @@ int _debug_spritecache_level;
|
||||
int _debug_oldloader_level;
|
||||
int _debug_pbs_level;
|
||||
int _debug_ntp_level;
|
||||
#ifdef GPMI
|
||||
int _debug_gpmi_level;
|
||||
#endif /* GPMI */
|
||||
int _debug_npf_level;
|
||||
|
||||
|
||||
@ -56,9 +53,6 @@ typedef struct DebugLevel {
|
||||
DEBUG_LEVEL(oldloader),
|
||||
DEBUG_LEVEL(pbs),
|
||||
DEBUG_LEVEL(ntp),
|
||||
#ifdef GPMI
|
||||
DEBUG_LEVEL(gpmi),
|
||||
#endif
|
||||
DEBUG_LEVEL(npf)
|
||||
};
|
||||
#undef DEBUG_LEVEL
|
||||
@ -132,10 +126,3 @@ const char *GetDebugString(void)
|
||||
|
||||
return dbgstr;
|
||||
}
|
||||
|
||||
#ifdef GPMI
|
||||
void gpmi_debug_openttd(int level, char *s)
|
||||
{
|
||||
DEBUG(gpmi, level)("[GPMI] %s", s);
|
||||
}
|
||||
#endif /* GPMI */
|
||||
|
7
debug.h
7
debug.h
@ -19,9 +19,6 @@
|
||||
extern int _debug_oldloader_level;
|
||||
extern int _debug_pbs_level;
|
||||
extern int _debug_ntp_level;
|
||||
#ifdef GPMI
|
||||
extern int _debug_gpmi_level;
|
||||
#endif /* GPMI */
|
||||
extern int _debug_npf_level;
|
||||
#endif
|
||||
|
||||
@ -30,8 +27,4 @@ void CDECL debug(const char *s, ...);
|
||||
void SetDebugString(const char *s);
|
||||
const char *GetDebugString(void);
|
||||
|
||||
#ifdef GPMI
|
||||
void gpmi_debug_openttd(int level, char *s);
|
||||
#endif /* GPMI */
|
||||
|
||||
#endif /* DEBUG_H */
|
||||
|
@ -1012,7 +1012,6 @@ STR_CONFIG_PATCHES_AI_BUILDS_SHIPS :{LTBLUE}Disable
|
||||
|
||||
STR_CONFIG_PATCHES_AINEW_ACTIVE :{LTBLUE}Enable new AI (alpha): {ORANGE}{STRING1}
|
||||
STR_CONFIG_PATCHES_AI_IN_MULTIPLAYER :{LTBLUE}Allow AIs in multiplayer (experimental): {ORANGE}{STRING1}
|
||||
STR_CONFIG_PATCHES_AI_GPMI :{LTBLUE}Enable GPMI-driven AIs: {ORANGE}{STRING1}
|
||||
|
||||
STR_CONFIG_PATCHES_SERVINT_TRAINS :{LTBLUE}Default service interval for trains: {ORANGE}{STRING1} days/%
|
||||
STR_CONFIG_PATCHES_SERVINT_TRAINS_DISABLED :{LTBLUE}Default service interval for trains: {ORANGE}disabled
|
||||
|
@ -32,7 +32,6 @@ $(MAKE_CONFIG):
|
||||
$(call CONFIG_LINE,WITH_NETWORK:=$(WITH_NETWORK))
|
||||
$(call CONFIG_LINE,DEDICATED:=$(DEDICATED))
|
||||
$(call CONFIG_LINE,MAX_NUM_AUTOSAVES:=$(MAX_NUM_AUTOSAVES))
|
||||
$(call CONFIG_LINE,GPMI:=$(GPMI))
|
||||
$(call CONFIG_LINE,)
|
||||
|
||||
$(call CONFIG_LINE,\# Disable asserts. Leave them on for easier bug finding)
|
||||
|
@ -13,7 +13,6 @@
|
||||
#include "economy.h"
|
||||
#include "network.h"
|
||||
#include "variables.h"
|
||||
#include "ai/ai.h"
|
||||
|
||||
/** Change the player's face.
|
||||
* @param x,y unused
|
||||
@ -76,7 +75,7 @@ int32 CmdIncreaseLoan(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
/* Loan the maximum amount or not? */
|
||||
int32 loan = (p2) ? _economy.max_loan - p->current_loan : (IS_HUMAN_PLAYER(_current_player) || _patches.ainew_active || _ai.gpmi) ? 10000 : 50000;
|
||||
int32 loan = (p2) ? _economy.max_loan - p->current_loan : (IS_HUMAN_PLAYER(_current_player) || _patches.ainew_active) ? 10000 : 50000;
|
||||
|
||||
p->money64 += loan;
|
||||
p->current_loan += loan;
|
||||
@ -110,7 +109,7 @@ int32 CmdDecreaseLoan(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||
loan = max(loan, 10000);
|
||||
loan -= loan % 10000;
|
||||
} else {
|
||||
loan = min(loan, (IS_HUMAN_PLAYER(_current_player) || _patches.ainew_active || _ai.gpmi) ? 10000 : 50000);
|
||||
loan = min(loan, (IS_HUMAN_PLAYER(_current_player) || _patches.ainew_active) ? 10000 : 50000);
|
||||
}
|
||||
|
||||
if (p->player_money < loan) {
|
||||
|
37
openttd.c
37
openttd.c
@ -43,11 +43,6 @@
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#ifdef GPMI
|
||||
#include <gpmi.h>
|
||||
#include <gpmi_pkg/paths.h>
|
||||
#endif /* GPMI */
|
||||
|
||||
void GenerateWorld(int mode, uint size_x, uint size_y);
|
||||
void CallLandscapeTick(void);
|
||||
void IncreaseDate(void);
|
||||
@ -314,9 +309,6 @@ int ttd_main(int argc, char* argv[])
|
||||
uint startdate = -1;
|
||||
bool dedicated;
|
||||
|
||||
#ifdef GPMI
|
||||
_ai.gpmi_param[0] = 0;
|
||||
#endif /* GPMI */
|
||||
musicdriver[0] = sounddriver[0] = videodriver[0] = 0;
|
||||
|
||||
_game_mode = GM_MENU;
|
||||
@ -331,9 +323,9 @@ int ttd_main(int argc, char* argv[])
|
||||
// a ':' behind it means: it need a param (e.g.: -m<driver>)
|
||||
// a '::' behind it means: it can optional have a param (e.g.: -d<debug>)
|
||||
#if !defined(__MORPHOS__) && !defined(__AMIGA__) && !defined(WIN32)
|
||||
optformat = "a:bm:s:v:hDfn::eit:d::r:g::G:p:c:";
|
||||
optformat = "bm:s:v:hDfn::eit:d::r:g::G:p:c:";
|
||||
#else
|
||||
optformat = "a:bm:s:v:hDn::eit:d::r:g::G:p:c:"; // no fork option
|
||||
optformat = "bm:s:v:hDn::eit:d::r:g::G:p:c:"; // no fork option
|
||||
#endif
|
||||
|
||||
MyGetOptInit(&mgo, argc-1, argv+1, optformat);
|
||||
@ -359,11 +351,6 @@ int ttd_main(int argc, char* argv[])
|
||||
else
|
||||
network_conn = NULL;
|
||||
} break;
|
||||
#ifdef GPMI
|
||||
case 'a': ttd_strlcpy(_ai.gpmi_param, mgo.opt, sizeof(_ai.gpmi_param)); break;
|
||||
#else
|
||||
case 'a': DEBUG(misc, 0)("The -a option only works if GPMI is compiled with OpenTTD."); break;
|
||||
#endif /* GPMI */
|
||||
case 'b': _ai.network_client = true; break;
|
||||
case 'r': ParseResolution(resolution, mgo.opt); break;
|
||||
case 't': startdate = atoi(mgo.opt); break;
|
||||
@ -409,21 +396,6 @@ int ttd_main(int argc, char* argv[])
|
||||
DeterminePaths();
|
||||
CheckExternalFiles();
|
||||
|
||||
#ifdef GPMI
|
||||
/* Set the debug proc */
|
||||
gpmi_debug_proc = &gpmi_debug_openttd;
|
||||
|
||||
/* Set the script-path (GPMI doesn't support multiple paths, yet!) */
|
||||
gpmi_path_scripts = strdup("ai/scripts");
|
||||
|
||||
/* Initialize GPMI */
|
||||
gpmi_init();
|
||||
|
||||
/* Add our paths so we can find our own packages */
|
||||
gpmi_path_append(&gpmi_path_modules, "ai/modules");
|
||||
gpmi_path_append(&gpmi_path_packages, "ai/packages");
|
||||
#endif /* GPMI */
|
||||
|
||||
#if defined(UNIX) && !defined(__MORPHOS__)
|
||||
// We must fork here, or we'll end up without some resources we need (like sockets)
|
||||
if (_dedicated_forks)
|
||||
@ -545,11 +517,6 @@ int ttd_main(int argc, char* argv[])
|
||||
/* stop the AI */
|
||||
AI_Uninitialize();
|
||||
|
||||
#ifdef GPMI
|
||||
/* Uninitialize GPMI */
|
||||
gpmi_uninit();
|
||||
#endif /* GPMI */
|
||||
|
||||
/* Close all and any open filehandles */
|
||||
FioCloseAll();
|
||||
UnInitializeGame();
|
||||
|
@ -15,7 +15,6 @@
|
||||
#include "news.h"
|
||||
#include "saveload.h"
|
||||
#include "vehicle_gui.h"
|
||||
#include "ai/ai_event.h"
|
||||
|
||||
enum {
|
||||
/* Max orders: 64000 (64 * 1000) */
|
||||
@ -394,8 +393,6 @@ int32 CmdInsertOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||
|
||||
/* Make sure to rebuild the whole list */
|
||||
RebuildVehicleLists();
|
||||
|
||||
ai_event(_current_player, ttai_Event_GiveOrder, v->index);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -17,7 +17,6 @@
|
||||
#include "depot.h"
|
||||
#include "pbs.h"
|
||||
#include "debug.h"
|
||||
#include "ai/ai_event.h"
|
||||
|
||||
/* When true, GetTrackStatus for roads will treat roads under reconstruction
|
||||
* as normal roads instead of impassable. This is used when detecting whether
|
||||
@ -487,8 +486,6 @@ do_clear:;
|
||||
_m[tile].m5 |= pieces;
|
||||
|
||||
MarkTileDirtyByTile(tile);
|
||||
|
||||
ai_event(_current_player, ttai_Event_BuildRoad, tile, pieces);
|
||||
}
|
||||
return cost;
|
||||
}
|
||||
@ -674,8 +671,6 @@ int32 CmdBuildRoadDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||
(p1 | 0x20) /* map5 */
|
||||
);
|
||||
|
||||
ai_event(_current_player, ttai_Event_BuildDepot, dep->index, tile);
|
||||
ai_event(_current_player, ttai_Event_BuildRoadDepot, dep->index, tile);
|
||||
}
|
||||
return cost + _price.build_road_depot;
|
||||
}
|
||||
@ -1160,10 +1155,6 @@ static uint32 VehicleEnter_Road(Vehicle *v, TileIndex tile, int x, int y)
|
||||
if (v->type == VEH_Road && v->u.road.frame == 11) {
|
||||
if (_roadveh_enter_depot_unk0[GB(_m[tile].m5, 0, 2)] == v->u.road.state) {
|
||||
RoadVehEnterDepot(v);
|
||||
|
||||
ai_event(v->owner, ttai_Event_VehicleEnterDepot, v->index, tile);
|
||||
ai_event(v->owner, ttai_Event_RoadVehicleEnterDepot, v->index, tile);
|
||||
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,6 @@
|
||||
#include "sound.h"
|
||||
#include "depot.h"
|
||||
#include "vehicle_gui.h"
|
||||
#include "ai/ai_event.h"
|
||||
|
||||
void ShowRoadVehViewWindow(Vehicle *v);
|
||||
|
||||
@ -196,9 +195,6 @@ int32 CmdBuildRoadVeh(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||
InvalidateWindow(WC_COMPANY, v->owner);
|
||||
if (IsLocalPlayer())
|
||||
InvalidateWindow(WC_REPLACE_VEHICLE, VEH_Road); // updates the replace Road window
|
||||
|
||||
ai_event(_current_player, ttai_Event_BuildVehicle, v->index, tile);
|
||||
ai_event(_current_player, ttai_Event_BuildRoadVehicle, v->index, tile);
|
||||
}
|
||||
|
||||
return cost;
|
||||
|
@ -11,7 +11,6 @@
|
||||
#include "variables.h"
|
||||
#include "network.h"
|
||||
#include "settings.h"
|
||||
#include "ai/ai.h"
|
||||
|
||||
typedef struct IniFile IniFile;
|
||||
typedef struct IniItem IniItem;
|
||||
@ -944,7 +943,6 @@ const SettingDesc patch_settings[] = {
|
||||
|
||||
{"ainew_active", SDT_BOOL, (void*)false, &_patches.ainew_active, NULL},
|
||||
{"ai_in_multiplayer", SDT_BOOL, (void*)false, &_patches.ai_in_multiplayer, NULL},
|
||||
{"ai_gpmi", SDT_BOOL, (void*)true, &_ai.gpmi, NULL},
|
||||
|
||||
{"map_x", SDT_UINT32, (void*)8, &_patches.map_x, NULL},
|
||||
{"map_y", SDT_UINT32, (void*)8, &_patches.map_y, NULL},
|
||||
|
@ -19,7 +19,6 @@
|
||||
#include "console.h"
|
||||
#include "town.h"
|
||||
#include "variables.h"
|
||||
#include "ai/ai.h"
|
||||
|
||||
static uint32 _difficulty_click_a;
|
||||
static uint32 _difficulty_click_b;
|
||||
@ -761,7 +760,6 @@ static const PatchEntry _patches_economy[] = {
|
||||
static const PatchEntry _patches_ai[] = {
|
||||
{PE_BOOL, 0, STR_CONFIG_PATCHES_AINEW_ACTIVE, "ainew_active", &_patches.ainew_active, 0, 1, 1, &AiNew_PatchActive_Warning},
|
||||
{PE_BOOL, 0, STR_CONFIG_PATCHES_AI_IN_MULTIPLAYER, "ai_in_multiplayer", &_patches.ai_in_multiplayer, 0, 1, 1, &Ai_In_Multiplayer_Warning},
|
||||
{PE_BOOL, 0, STR_CONFIG_PATCHES_AI_GPMI, "ai_gpmi", &_ai.gpmi, 0, 1, 1, NULL},
|
||||
|
||||
{PE_BOOL, 0, STR_CONFIG_PATCHES_AI_BUILDS_TRAINS, "ai_disable_veh_train", &_patches.ai_disable_veh_train, 0, 0, 0, NULL},
|
||||
{PE_BOOL, 0, STR_CONFIG_PATCHES_AI_BUILDS_ROADVEH,"ai_disable_veh_roadveh",&_patches.ai_disable_veh_roadveh, 0, 0, 0, NULL},
|
||||
|
@ -27,7 +27,6 @@
|
||||
#include "depot.h"
|
||||
#include "pbs.h"
|
||||
#include "train.h"
|
||||
#include "ai/ai_event.h"
|
||||
|
||||
enum {
|
||||
/* Max stations: 64000 (64 * 1000) */
|
||||
@ -1464,9 +1463,6 @@ int32 CmdBuildRoadStop(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||
UpdateStationVirtCoordDirty(st);
|
||||
UpdateStationAcceptance(st, false);
|
||||
InvalidateWindow(WC_STATION_LIST, st->owner);
|
||||
|
||||
ai_event(_current_player, ttai_Event_BuildStation, st->index, tile);
|
||||
ai_event(_current_player, ttai_Event_BuildRoadStation, st->index, tile);
|
||||
}
|
||||
return cost;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user