1 /*
2 ===========================================================================
3 
4 Return to Castle Wolfenstein single player GPL Source Code
5 Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”).
8 
9 RTCW SP Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 RTCW SP Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with RTCW SP Source Code.  If not, see <http://www.gnu.org/licenses/>.
21 
22 In addition, the RTCW SP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW SP Source Code.  If not, please request a copy in writing from id Software at the address below.
23 
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25 
26 ===========================================================================
27 */
28 
29 //===========================================================================
30 //
31 // Name:			ai_cast_debug.c
32 // Function:		Wolfenstein AI Character Routines
33 // Programmer:		Ridah
34 // Tab Size:		4 (real tabs)
35 //===========================================================================
36 
37 #include "g_local.h"
38 #include "../botlib/botlib.h"      //bot lib interface
39 #include "../botlib/be_aas.h"
40 #include "../botlib/be_ea.h"
41 #include "../botlib/be_ai_gen.h"
42 #include "../botlib/be_ai_goal.h"
43 #include "../botlib/be_ai_move.h"
44 #include "../botlib/botai.h"          //bot ai interface
45 
46 #include "ai_cast.h"
47 
48 static int numaifuncs;
49 static char     *aifuncs[MAX_AIFUNCS];
50 
51 /*
52 ==========
53 AICast_DBG_InitAIFuncs
54 ==========
55 */
AICast_DBG_InitAIFuncs(void)56 void AICast_DBG_InitAIFuncs( void ) {
57 	numaifuncs = 0;
58 }
59 
60 /*
61 ==========
62 AICast_DBG_AddAIFunc
63 ==========
64 */
AICast_DBG_AddAIFunc(cast_state_t * cs,char * funcname)65 void AICast_DBG_AddAIFunc( cast_state_t *cs, char *funcname ) {
66 	if ( aicast_debug.integer ) {
67 		if ( aicast_debug.integer != 2 || ( g_entities[cs->entityNum].aiName && !strcmp( aicast_debugname.string, g_entities[cs->entityNum].aiName ) ) ) {
68 			G_Printf( "%s: %s\n", g_entities[cs->entityNum].aiName, funcname );
69 		}
70 	}
71 	aifuncs[numaifuncs] = funcname;
72 	numaifuncs++;
73 }
74 
75 /*
76 ==========
77 AICast_DBG_ListAIFuncs
78 ==========
79 */
AICast_DBG_ListAIFuncs(cast_state_t * cs,int numprint)80 void AICast_DBG_ListAIFuncs( cast_state_t *cs, int numprint ) {
81 	int i;
82 
83 	if ( aicast_debug.integer != 2 || ( g_entities[cs->entityNum].aiName && !strcmp( aicast_debugname.string, g_entities[cs->entityNum].aiName ) ) ) {
84 		AICast_Printf( AICAST_PRT_DEBUG, S_COLOR_RED "AICast_ProcessAIFunctions: executed more than %d AI funcs\n", MAX_AIFUNCS );
85 		for ( i = MAX_AIFUNCS - numprint; i < MAX_AIFUNCS; i++ )
86 			AICast_Printf( AICAST_PRT_DEBUG, "%s, ", aifuncs[i] );
87 		AICast_Printf( AICAST_PRT_DEBUG, "\n" );
88 	}
89 }
90 
91 /*
92 ==========
93 AICast_DebugFrame
94 ==========
95 */
AICast_DebugFrame(cast_state_t * cs)96 void AICast_DebugFrame( cast_state_t *cs ) {
97 	gentity_t *ent;
98 
99 	if ( aicast_debug.integer ) {
100 		ent = &g_entities[cs->entityNum];
101 
102 		if ( cs->castScriptStatus.castScriptEventIndex >= 0 ) {
103 			ent->client->ps.eFlags |= EF_TALK;
104 		} else {
105 			ent->client->ps.eFlags &= ~EF_TALK;
106 		}
107 	}
108 }
109 
110 /*
111 ===========
112 AICast_DBG_RouteTable_f
113 ===========
114 */
AICast_DBG_RouteTable_f(vec3_t org,char * param)115 void AICast_DBG_RouteTable_f( vec3_t org, char *param ) {
116 	static int srcarea = 0, dstarea = 0;
117 //	extern botlib_export_t botlib;
118 
119 	if ( !param || strlen( param ) < 1 ) {
120 		trap_Print( "You must specify 'src', 'dest' or 'show'\n" );
121 		return;
122 	}
123 
124 	trap_AAS_SetCurrentWorld( 0 );  // use the default world, which should have a routetable
125 
126 	if ( Q_stricmp( param, "toggle" ) == 0 ) {
127 		trap_AAS_RT_ShowRoute( vec3_origin, -666, -666 );   // stupid toggle hack
128 		return;
129 	}
130 
131 	if ( Q_stricmp( param, "src" ) == 0 ) { // set the src
132 		srcarea = 1 + trap_AAS_PointAreaNum( org );
133 		return;
134 	} else if ( Q_stricmp( param, "dest" ) == 0 )        {
135 		dstarea = 1 + trap_AAS_PointAreaNum( org );
136 	}
137 
138 	if ( srcarea && dstarea ) { // show the path
139 		trap_AAS_RT_ShowRoute( org, srcarea - 1, dstarea - 1 );
140 	} else
141 	{
142 		trap_Print( "You must specify 'src' & 'dest' first\n" );
143 	}
144 }
145 
146 /*
147 ===============
148 AICast_DBG_Spawn_f
149 ===============
150 */
AICast_DBG_Spawn_f(gclient_t * client,char * cmd)151 void AICast_DBG_Spawn_f( gclient_t *client, char *cmd ) {
152 	extern qboolean G_CallSpawn( gentity_t *ent );
153 	gentity_t   *ent;
154 	vec3_t dir;
155 
156 	ent = G_Spawn();
157 	ent->classname = G_Alloc( strlen( cmd ) + 1 );
158 	strcpy( ent->classname, cmd );
159 	AngleVectors( client->ps.viewangles, dir, NULL, NULL );
160 	VectorMA( client->ps.origin, 96, dir, ent->s.origin );
161 
162 	if ( !G_CallSpawn( ent ) ) {
163 		G_Printf( "Error: unable to spawn \"%s\" entity\n", cmd );
164 	}
165 }
166 
167 /*
168 ===============
169 AICast_DBG_Cmd_f
170 
171   General entry point for all "aicast ..." commands
172 ===============
173 */
AICast_DBG_Cmd_f(int clientNum)174 void AICast_DBG_Cmd_f( int clientNum ) {
175 	gentity_t *ent;
176 	char cmd[MAX_TOKEN_CHARS];
177 
178 	ent = g_entities + clientNum;
179 	if ( !ent->client ) {
180 		return;     // not fully in game yet
181 	}
182 
183 	// get the first word following "aicast"
184 	trap_Argv( 1, cmd, sizeof( cmd ) );
185 
186 	if ( Q_stricmp( cmd, "dbg_routetable" ) == 0 ) {
187 		trap_Argv( 2, cmd, sizeof( cmd ) );
188 		AICast_DBG_RouteTable_f( ent->client->ps.origin, cmd );
189 		return;
190 	}
191 	if ( Q_stricmp( cmd, "spawn" ) == 0 ) {
192 		// spawn a given character
193 		trap_Argv( 2, cmd, sizeof( cmd ) );
194 		AICast_DBG_Spawn_f( ent->client, cmd );
195 		return;
196 	}
197 	if ( Q_stricmp( cmd, "getname" ) == 0 ) {
198 		// get name of character we're looking at
199 //		AICast_DBG_GetName_f(ent);
200 		return;
201 	}
202 	if ( Q_stricmp( cmd, "followme" ) == 0 ) {
203 		// tell character to follow us
204 		trap_Argv( 2, cmd, sizeof( cmd ) );
205 //		AICast_DBG_FollowMe_f(ent->client, cmd);
206 		return;
207 	}
208 }
209 /*
210 // Ridah, faster Win32 code
211 #ifdef _WIN32
212 #include <windows.h>
213 #endif
214 
215 int Sys_MilliSeconds(void)
216 {
217 // Ridah, faster Win32 code
218 #ifdef _WIN32
219 	int			sys_curtime;
220 	static qboolean	initialized = qfalse;
221 	static int	sys_timeBase;
222 
223 	if (!initialized) {
224 		sys_timeBase = timeGetTime();
225 		initialized = qtrue;
226 	}
227 	sys_curtime = timeGetTime() - sys_timeBase;
228 
229 	return sys_curtime;
230 #else
231 	return clock() * 1000 / CLOCKS_PER_SEC;
232 #endif
233 } //end of the function Sys_MilliSeconds
234 */
235