1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
/*
SABRE Fighter Plane Simulator
Copyright (c) 1997 Dan Hammer
Portions Donated By Antti Barck
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 1, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*************************************************
* SABRE Fighter Plane Simulator *
* Version: 0.1 *
* File : waypoint.C *
* Date : January, 1998 *
* Author : Dan Hammer *
*************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <iostream.h>
#include <fstream.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include <values.h>
#include <stdarg.h>
#include "defs.h"
#include "sim.h"
#include "simerr.h"
#include "simfile.h"
#include "vmath.h"
#include "waypoint.h"
WayPoint ** WayPoint::gwaypoints = NULL;
int WayPoint::n_waypoints = 0;
void WayPoint::read(istream &is)
{
char c = ' ';
READ_TOK('(',is,c)
is >> mode >> mode_x >> mode_y ;
is >> location >> average_speed >> c;
location *= world_scale;
READ_TOK(')',is,c)
average_speed = kts2fps(average_speed);
}
void WayPoint::write(ostream &os)
{
os << "(\n" << mode << " " << mode_x << " " << mode_y << "\n";
os << location << " " << fps2kts(average_speed) << "\n";
os << ")\n";
}
void WayPoint::readWayPoints(istream &is)
{
int i;
int n;
gwaypoints = NULL;
is >> n_waypoints;
if (n_waypoints > 0)
{
if (gwaypoints != NULL)
delete gwaypoints;
gwaypoints = new WayPoint *[n_waypoints];
MYCHECK(gwaypoints != NULL);
for (i=0;i<n_waypoints;i++)
gwaypoints[i] = readWayPointChain(is,n);
}
}
WayPoint *WayPoint::readWayPointChain(istream &is, int &n)
{
char c;
WayPoint *result = NULL;
READ_TOKI('{',is ,c);
is >> n;
result = new WayPoint[n];
MYCHECK(result != NULL);
for (int j=0;j<n;j++)
{
is >> result[j];
if (j > 0)
{
result[j].prev = &result[j-1];
result[j-1].next = &result[j];
}
}
is >> c;
READ_TOK('}',is ,c);
return (result);
}
void WayPoint::readWayPointFile(char *path)
{
ifstream is;
if (open_is(is,path))
readWayPoints(is);
}
void WayPoint::writeWayPoints(ostream &)
{
}
void WayPoint::writeWayPointFile(char *path)
{
ofstream os;
if (open_libos(os,path))
writeWayPoints(os);
}
WayPoint *WayPoint::getWayPoint(char *idd)
{
WayPoint *result = NULL;
for (int i=0;i<n_waypoints;i++)
{
WayPoint *wp = gwaypoints[i];
while (wp != NULL)
{
if (!strcmp(wp->id,idd))
{
result = wp;
break;
}
wp = wp->next;
}
}
return (result);
}
|