FS2_Open
Open source remastering of the Freespace 2 engine
ai.cpp
Go to the documentation of this file.
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 the
6  * source.
7  *
8 */
9 
16 #include "ai/ai.h"
17 #include "object/object.h"
18 #include "ship/ship.h"
19 
20 
25 
30 int ai_get_slot(int shipnum)
31 {
32  int i;
33 
34  for (i=0; i<MAX_AI_INFO ; i++)
35  if (Ai_info[i].shipnum == -1) {
36  Ai_info[i].shipnum = shipnum;
37  return i;
38  }
39 
40  Warning( LOCATION, "Couldn't get AI slot" );
41  Int3();
42 
43  return -1;
44 }
45 
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_target_name(const char *name, int *index)
86 {
87  Assert(name != NULL);
88  Assert(index != NULL);
89  int i;
90 
91  for (i=0; i < Total_goal_target_names; i++)
92  if (!stricmp(name, Goal_target_names[i])) {
93  *index = i;
94  return Goal_target_names[i];
95  }
96 
97  Assert(Total_goal_target_names < MAX_GOAL_TARGET_NAMES);
98  Assertion(strlen(name) <= NAME_LENGTH - 1, "Goal target name %s is too long. Needs to be 31 characters or less.", name);
99  i = Total_goal_target_names++;
100  strcpy_s(Goal_target_names[i], name);
101  *index = i;
102  return Goal_target_names[i];
103 }
int i
Definition: multi_pxo.cpp:466
int Total_goal_target_names
Definition: ai.cpp:21
ai_info * Player_ai
Definition: ai.cpp:24
GLuint index
Definition: Glext.h:5608
#define MAX_SHIPS
Definition: globals.h:37
void _cdecl void void _cdecl void _cdecl Warning(char *filename, int line, SCP_FORMAT_STRING const char *format,...) SCP_FORMAT_STRING_ARGS(3
Assert(pm!=NULL)
int ai_index
Definition: ship.h:538
ai_info Ai_info[MAX_AI_INFO]
Definition: ai.cpp:23
#define Assertion(expr, msg,...)
Definition: clang.h:41
Definition: ai.h:329
char Goal_target_names[MAX_GOAL_TARGET_NAMES][NAME_LENGTH]
Definition: ai.cpp:22
#define Int3()
Definition: pstypes.h:292
GLenum type
Definition: Gl.h:1492
int instance
Definition: object.h:150
int shipnum
Definition: ai.h:331
object Objects[MAX_OBJECTS]
Definition: object.cpp:62
char * ai_get_goal_target_name(const char *name, int *index)
Definition: ai.cpp:85
#define OBJ_SHIP
Definition: object.h:32
GLuint const GLchar * name
Definition: Glext.h:5608
ship Ships[MAX_SHIPS]
Definition: ship.cpp:122
#define MAX_AI_INFO
Definition: ai.h:564
#define NAME_LENGTH
Definition: globals.h:15
#define LOCATION
Definition: pstypes.h:245
void set_wingnum(int objnum, int wingnum)
Definition: ai.cpp:68
int wing
Definition: ai.h:333
int get_wingnum(int objnum)
Definition: ai.cpp:57
void ai_free_slot(int ai_index)
Frees a currently used AI slot.
Definition: ai.cpp:50
int ai_get_slot(int shipnum)
Returns index of free AI slot.
Definition: ai.cpp:30
#define stricmp(s1, s2)
Definition: config.h:271
#define strcpy_s(...)
Definition: safe_strings.h:67
#define MAX_GOAL_TARGET_NAMES
Definition: ai.h:164