-
Notifications
You must be signed in to change notification settings - Fork 0
/
Modes.cpp
182 lines (154 loc) · 4.92 KB
/
Modes.cpp
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
177
178
179
180
181
182
/*
* Modes.cpp
*
* Copyright 2015 Joaquín Monteagudo Gómez <kindos7@gmail.com>
*
* 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*
*/
/*
C++ library (source file)
Modes
Gamemodes
*/
/*
Version 0.1 (dd/mm/yy, 22/11/2015 ->)
*/
/*
Preprocessor
*/
/* Includes */
//Header file
#include "Modes.hpp"
namespace fdx{ namespace fighter
{
/*Init*/
std::uniform_real_distribution<double> Offline_Survival::RNG_D(0,1);//Generates random doubles
std::default_random_engine Offline_Survival::RE;//Engine for the random numbers
std::uniform_real_distribution<double> Multi_DM::RNG_D(0,1);//Generates random doubles
std::default_random_engine Multi_DM::RE;//Engine for the random numbers
/*
Functions
*/
/*Offline survival*/
//Population control
void Offline_Survival::add_enemy()//Add enemy
{
//Update the counters
++now_cur;
--now_tot;
//Insert the enemy
ais.emplace_front(get_rand_cnt(),txture,cfg,Team(player?player->team().get_swapped():Team().get_swapped()));
//Configure it
AI_spaceship& new_ai=ais.front();
new_ai.set_enemy(player);
new_ai.put_lasers(&al);
new_ai.put_cannon(can);
new_ai.put_cannon_lasers(&al);
}
void Offline_Survival::clean()//Delete dead ships
{
for (auto it=ais.begin();it!=ais.end();)//Circle through the ships
{
if (it->alive())//Ignore the alive ones
++it;
else//Dead, notice and delete
{
//Notice
sf::Text new_text;
new_text.setString(fdx::menu::Language::getText(fdx::menu::Language::ENEMY_DIED));
new_text.setColor(teams.get_friendly());
texts.push_back(new_text);
//Delete
it=ais.erase(it);
now_cur--;
}
}
}
void Offline_Survival::update(unsigned int ticks)
{
if (end_game()) return;
while (need_add())
add_enemy();
clean();
al.mov(ticks);
if (player&&need_rev())
{
//Revive the player only if it has any lifes left
if (--now_lif)
player->revive_at(arrow::Vct(0,0));
sf::Text new_text;
new_text.setString(fdx::menu::Language::getText(fdx::menu::Language::YOU_DIED));
new_text.setColor(teams.get_enemy());
texts.push_back(new_text);
}
for (auto it=ais.begin();it!=ais.end();++it)
{
it->think();
it->play();
it->mov(ticks);
}
}
void Multi_DM::update(unsigned int ticks)
{
if (delay1)
{
if (ticks>delay1)
delay1=0;
else
delay1-=ticks;
}
if (delay2)
{
if (ticks>delay2)
delay2=0;
else
delay2-=ticks;
}
if (end_game())
{
if (!ended)
{
ended=true;
if (get_winner().friendly(player->team()))
{
sf::Text new_text;
new_text.setString(fdx::menu::Language::getText(fdx::menu::Language::WON));
new_text.setColor(teams.get_friendly());
texts.push_back(new_text);
sf::Text new_text2;
new_text2.setString(fdx::menu::Language::getText(fdx::menu::Language::LOSE));
new_text2.setColor(teams.get_enemy());
texts2.push_back(new_text2);
}
else
{
sf::Text new_text;
new_text.setString(fdx::menu::Language::getText(fdx::menu::Language::LOSE));
new_text.setColor(teams.get_enemy());
texts.push_back(new_text);
sf::Text new_text2;
new_text2.setString(fdx::menu::Language::getText(fdx::menu::Language::WON));
new_text2.setColor(teams.get_friendly());
texts2.push_back(new_text2);
}
}
}
al.mov(ticks);
rev_ships();
}
}}//End of namespace