ew-progs/xsniperbot/xwayfile.qc

335 lines
6 KiB
C++
Raw Normal View History

2011-09-06 00:00:00 +00:00
/*
=============================
xwayfile.qc
coded by
Michael Rogers a.k.a Xsniper
ssj_xsniper@yahoo.com
http://www.xsniper.net
Description:
Load Waypoint list from file, and Create waypoint list files.
=============================
*/
/*
======================
CreateWayFile
This function will dump the current waypoints in the level to a file
that is named after the level.
This file has no file extension.
======================
*/
void() CreateWayFile =
{
local float file;
local string entry, newline, directory;
local entity way;
//set up our map name
directory = "maps/";
entry = strcat(directory,mapname);
//debug
bprint("Creating file: ");
bprint(entry);
bprint("\n");
//open the file in write mode
file = open(entry, FILE_WRITE);
//if the file didnt open correctly
if (file == -1)
{
bprint("Error: file not found\n");
return;
}
//do them one path at a time
//path 1
entry = ftos(path1_total);
write(file, entry);
//make a blank line
newline = "\n";
write(file, newline);
//find the waypoints
way = find(world, classname, "waypoint");
//write them to the file
while (way)
{
//only do first path waypoints
if (way.path == 0)
{
//do the path first
entry = ftos(way.path);
write(file, entry);
//make a blank line
write(file, newline);
//now do the waypoint number
entry = ftos(way.waypoint);
write(file, entry);
//make a blank line
write(file, newline);
//do the coordinates
entry = vtos(way.origin);
write(file, entry);
//make a blank line
write(file, newline);
//finally put the current angles of the waypoint
entry = vtos(way.angles);
write(file, entry);
//make a blank line
write(file, newline);
}
//next waypoint
way = find(way, classname, "waypoint");
}
//path 2
entry = ftos(path2_total);
write(file, entry);
//blank line
write(file, newline);
//find the waypoints
way = find(world, classname, "waypoint");
//write them to the file
while (way)
{
//only do second path waypoints
if (way.path == 1)
{
//do the path first
entry = ftos(way.path);
write(file, entry);
//make a blank line
write(file, newline);
//now do the waypoint number
entry = ftos(way.waypoint);
write(file, entry);
//make a blank line
write(file, newline);
//do the coordinates
entry = vtos(way.origin);
write(file, entry);
//make a blank line
write(file, newline);
//finally put the current angles of the waypoint
entry = vtos(way.angles);
write(file, entry);
//make a blank line
write(file, newline);
}
//next waypoint
way = find(way, classname, "waypoint");
}
//path 3
entry = ftos(path3_total);
write(file, entry);
//blank line
write(file, newline);
//find the waypoints
way = find(world, classname, "waypoint");
//write them to the file
while (way)
{
//only do third path waypoints
if (way.path == 2)
{
//do the path first
entry = ftos(way.path);
write(file, entry);
//make a blank line
write(file, newline);
//now do the waypoint number
entry = ftos(way.waypoint);
write(file, entry);
//make a blank line
write(file, newline);
//do the coordinates
entry = vtos(way.origin);
write(file, entry);
//make a blank line
write(file, newline);
//finally put the current angles of the waypoint
entry = vtos(way.angles);
write(file, entry);
//make a blank line
write(file, newline);
}
//next waypoint
way = find(way, classname, "waypoint");
}
//close out the file
close(file);
};
void() OpenWayFile =
{
local float file, waypath, waynum, i, j;
local string entry, directory;
local vector spot, wayangles;
//on final map so we do something special
if (mapname == "ewend")
entry = "maps/ewend.way";
else
{
//set up our map name
directory = "maps/";
entry = strcat(directory,mapname);
}
//debug
bprint("Opening file: ");
bprint(entry);
bprint("\n");
//open the file in read mode
file = open(entry, FILE_READ);
//if the file didnt open correctly
if (file == -1)
{
bprint("Error: no waypoint file found\n");
return;
}
//read them in one path at a time
//path1
entry = read(file);
path1_total = stof(entry);
//set up the loop
i = 0;
j = path1_total;
//read from file
while (i < j)
{
//read the path
entry = read(file);
waypath = stof(entry);
//now get the waypoint number
entry = read(file);
waynum = stof(entry);
//get the coordinates
entry = read(file);
spot = stov(entry);
//finally get the angles
entry = read(file);
wayangles = stov(entry);
//create the waypoint
create_waypoint(waypath,waynum,spot,wayangles);
//increment i
i = i + 1;
}
//path2
entry = read(file);
path2_total = stof(entry);
//set up the loop
i = 0;
j = path2_total;
//read from file
while (i < j)
{
//read the path
entry = read(file);
waypath = stof(entry);
//now get the waypoint number
entry = read(file);
waynum = stof(entry);
//get the coordinates
entry = read(file);
spot = stov(entry);
//finally get the angles
entry = read(file);
wayangles = stov(entry);
//create the waypoint
create_waypoint(waypath,waynum,spot,wayangles);
//increment i
i = i + 1;
}
//path3
entry = read(file);
path3_total = stof(entry);
//set up the loop
i = 0;
j = path3_total;
//read from file
while (i < j)
{
//read the path
entry = read(file);
waypath = stof(entry);
//now get the waypoint number
entry = read(file);
waynum = stof(entry);
//get the coordinates
entry = read(file);
spot = stov(entry);
//finally get the angles
entry = read(file);
wayangles = stov(entry);
//create the waypoint
create_waypoint(waypath,waynum,spot,wayangles);
//increment i
i = i + 1;
}
//close out the file
close(file);
};