-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplanet.h
More file actions
139 lines (110 loc) · 3.98 KB
/
planet.h
File metadata and controls
139 lines (110 loc) · 3.98 KB
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
/*
Copyright (c) 2013 Auston Sterling
See license.txt for copying permission.
-----Planet Class Declaration-----
Auston Sterling
austonst@gmail.com
Header for the Planet class in "Galcon".
*/
#include "rotationcache.h"
#include "SDL/SDL.h"
#include "SDL/SDL_ttf.h"
#include "buildingInstance.h"
#include "vec2f.h"
#include "shipstats.h"
#include <vector>
#include <map>
#include <list>
#ifndef _planet_h_
#define _planet_h_
const int NUM_PLANET_ROTATIONS = 500;
const int UNSCALED_PLANET_RADIUS = 50;
const float PLANET1_FUEL_PER_SIZE = 240000;
const float PLANET1_DEPLETION_RATE = 1000;
const float PLANET1_DEPLETION_PENALTY = .5;
const float PLANET_DAMAGE_MULT[2] = {1,1.3};
class Planet
{
public:
//Constructors/Destructor
Planet();
Planet(SDL_Surface* surf, float size, Vec2f loc, int type);
~Planet();
//Regular use functions
void display(SDL_Surface* screen, TTF_Font* font, const SDL_Rect& camera);
void update();
bool canBuild();
void build(Building* inbuild);
void build(Building* inbuild, const std::vector<std::list<Building*> >& rules);
void destroy(int index);
void addShips(int inships, int type);
int splitShips(float ratio, int type);
void takeAttack(int inships, int type, int player, const std::vector<ShipStats>& shipstats, SDL_Surface* indicator[]);
//Accessors
SDL_Surface* rotation(float angle = -1);
Vec2f pos() const {return pos_;}
Vec2f center() const {Vec2f c = pos()+Vec2f(UNSCALED_PLANET_RADIUS,UNSCALED_PLANET_RADIUS); return c;}
double x() const {return pos_.x();}
double y() const {return pos_.y();}
float size() const {return size_;}
char type() const {return type_;}
float shipcount(int index) const {return ship_[index].first;}
std::vector<int> shipcount() const;
float shiprate(int index) const {return ship_[index].second;}
std::vector<float> shiprate() const;
unsigned int buildcount() const {return building_.size();}
BuildingInstance* building(int i) {return &(building_[i]);}
Vec2f buildcoords(int i);
int owner() const {return owner_;}
int buildIndex() const {return buildIndex_;}
float totalAttack(const std::vector<ShipStats>& shipstats) const;
float totalDefense(const std::vector<ShipStats>& shipstats) const;
int typeInfo() const {return typeInfo_;}
//Mutators
void setImage(SDL_Surface* insurf);
void setRotSpeed(const float& inspeed) {rotspeed_ = inspeed;}
void setSize(const float& insize) {size_ = insize;}
void setType(const int& intype);
void setOwner(const int inowner, SDL_Surface* indicator[]);
void setShipRate(int index, float rate) {ship_[index].second = rate * size_;}
void setDifficulty(int diff) {if (owner_==0) ship_[0].first = diff;}
void setTypeInfo(int ti) {typeInfo_ = ti;}
private:
//Stores the rotations of the planet
RotationCache rotation_;
//Current rotation, in radians
float rot_;
//Rotation speed of the planet, in rad/s
float rotspeed_;
//Location of the planet
Vec2f pos_;
//Size of the planet as a scalar amount from the base
float size_;
//Time of last progress() call
int time_;
//Type of planet
unsigned char type_;
//Vector of buildings on this planet
std::vector<BuildingInstance> building_;
//Index of which building is being built
int buildIndex_;
//Time passed (ms) for this building's construction
int buildTime_;
//Vector of pairs of ship counts and build rates, respectively
std::vector<std::pair<float, float> > ship_;
//The surface with text showing the total number of ships
SDL_Surface* countImg_;
//The actual number from last time
int count_;
//The number for the player who owns the planet
int owner_;
//The surface for the scaled owner indicator
SDL_Surface* indicator_;
//Variable for keeping track of type-specific information
int typeInfo_;
};
typedef std::list<Planet>::iterator planetIter;
typedef std::list<Planet>::const_iterator planetIterConst;
typedef std::list<Planet*>::iterator planetPtrIter;
typedef std::list<Planet*>::const_iterator planetPtrIterConst;
#endif