1
/* $Id: shared.cpp 11818 2008-01-12 14:10:35Z rubidium $ */
3
#include "../../stdafx.h"
4
#include "../../openttd.h"
5
#include "../../debug.h"
6
#include "../../map_func.h"
7
#include "../../vehicle_base.h"
8
#include "../../player_base.h"
11
int AiNew_GetRailDirection(TileIndex tile_a, TileIndex tile_b, TileIndex tile_c)
20
uint x1 = TileX(tile_a);
21
uint x2 = TileX(tile_b);
22
uint x3 = TileX(tile_c);
24
uint y1 = TileY(tile_a);
25
uint y2 = TileY(tile_b);
26
uint y3 = TileY(tile_c);
28
if (y1 == y2 && y2 == y3) return 0;
29
if (x1 == x2 && x2 == x3) return 1;
30
if (y2 > y1) return x2 > x3 ? 2 : 4;
31
if (x2 > x1) return y2 > y3 ? 2 : 5;
32
if (y1 > y2) return x2 > x3 ? 5 : 3;
33
if (x1 > x2) return y2 > y3 ? 4 : 3;
38
int AiNew_GetRoadDirection(TileIndex tile_a, TileIndex tile_b, TileIndex tile_c)
67
// Get's the direction between 2 tiles seen from tile_a
68
DiagDirection AiNew_GetDirection(TileIndex tile_a, TileIndex tile_b)
70
if (TileY(tile_a) < TileY(tile_b)) return DIAGDIR_SE;
71
if (TileY(tile_a) > TileY(tile_b)) return DIAGDIR_NW;
72
if (TileX(tile_a) < TileX(tile_b)) return DIAGDIR_SW;
77
// This functions looks up if this vehicle is special for this AI
78
// and returns his flag
79
uint AiNew_GetSpecialVehicleFlag(Player* p, Vehicle* v)
83
for (i = 0; i < AI_MAX_SPECIAL_VEHICLES; i++) {
84
if (_players_ainew[p->index].special_vehicles[i].veh_id == v->index) {
85
return _players_ainew[p->index].special_vehicles[i].flag;
94
bool AiNew_SetSpecialVehicleFlag(Player* p, Vehicle* v, uint flag)
99
for (i = 0; i < AI_MAX_SPECIAL_VEHICLES; i++) {
100
if (_players_ainew[p->index].special_vehicles[i].veh_id == v->index) {
101
_players_ainew[p->index].special_vehicles[i].flag |= flag;
105
_players_ainew[p->index].special_vehicles[i].veh_id == 0 &&
106
_players_ainew[p->index].special_vehicles[i].flag == 0) {
111
// Out of special_vehicle spots :s
113
DEBUG(ai, 1, "special_vehicles list is too small");
116
_players_ainew[p->index].special_vehicles[new_id].veh_id = v->index;
117
_players_ainew[p->index].special_vehicles[new_id].flag = flag;