summaryrefslogtreecommitdiff
path: root/ai/trolly/build.c
diff options
context:
space:
mode:
authortron <tron@openttd.org>2006-06-04 09:10:24 +0000
committertron <tron@openttd.org>2006-06-04 09:10:24 +0000
commit877c7e34a52874eab1eb7e2a0ed15a007390d1df (patch)
tree7169789e49a59433f674337c2c7505ad5938e746 /ai/trolly/build.c
parent7dff47b7f09d0b9dfbaeaf2445d54075e83e5ed9 (diff)
downloadopenttd-877c7e34a52874eab1eb7e2a0ed15a007390d1df.tar.xz
(svn r5092) -Fix: There was a gross race condition in the AI code which made it pretty random if the AI could give a new vehicle its orders
Diffstat (limited to 'ai/trolly/build.c')
-rw-r--r--ai/trolly/build.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/ai/trolly/build.c b/ai/trolly/build.c
index 2b6342604..1f4324355 100644
--- a/ai/trolly/build.c
+++ b/ai/trolly/build.c
@@ -7,6 +7,7 @@
#include "../../map.h"
#include "../../road_map.h"
#include "../../tile.h"
+#include "../../vehicle.h"
#include "../../command.h"
#include "trolly.h"
#include "../../engine.h"
@@ -249,6 +250,20 @@ EngineID AiNew_PickVehicle(Player *p)
}
+void CcAI(bool success, TileIndex tile, uint32 p1, uint32 p2)
+{
+ Player* p = GetPlayer(_current_player);
+
+ if (success) {
+ p->ainew.state = AI_STATE_GIVE_ORDERS;
+ p->ainew.veh_id = _new_vehicle_id;
+ } else {
+ /* XXX this should be handled more gracefully */
+ p->ainew.state = AI_STATE_NOTHING;
+ }
+}
+
+
// Builds the best vehicle possible
int AiNew_Build_Vehicle(Player *p, TileIndex tile, byte flag)
{
@@ -257,7 +272,11 @@ int AiNew_Build_Vehicle(Player *p, TileIndex tile, byte flag)
if (i == INVALID_ENGINE) return CMD_ERROR;
if (p->ainew.tbt == AI_TRAIN) return CMD_ERROR;
- return AI_DoCommand(tile, i, 0, flag, CMD_BUILD_ROAD_VEH);
+ if (flag & DC_EXEC) {
+ return AI_DoCommandCc(tile, i, 0, flag, CMD_BUILD_ROAD_VEH, CcAI);
+ } else {
+ return AI_DoCommand(tile, i, 0, flag, CMD_BUILD_ROAD_VEH);
+ }
}
int AiNew_Build_Depot(Player* p, TileIndex tile, DiagDirection direction, byte flag)