2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2005-09-02 19:10:45 +00:00
|
|
|
#include "../../stdafx.h"
|
|
|
|
#include "../../openttd.h"
|
|
|
|
#include "../../debug.h"
|
|
|
|
#include "../../map.h"
|
|
|
|
#include "trolly.h"
|
|
|
|
#include "../../vehicle.h"
|
2004-08-22 15:56:56 +00:00
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
int AiNew_GetRailDirection(TileIndex tile_a, TileIndex tile_b, TileIndex tile_c)
|
|
|
|
{
|
2004-08-22 15:56:56 +00:00
|
|
|
// 0 = vert
|
|
|
|
// 1 = horz
|
|
|
|
// 2 = dig up-left
|
|
|
|
// 3 = dig down-right
|
|
|
|
// 4 = dig down-left
|
|
|
|
// 5 = dig up-right
|
|
|
|
|
2006-06-27 21:25:53 +00:00
|
|
|
uint x1 = TileX(tile_a);
|
|
|
|
uint x2 = TileX(tile_b);
|
|
|
|
uint x3 = TileX(tile_c);
|
2004-08-22 15:56:56 +00:00
|
|
|
|
2006-06-27 21:25:53 +00:00
|
|
|
uint y1 = TileY(tile_a);
|
|
|
|
uint y2 = TileY(tile_b);
|
|
|
|
uint y3 = TileY(tile_c);
|
2004-08-22 15:56:56 +00:00
|
|
|
|
|
|
|
if (y1 == y2 && y2 == y3) return 0;
|
|
|
|
if (x1 == x2 && x2 == x3) return 1;
|
2006-06-27 21:25:53 +00:00
|
|
|
if (y2 > y1) return x2 > x3 ? 2 : 4;
|
|
|
|
if (x2 > x1) return y2 > y3 ? 2 : 5;
|
|
|
|
if (y1 > y2) return x2 > x3 ? 5 : 3;
|
|
|
|
if (x1 > x2) return y2 > y3 ? 4 : 3;
|
2004-08-22 15:56:56 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
int AiNew_GetRoadDirection(TileIndex tile_a, TileIndex tile_b, TileIndex tile_c)
|
|
|
|
{
|
2004-08-22 15:56:56 +00:00
|
|
|
int x1, x2, x3;
|
|
|
|
int y1, y2, y3;
|
|
|
|
int r;
|
|
|
|
|
2005-01-07 17:02:43 +00:00
|
|
|
x1 = TileX(tile_a);
|
|
|
|
x2 = TileX(tile_b);
|
|
|
|
x3 = TileX(tile_c);
|
2004-08-22 15:56:56 +00:00
|
|
|
|
2005-01-07 17:02:43 +00:00
|
|
|
y1 = TileY(tile_a);
|
|
|
|
y2 = TileY(tile_b);
|
|
|
|
y3 = TileY(tile_c);
|
2004-08-22 15:56:56 +00:00
|
|
|
|
|
|
|
r = 0;
|
|
|
|
|
|
|
|
if (x1 < x2) r += 8;
|
|
|
|
if (y1 < y2) r += 1;
|
|
|
|
if (x1 > x2) r += 2;
|
|
|
|
if (y1 > y2) r += 4;
|
|
|
|
|
|
|
|
if (x2 < x3) r += 2;
|
|
|
|
if (y2 < y3) r += 4;
|
|
|
|
if (x2 > x3) r += 8;
|
|
|
|
if (y2 > y3) r += 1;
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get's the direction between 2 tiles seen from tile_a
|
2006-04-23 19:08:33 +00:00
|
|
|
DiagDirection AiNew_GetDirection(TileIndex tile_a, TileIndex tile_b)
|
2005-06-24 12:38:35 +00:00
|
|
|
{
|
2006-04-23 19:08:33 +00:00
|
|
|
if (TileY(tile_a) < TileY(tile_b)) return DIAGDIR_SE;
|
|
|
|
if (TileY(tile_a) > TileY(tile_b)) return DIAGDIR_NW;
|
|
|
|
if (TileX(tile_a) < TileX(tile_b)) return DIAGDIR_SW;
|
|
|
|
return DIAGDIR_NE;
|
2004-08-22 15:56:56 +00:00
|
|
|
}
|
2004-08-31 16:12:52 +00:00
|
|
|
|
2006-06-27 21:25:53 +00:00
|
|
|
|
2004-08-31 16:12:52 +00:00
|
|
|
// This functions looks up if this vehicle is special for this AI
|
|
|
|
// and returns his flag
|
2006-06-27 21:25:53 +00:00
|
|
|
uint AiNew_GetSpecialVehicleFlag(Player* p, Vehicle* v)
|
|
|
|
{
|
|
|
|
uint i;
|
|
|
|
|
|
|
|
for (i = 0; i < AI_MAX_SPECIAL_VEHICLES; i++) {
|
2004-08-31 16:12:52 +00:00
|
|
|
if (p->ainew.special_vehicles[i].veh_id == v->index) {
|
|
|
|
return p->ainew.special_vehicles[i].flag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Not found :(
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-06-27 21:25:53 +00:00
|
|
|
|
|
|
|
bool AiNew_SetSpecialVehicleFlag(Player* p, Vehicle* v, uint flag)
|
|
|
|
{
|
|
|
|
int new_id = -1;
|
|
|
|
uint i;
|
|
|
|
|
|
|
|
for (i = 0; i < AI_MAX_SPECIAL_VEHICLES; i++) {
|
2004-08-31 16:12:52 +00:00
|
|
|
if (p->ainew.special_vehicles[i].veh_id == v->index) {
|
|
|
|
p->ainew.special_vehicles[i].flag |= flag;
|
|
|
|
return true;
|
|
|
|
}
|
2006-06-27 21:25:53 +00:00
|
|
|
if (new_id == -1 &&
|
|
|
|
p->ainew.special_vehicles[i].veh_id == 0 &&
|
|
|
|
p->ainew.special_vehicles[i].flag == 0) {
|
2004-08-31 16:12:52 +00:00
|
|
|
new_id = i;
|
2006-06-27 21:25:53 +00:00
|
|
|
}
|
2004-08-31 16:12:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Out of special_vehicle spots :s
|
|
|
|
if (new_id == -1) {
|
2006-12-26 17:36:18 +00:00
|
|
|
DEBUG(ai, 1, "special_vehicles list is too small");
|
2004-08-31 16:12:52 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
p->ainew.special_vehicles[new_id].veh_id = v->index;
|
|
|
|
p->ainew.special_vehicles[new_id].flag = flag;
|
|
|
|
return true;
|
|
|
|
}
|