2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
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
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.
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];
30 // Return index of free AI slot.
31 // Return -1 if no free slot.
32 int ai_get_slot(int shipnum)
36 for (i=0; i<MAX_AI_INFO ; i++)
37 if (Ai_info[i].shipnum == -1) {
38 Ai_info[i].shipnum = shipnum;
42 Warning( LOCATION, "Couldn't get AI slot" );
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)
52 SDL_assert( (ai_index >= 0) && (ai_index < MAX_AI_INFO) );
54 Ai_info[ai_index].shipnum = -1;
57 int get_wingnum(int objnum)
59 int shipnum, ai_index;
61 shipnum = Objects[objnum].instance;
63 ai_index = Ships[shipnum].ai_index;
65 return Ai_info[ai_index].wing;
68 void set_wingnum(int objnum, int wingnum)
70 int shipnum, ai_index;
72 SDL_assert(Objects[objnum].type == OBJ_SHIP);
74 shipnum = Objects[objnum].instance;
76 SDL_assert((shipnum >= 0) && (shipnum < MAX_SHIPS));
78 ai_index = Ships[shipnum].ai_index;
80 SDL_assert( (ai_index >= 0) && (ai_index < MAX_AI_INFO) );
82 Ai_info[ai_index].wing = wingnum;
85 char *ai_get_goal_ship_name(const char *name, int *index)
89 for (i=0; i < Total_goal_ship_names; i++)
90 if (!SDL_strcasecmp(name, Goal_ship_names[i])) {
92 return Goal_ship_names[i];
95 SDL_assert(Total_goal_ship_names < MAX_GOAL_SHIP_NAMES);
96 SDL_assert(strlen(name) < NAME_LENGTH - 1);
97 i = Total_goal_ship_names++;
98 SDL_strlcpy(Goal_ship_names[i], name, NAME_LENGTH);
100 return Goal_ship_names[i];