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.
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];
22 // Return index of free AI slot.
23 // Return -1 if no free slot.
24 int ai_get_slot(int shipnum)
28 for (i=0; i<MAX_AI_INFO ; i++)
29 if (Ai_info[i].shipnum == -1) {
30 Ai_info[i].shipnum = shipnum;
34 Warning( LOCATION, "Couldn't get AI slot" );
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)
44 Assert( (ai_index >= 0) && (ai_index < MAX_AI_INFO) );
46 Ai_info[ai_index].shipnum = -1;
49 int get_wingnum(int objnum)
51 int shipnum, ai_index;
53 shipnum = Objects[objnum].instance;
55 ai_index = Ships[shipnum].ai_index;
57 return Ai_info[ai_index].wing;
60 void set_wingnum(int objnum, int wingnum)
62 int shipnum, ai_index;
64 Assert(Objects[objnum].type == OBJ_SHIP);
66 shipnum = Objects[objnum].instance;
68 Assert((shipnum >= 0) && (shipnum < MAX_SHIPS));
70 ai_index = Ships[shipnum].ai_index;
72 Assert( (ai_index >= 0) && (ai_index < MAX_AI_INFO) );
74 Ai_info[ai_index].wing = wingnum;
77 char *ai_get_goal_ship_name(char *name, int *index)
81 for (i=0; i < Total_goal_ship_names; i++)
82 if (!stricmp(name, Goal_ship_names[i])) {
84 return Goal_ship_names[i];
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);
92 return Goal_ship_names[i];