File: LevelPack.hpp

package info (click to toggle)
criticalmass 0.97-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 5,376 kB
  • ctags: 2,652
  • sloc: cpp: 15,548; xml: 3,182; sh: 334; makefile: 170
file content (176 lines) | stat: -rw-r--r-- 3,617 bytes parent folder | download | duplicates (2)
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
// Description:
//   Structures and classes for LevelPacks.
//
// Copyright (C) 2001 Frank Becker
//
// 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 2 of the License,  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
//
#ifndef _LevelPack_hpp_
#define _LevelPack_hpp_

#include <Trace.hpp>
#include <Point.hpp>
#include <BezierCurve.hpp>

struct LevelInfo
{
    string name;       //Name for Level or LevelPack
    string author;     //Author of Level or LevelPack
    float version;

#if 0
    //extra data...
    int numTags;
    string *tagName; 
    Value  *tagValue;
#endif
};

class LPath
{
//bezier curve or some constant velocity curve...
public:
    LPath( BezierCurve<Point3D> *bc, bool linear=false):
        _isLinear(linear),
        _bc(bc)
    {
	XTRACE();
        _init();
    }
    LPath( void):_isLinear(false), _bc(0) {}

    void init( BezierCurve<Point3D> *bc, bool linear=false)
    {
	XTRACE();
        _bc = bc;
        _isLinear = linear;
        _init();
    }
    ~LPath()
    {
	XTRACE();
        delete _bc;
    }

    float length( void)
    {
        return _length;
    }
    void getPos( float t, Point3D &pos)
    {
        //assume t is [0,_length]
	_bc->GetPos( t, pos);
    }
    void getTangent( float t, Point3D &tangent)
    {
        //assume t is [0,_length]
	_bc->GetTangent( t, tangent);
    }

    void start( Point3D &pos)
    {
        pos = _start;
    }
    void startT( Point3D &tangent)
    {
        tangent = _startT;
    }
    void end( Point3D &pos)
    {
        pos = _end;
    }
    void endT( Point3D &tangent)
    {
        tangent = _endT;
    }

    void update( void)
    {
        //update internally cached values
        _init();
    }

    BezierCurve<Point3D> *getBezierCurve( void)
    {
        return _bc;
    }

private:
    bool _isLinear;
    float _length;

    void _init( void)
    {
	XTRACE();
        int num = _bc->GetNumSegments();
        if( num > 0) 
        {
	    _length = (float)(num);
	    _start  = _bc->GetControlPoint( 0);
	    _startT = _bc->GetControlPoint( 1) - _start;
	    _end  = _bc->GetControlPoint( _bc->GetNumControlPoints()-1);
	    _endT = _bc->GetControlPoint( _bc->GetNumControlPoints()-2) - _end;
        }
        else
            _length = 0.0;
    }

    Point3D _start;
    Point3D _startT;
    Point3D _end;
    Point3D _endT;

    BezierCurve<Point3D> *_bc;
};

class Model;

//spawnTime after level start at spawnPoint
//follow entryPath then transition to home.
//From home via attackPath away from home
//and via retreatPath towards home.
//Idlepath when home.
struct LEnemy
{
    float spawnTime;   //time at which to enter level
    Point3D spawnPoint;//start position
    Point3D home;      //home position

    //the flight path this enemy is capable of
    int numAttackPaths;
    LPath **attack;

    int numRetreatPaths;
    LPath **retreat;

    //a single entry and idle path
    LPath *entry;
    LPath *idle;

    Model *model;      //the model for this enemy
};

struct LevelDescription
{
    LevelInfo info;    //info for the level

    int numEnemies;
    LEnemy *enemy;
};

struct LevelPack
{
    LevelInfo info;    //info for the levelpack

    int numLevels;
    LevelDescription *level;
};

#endif