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