summaryrefslogtreecommitdiff
path: root/ai_shared.c
diff options
context:
space:
mode:
authortruelight <truelight@openttd.org>2004-08-31 16:12:52 +0000
committertruelight <truelight@openttd.org>2004-08-31 16:12:52 +0000
commit5eba928cb8afb98d25d8145b8f026e0de199d875 (patch)
treeb97b894f85152a05546c2ecb614f2488d094de11 /ai_shared.c
parenta7dd461672f1802054c1e879dc1250bfcaac464f (diff)
downloadopenttd-5eba928cb8afb98d25d8145b8f026e0de199d875.tar.xz
(svn r146) -Fix [AI]: Tunnel/bridge bug
-Fix [AI]: Minor problems -Add [AI]: Profit check (if not making enough money, vehicles are sold)
Diffstat (limited to 'ai_shared.c')
-rw-r--r--ai_shared.c39
1 files changed, 37 insertions, 2 deletions
diff --git a/ai_shared.c b/ai_shared.c
index 3e2c4a930..9e7edaad0 100644
--- a/ai_shared.c
+++ b/ai_shared.c
@@ -1,7 +1,7 @@
#include "stdafx.h"
#include "ttd.h"
-#include "player.h"
#include "ai.h"
+#include "vehicle.h"
int AiNew_GetRailDirection(uint tile_a, uint tile_b, uint tile_c) {
// 0 = vert
@@ -79,4 +79,39 @@ int AiNew_GetDirection(uint tile_a, uint tile_b) {
if (GET_TILE_X(tile_a) < GET_TILE_X(tile_b)) return 2;
return 0;
}
-
+
+// This functions looks up if this vehicle is special for this AI
+// and returns his flag
+uint AiNew_GetSpecialVehicleFlag(Player *p, Vehicle *v) {
+ int i;
+ for (i=0;i<AI_MAX_SPECIAL_VEHICLES;i++) {
+ if (p->ainew.special_vehicles[i].veh_id == v->index) {
+ return p->ainew.special_vehicles[i].flag;
+ }
+ }
+
+ // Not found :(
+ return 0;
+}
+
+bool AiNew_SetSpecialVehicleFlag(Player *p, Vehicle *v, uint flag) {
+ int i, new_id = -1;
+ for (i=0;i<AI_MAX_SPECIAL_VEHICLES;i++) {
+ if (p->ainew.special_vehicles[i].veh_id == v->index) {
+ p->ainew.special_vehicles[i].flag |= flag;
+ return true;
+ }
+ if (new_id == -1 && p->ainew.special_vehicles[i].veh_id == 0 &&
+ p->ainew.special_vehicles[i].flag == 0)
+ new_id = i;
+ }
+
+ // Out of special_vehicle spots :s
+ if (new_id == -1) {
+ DEBUG(ai, 1)("special_vehicles list is too small :(");
+ return false;
+ }
+ p->ainew.special_vehicles[new_id].veh_id = v->index;
+ p->ainew.special_vehicles[new_id].flag = flag;
+ return true;
+}