]> icculus.org git repositories - taylor/freespace2.git/blob - src/ship/ai.cpp
Initial revision
[taylor/freespace2.git] / src / ship / ai.cpp
1 // The code in here is just for bookeeping, allocating
2 // ai slots and linking them to ships.
3 // See AiCode.cpp for the actual AI code.
4
5 #include "pstypes.h"
6 #include "object.h"
7 #include "physics.h"
8 #include "vecmat.h"
9 #include "ship.h"
10 #include "model.h"
11 #include "2d.h"
12 #include "3d.h"
13 #include "ai.h"
14 #include "floating.h"
15 #include "ailocal.h"
16
17 int Total_goal_ship_names = 0;
18 char Goal_ship_names[MAX_GOAL_SHIP_NAMES][NAME_LENGTH];
19 ai_info Ai_info[MAX_AI_INFO];
20 ai_info *Player_ai;
21
22 // Return index of free AI slot.
23 // Return -1 if no free slot.
24 int ai_get_slot(int shipnum)
25 {
26         int     i;
27
28         for (i=0; i<MAX_AI_INFO ; i++)
29                 if (Ai_info[i].shipnum == -1)   {
30                         Ai_info[i].shipnum = shipnum;
31                         return i;
32                 }
33
34         Warning( LOCATION, "Couldn't get AI slot" );
35         Int3();
36
37         return -1;
38 }
39
40 // Releases an AI slot to be used by someone else.
41 // Only modifies in Ai_info struct.  Does not modify hook in ship.
42 void ai_free_slot(int ai_index)
43 {
44         Assert( (ai_index >= 0) && (ai_index < MAX_AI_INFO) );
45
46         Ai_info[ai_index].shipnum = -1;
47 }
48
49 int get_wingnum(int objnum)
50 {
51         int     shipnum, ai_index;
52
53         shipnum = Objects[objnum].instance;
54
55         ai_index = Ships[shipnum].ai_index;
56
57         return Ai_info[ai_index].wing;
58 }
59
60 void set_wingnum(int objnum, int wingnum)
61 {
62         int     shipnum, ai_index;
63
64         Assert(Objects[objnum].type == OBJ_SHIP);
65
66         shipnum = Objects[objnum].instance;
67
68         Assert((shipnum >= 0) && (shipnum < MAX_SHIPS));
69
70         ai_index = Ships[shipnum].ai_index;
71
72         Assert( (ai_index >= 0) && (ai_index < MAX_AI_INFO) );
73
74         Ai_info[ai_index].wing = wingnum;
75 }
76
77 char *ai_get_goal_ship_name(char *name, int *index)
78 {
79         int i;
80
81         for (i=0; i < Total_goal_ship_names; i++)
82                 if (!stricmp(name, Goal_ship_names[i])) {
83                         *index = i;
84                         return Goal_ship_names[i];
85                 }
86
87         Assert(Total_goal_ship_names < MAX_GOAL_SHIP_NAMES);
88         Assert(strlen(name) < NAME_LENGTH - 1);
89         i = Total_goal_ship_names++;
90         strcpy(Goal_ship_names[i], name);
91         *index = i;
92         return Goal_ship_names[i];
93 }