waypoint loading. currently done by hand. while it's safe to load waypoints

with bots already in the game, re-loading doesn't seem to be a good idea.
waypoint file must be in the quake fs.
This commit is contained in:
Bill Currie 2006-12-11 10:39:43 +00:00
parent 3450ccb016
commit 9cd6038423
3 changed files with 82 additions and 4 deletions

View File

@ -141,7 +141,6 @@ void (entity e, integer ping) SV_SetPing = #0;
void (entity cl, float sec, vector angles, vector move, integer buttons, integer impulse) SV_UserCmd = #0;
void (entity cl) SV_Spawn = #0;
void () Break = #6;
string (integer i) itos = #112;
//----------------------------------------------------------------------------
@ -243,7 +242,7 @@ ClientDisconnected =
[players[i] lost:p:0];
}
}
[p dealloc];
[p release];
};
// BotConnect and related functions. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
@ -329,6 +328,16 @@ bot_kick_f =
[Bot kick];
};
void ()
bot_loadway_f =
{
if (Cmd_Argc () != 2) {
dprint ("usage: bot_loadway <path>\n");
return;
}
[Waypoint loadFile:Cmd_Argv (1)];
};
// BotInit ====================================================================
void ()
@ -343,6 +352,7 @@ BotInit =
bot_map_load ();
Cmd_AddCommand ("bot_add", bot_add_f);
Cmd_AddCommand ("bot_kick", bot_kick_f);
Cmd_AddCommand ("bot_loadway", bot_loadway_f);
};
/*

View File

@ -55,7 +55,7 @@ integer bot_way_linker;
if (current_way == what)
current_way = NIL;
[waypoint_array removeItem:what];
[what dealloc];
[what release];
}
/*

View File

@ -45,6 +45,10 @@ this notice in its entirety.
#include "libfrikbot.h"
#include "Array.h"
#include "List.h"
#include "qfile.h"
#include "qfs.h"
#include "string.h"
#include "PropertyList.h"
Array waypoint_array;
@static entity waypoint_thinker;
@ -80,6 +84,21 @@ Array waypoint_array;
return self;
}
-(id)initAt:(vector)org linkedTo:(integer[])link flags:(integer)flag
{
[self init];
[waypoint_array addItem: self];
origin = org;
links[0] = (Waypoint) link[0];
links[1] = (Waypoint) link[1];
links[2] = (Waypoint) link[2];
links[3] = (Waypoint) link[3];
flags = flag;
search_time = time;
distance = -1;
return self;
}
-(id)initFromEntity:(entity)ent
{
[self initAt:ent.origin];
@ -181,10 +200,59 @@ Waypoint Loading from file
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
*/
+(void)loadFile:(string)path
{
local QFile file;
local PLItem plist;
local string plist_data, l;
local integer i, count;
file = QFS_OpenFile (path);
if (!file) {
dprint (sprintf ("could not load file: %s", path));
return;
}
plist_data = str_new ();
while ((l = Qgetline (file)))
str_cat (plist_data, l);
Qclose (file);
plist = [PLItem newFromString:plist_data];
str_free (plist_data);
[Waypoint clearAll];
count = [(PLArray)plist numObjects];
dprint (sprintf ("%i waypoints\n", count));
for (i = 0; i < count; i++) {
local PLItem way = [plist getObjectAtIndex:i];
local PLString s = (PLString) [way getObjectForKey:"origin"];
local vector org = stov (sprintf ("'%s'", [s string]));
local PLItem links = [way getObjectForKey:"link"];
//FIXME compiler/vm "bug" makes passing pointers to locals dangerous
s = (PLString) [way getObjectForKey:"flags"];
local integer flags = stoi ([s string]);
@static integer[4] link;
s = (PLString) [links getObjectAtIndex:0];
link[0] = stoi ([s string]);
s = (PLString) [links getObjectAtIndex:1];
link[1] = stoi ([s string]);
s = (PLString) [links getObjectAtIndex:2];
link[2] = stoi ([s string]);
s = (PLString) [links getObjectAtIndex:3];
link[3] = stoi ([s string]);
[[Waypoint alloc] initAt:org linkedTo:link flags:flags];
}
[Waypoint fixWaypoints];
}
+(void)clearAll
{
dprint ("Waypoint clearAll\n");
if (waypoint_array)
[waypoint_array dealloc];
[waypoint_array release];
waypoint_init ();
}