~ubuntu-branches/debian/squeeze/openttd/squeeze

« back to all changes in this revision

Viewing changes to src/ai/trolly/shared.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jordi Mallach, Matthijs Kooijman, Jordi Mallach
  • Date: 2009-04-15 18:22:10 UTC
  • mfrom: (1.1.6 upstream) (2.1.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090415182210-22ktb8kdbp2tf3bm
[ Matthijs Kooijman ]
* New upstream release.
* Remove Debian specific desktop file, upstream provides one now. 
* Add debian/watch file.

[ Jordi Mallach ]
* Bump Standards-Version to 3.8.1, with no changes required.
* Move to debhelper compat 7. Bump Build-Depends accordingly.
* Use dh_prep.
* Add "set -e" to config script.
* Remove a few extra doc files that get installed by upstream Makefile.
* Add more complete copyright information.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: shared.cpp 11818 2008-01-12 14:10:35Z rubidium $ */
2
 
 
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"
9
 
#include "trolly.h"
10
 
 
11
 
int AiNew_GetRailDirection(TileIndex tile_a, TileIndex tile_b, TileIndex tile_c)
12
 
{
13
 
        // 0 = vert
14
 
        // 1 = horz
15
 
        // 2 = dig up-left
16
 
        // 3 = dig down-right
17
 
        // 4 = dig down-left
18
 
        // 5 = dig up-right
19
 
 
20
 
        uint x1 = TileX(tile_a);
21
 
        uint x2 = TileX(tile_b);
22
 
        uint x3 = TileX(tile_c);
23
 
 
24
 
        uint y1 = TileY(tile_a);
25
 
        uint y2 = TileY(tile_b);
26
 
        uint y3 = TileY(tile_c);
27
 
 
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;
34
 
 
35
 
        return 0;
36
 
}
37
 
 
38
 
int AiNew_GetRoadDirection(TileIndex tile_a, TileIndex tile_b, TileIndex tile_c)
39
 
{
40
 
        int x1, x2, x3;
41
 
        int y1, y2, y3;
42
 
        int r;
43
 
 
44
 
        x1 = TileX(tile_a);
45
 
        x2 = TileX(tile_b);
46
 
        x3 = TileX(tile_c);
47
 
 
48
 
        y1 = TileY(tile_a);
49
 
        y2 = TileY(tile_b);
50
 
        y3 = TileY(tile_c);
51
 
 
52
 
        r = 0;
53
 
 
54
 
        if (x1 < x2) r += 8;
55
 
        if (y1 < y2) r += 1;
56
 
        if (x1 > x2) r += 2;
57
 
        if (y1 > y2) r += 4;
58
 
 
59
 
        if (x2 < x3) r += 2;
60
 
        if (y2 < y3) r += 4;
61
 
        if (x2 > x3) r += 8;
62
 
        if (y2 > y3) r += 1;
63
 
 
64
 
        return r;
65
 
}
66
 
 
67
 
// Get's the direction between 2 tiles seen from tile_a
68
 
DiagDirection AiNew_GetDirection(TileIndex tile_a, TileIndex tile_b)
69
 
{
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;
73
 
        return DIAGDIR_NE;
74
 
}
75
 
 
76
 
 
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)
80
 
{
81
 
        uint i;
82
 
 
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;
86
 
                }
87
 
        }
88
 
 
89
 
        // Not found :(
90
 
        return 0;
91
 
}
92
 
 
93
 
 
94
 
bool AiNew_SetSpecialVehicleFlag(Player* p, Vehicle* v, uint flag)
95
 
{
96
 
        int new_id = -1;
97
 
        uint i;
98
 
 
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;
102
 
                        return true;
103
 
                }
104
 
                if (new_id == -1 &&
105
 
                                _players_ainew[p->index].special_vehicles[i].veh_id == 0 &&
106
 
                                _players_ainew[p->index].special_vehicles[i].flag == 0) {
107
 
                        new_id = i;
108
 
                }
109
 
        }
110
 
 
111
 
        // Out of special_vehicle spots :s
112
 
        if (new_id == -1) {
113
 
                DEBUG(ai, 1, "special_vehicles list is too small");
114
 
                return false;
115
 
        }
116
 
        _players_ainew[p->index].special_vehicles[new_id].veh_id = v->index;
117
 
        _players_ainew[p->index].special_vehicles[new_id].flag = flag;
118
 
        return true;
119
 
}