Skip to content

Commit c955bd3

Browse files
committed
fix base attack screen.
tested and working and marvellous.
1 parent 0f3928f commit c955bd3

8 files changed

Lines changed: 176 additions & 94 deletions

File tree

src/Battlescape/BattlescapeGenerator.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -333,17 +333,6 @@ void BattlescapeGenerator::run()
333333
}
334334
else if (_base != 0)
335335
{
336-
// add vehicles that are in the crafts of the base, if it's not out
337-
for (std::vector<Craft*>::iterator c = _base->getCrafts()->begin(); c != _base->getCrafts()->end(); ++c)
338-
{
339-
if ((*c)->getStatus() != "STR_OUT")
340-
{
341-
for (std::vector<Vehicle*>::iterator i = (*c)->getVehicles()->begin(); i != (*c)->getVehicles()->end(); ++i)
342-
{
343-
addXCOMVehicle(*i);
344-
}
345-
}
346-
}
347336
// add vehicles that are in the base inventory
348337
for (std::vector<Vehicle*>::iterator i = _base->getVehicles()->begin(); i != _base->getVehicles()->end(); ++i)
349338
{

src/Battlescape/BriefingState.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,6 @@ BriefingState::BriefingState(Game *game, Craft *craft, Base *base, Ufo *ufo) : S
145145

146146
if (mission == "STR_BASE_DEFENSE")
147147
{
148-
// Mark as destroyed any way, to remove it from Geoscape.
149-
ufo->setStatus(Ufo::DESTROYED);
150148
// And make sure the base is unmarked.
151149
base->setRetaliationTarget(false);
152150
}

src/Battlescape/DebriefingState.cpp

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include <sstream>
5151
#include <map>
5252
#include "../Menu/MainMenuState.h"
53+
#include "../Engine/RNG.h"
5354

5455
namespace OpenXcom
5556
{
@@ -224,9 +225,11 @@ void DebriefingState::btnOkClick(Action *)
224225
{
225226
_game->getSavedGame()->setBattleGame(0);
226227
_game->popState();
228+
std::stringstream ss;
229+
ss << "GMGEO" << RNG::generate(1, 2);
230+
_game->getResourcePack()->getMusic(ss.str())->play();
227231
if (_game->getSavedGame()->getMonthsPassed() == -1)
228232
{
229-
//_game->popState();
230233
_game->setState(new MainMenuState(_game));
231234
}
232235
else if (!_destroyBase)
@@ -545,14 +548,30 @@ void DebriefingState::prepareDebriefing()
545548
}
546549
else
547550
{
548-
// non soldier player = tank
549-
for (std::vector<Vehicle*>::iterator i = craft->getVehicles()->begin(); i != craft->getVehicles()->end(); ++i)
551+
if (craft)
550552
{
551-
if ((*i)->getRules()->getType() == "STR_" + type)
553+
// non soldier player = tank
554+
for (std::vector<Vehicle*>::iterator i = craft->getVehicles()->begin(); i != craft->getVehicles()->end(); ++i)
552555
{
553-
delete (*i);
554-
craft->getVehicles()->erase(i);
555-
break;
556+
if ((*i)->getRules()->getType() == "STR_" + type)
557+
{
558+
delete (*i);
559+
craft->getVehicles()->erase(i);
560+
break;
561+
}
562+
}
563+
}
564+
else
565+
{
566+
// non soldier player = tank
567+
for (std::vector<Vehicle*>::iterator i = base->getVehicles()->begin(); i != base->getVehicles()->end(); ++i)
568+
{
569+
if ((*i)->getRules()->getType() == "STR_" + type)
570+
{
571+
delete (*i);
572+
base->getVehicles()->erase(i);
573+
break;
574+
}
556575
}
557576
}
558577
}

src/Geoscape/BaseDefenseState.cpp

Lines changed: 105 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ namespace OpenXcom
5454
BaseDefenseState::BaseDefenseState(Game *game, Base *base, Ufo *ufo) : State(game)
5555
{
5656
_base = base;
57+
_action = BDA_NONE;
58+
_row = -1;
59+
_passes = 0;
60+
_attacks = 0;
61+
_thinkcycles = 0;
5762
_ufo = ufo;
5863
// Create objects
5964
_window = new Window(this, 320, 200, 0, 0);
@@ -86,69 +91,115 @@ BaseDefenseState::BaseDefenseState(Game *game, Base *base, Ufo *ufo) : State(gam
8691
std::wstringstream ss;
8792
ss << _base->getName() << _game->getLanguage()->getString("STR_UNDER_ATTACK");
8893
_txtTitle->setText(ss.str());
94+
_txtInit->setVisible(false);
8995

9096
_txtInit->setColor(Palette::blockOffset(13)+10);
9197
_txtInit->setText(_game->getLanguage()->getString("STR_BASE_DEFENSES_INITIATED"));
9298

9399
_lstDefenses->setColor(Palette::blockOffset(13)+10);
94100
_lstDefenses->setColumns(3, 134, 70, 50);
101+
_gravShields = _base->getGravShields();
102+
_defenses = _base->getDefenses()->size();
103+
_nextEventTime = clock();
104+
}
105+
/**
106+
*
107+
*/
108+
BaseDefenseState::~BaseDefenseState()
109+
{
110+
}
95111

96-
int row = -1;
97-
for(int pass = 0; pass != _base->getGravShields()+1; ++pass)
112+
void BaseDefenseState::think()
113+
{
114+
if (_thinkcycles == -1 || clock() < _nextEventTime)
115+
return;
116+
117+
_nextEventTime = clock() + 750;
118+
119+
if (_thinkcycles == 1)
98120
{
99-
if(pass)
121+
_txtInit->setVisible(true);
122+
++_thinkcycles;
123+
return;
124+
}
125+
126+
if (_thinkcycles != -1)
127+
{
128+
++_thinkcycles;
129+
}
130+
131+
if (_thinkcycles > 1)
132+
{
133+
if (_action == BDA_DESTROY)
134+
{
135+
_lstDefenses->addRow(2, _game->getLanguage()->getString("STR_UFO_DESTROYED").c_str()," "," ");
136+
_game->getResourcePack()->getSoundSet("GEO.CAT")->getSound(11)->play();
137+
_action = BDA_END;
138+
return;
139+
}
140+
141+
if (_action == BDA_END)
142+
{
143+
_btnOk->setVisible(true);
144+
_thinkcycles = -1;
145+
return;
146+
}
147+
148+
if (_attacks == _defenses && _passes == _gravShields)
100149
{
101-
_lstDefenses->addRow(3, _game->getLanguage()->getString("STR_GRAV_SHIELD_REPELS_UFO").c_str(),"","");
102-
++row;
150+
_action = BDA_END;
151+
return;
103152
}
104-
for(std::vector<BaseFacility*>::iterator def = _base->getDefenses()->begin(); def != _base->getDefenses()->end(); ++def)
153+
else if (_attacks == _defenses && _passes < _gravShields)
105154
{
106-
delay();
107-
_lstDefenses->addRow(3, _game->getLanguage()->getString((*def)->getRules()->getType()).c_str(),"","");
108-
++row;
109-
delay();
110-
_lstDefenses->setCellText(row, 2, _game->getLanguage()->getString("STR_FIRING"));
111-
_game->getResourcePack()->getSoundSet("SAMPLE.CAT")->getSound((*def)->getRules()->getFireSound())->play();
112-
delay();
113-
if(RNG::generate(1, 100) > (*def)->getRules()->getHitRatio())
155+
_lstDefenses->addRow(3, _game->getLanguage()->getString("STR_GRAV_SHIELD_REPELS_UFO").c_str()," "," ");
156+
++_row;
157+
++_passes;
158+
_attacks = 0;
159+
return;
160+
}
161+
162+
163+
164+
BaseFacility* def = _base->getDefenses()->at(_attacks);
165+
166+
if (_action == BDA_NONE)
167+
{
168+
_lstDefenses->addRow(3, _game->getLanguage()->getString((def)->getRules()->getType()).c_str()," "," ");
169+
++_row;
170+
_action = BDA_FIRE;
171+
return;
172+
}
173+
174+
if (_action == BDA_FIRE)
175+
{
176+
_lstDefenses->setCellText(_row, 1, _game->getLanguage()->getString("STR_FIRING").c_str());
177+
_game->getResourcePack()->getSoundSet("GEO.CAT")->getSound((def)->getRules()->getFireSound())->play();
178+
_action = BDA_RESOLVE;
179+
return;
180+
}
181+
182+
if (_action == BDA_RESOLVE)
183+
{
184+
if (RNG::generate(0, 100) > (def)->getRules()->getHitRatio())
114185
{
115-
_lstDefenses->setCellText(row, 3, _game->getLanguage()->getString("STR_MISSED"));
186+
_lstDefenses->setCellText(_row, 2, _game->getLanguage()->getString("STR_MISSED").c_str());
116187
}
117188
else
118189
{
119-
_lstDefenses->setCellText(row, 3, _game->getLanguage()->getString("STR_HIT"));
120-
_game->getResourcePack()->getSoundSet("SAMPLE.CAT")->getSound((*def)->getRules()->getHitSound())->play();
121-
_ufo->setDamage(_ufo->getDamage() + (*def)->getRules()->getDefenseValue());
122-
if(_ufo->getStatus() == 3)
123-
{
124-
delay();
125-
_lstDefenses->addRow(3, _game->getLanguage()->getString("STR_UFO_DESTROYED").c_str(),"","");
126-
_game->getResourcePack()->getSoundSet("SAMPLE.CAT")->getSound(11)->play();
127-
continue;
128-
}
190+
_lstDefenses->setCellText(_row, 2, _game->getLanguage()->getString("STR_HIT").c_str());
191+
_game->getResourcePack()->getSoundSet("GEO.CAT")->getSound((def)->getRules()->getHitSound())->play();
192+
_ufo->setDamage(_ufo->getDamage() + (def)->getRules()->getDefenseValue());
129193
}
130-
}
131-
if(_ufo->getStatus() == 3)
132-
{
133-
continue;
194+
if (_ufo->getStatus() == Ufo::DESTROYED)
195+
_action = BDA_DESTROY;
196+
else
197+
_action = BDA_NONE;
198+
++_attacks;
199+
return;
134200
}
135201
}
136-
_btnOk->setVisible(true);
137-
}
138-
/**
139-
*
140-
*/
141-
BaseDefenseState::~BaseDefenseState()
142-
{
143202
}
144-
145-
/**
146-
* Resets the palette.
147-
*/
148-
void BaseDefenseState::init()
149-
{
150-
}
151-
152203
/**
153204
* Returns to the previous screen.
154205
* @param action Pointer to an action.
@@ -159,7 +210,6 @@ void BaseDefenseState::btnOkClick(Action *)
159210
_game->popState();
160211
if(_ufo->getStatus() != 3 && _base->getSoldiers())
161212
{
162-
_game->popState();
163213
if (_base->getSoldiers())
164214
{
165215
size_t month = _game->getSavedGame()->getMonthsPassed();
@@ -170,7 +220,6 @@ void BaseDefenseState::btnOkClick(Action *)
170220
bgame->setMissionType("STR_BASE_DEFENSE");
171221
BattlescapeGenerator bgen = BattlescapeGenerator(_game);
172222
bgen.setBase(_base);
173-
bgen.setUfo(_ufo);
174223
bgen.setAlienRace(_ufo->getAlienRace());
175224
bgen.setAlienItemlevel(_game->getRuleset()->getAlienItemLevels().at(month).at(RNG::generate(0,9)));
176225
bgen.run();
@@ -182,12 +231,15 @@ void BaseDefenseState::btnOkClick(Action *)
182231
_game->pushState(new BaseDestroyedState(_game, _base));
183232
}
184233
}
185-
}
186-
187-
void BaseDefenseState::delay()
188-
{
189-
clock_t start_time = clock();
190-
clock_t end_time = 500 + start_time;
191-
while(clock() != end_time);
234+
// destroy any way, to remove it from Geoscape.
235+
for (std::vector<Ufo*>::iterator i = _game->getSavedGame()->getUfos()->begin(); i != _game->getSavedGame()->getUfos()->end(); ++i)
236+
{
237+
if ((*i) == _ufo)
238+
{
239+
delete *i;
240+
_game->getSavedGame()->getUfos()->erase(i);
241+
break;
242+
}
243+
}
192244
}
193245
}

src/Geoscape/BaseDefenseState.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#define OPENXCOM_BASEDEFENSESTATE_H
2121

2222
#include "../Engine/State.h"
23+
#include <ctime>
2324

2425
namespace OpenXcom
2526
{
@@ -31,6 +32,8 @@ class Base;
3132
class Ufo;
3233
class TextList;
3334

35+
enum BaseDefenseActionType { BDA_NONE, BDA_FIRE, BDA_RESOLVE, BDA_DESTROY, BDA_END };
36+
3437
/**
3538
* Base Defense Screen for when ufos try to attack.
3639
*/
@@ -43,17 +46,18 @@ class BaseDefenseState : public State
4346
TextList *_lstDefenses;
4447
Base *_base;
4548
Ufo *_ufo;
49+
int _thinkcycles, _row, _passes, _gravShields, _defenses, _attacks;
50+
BaseDefenseActionType _action;
51+
clock_t _nextEventTime;
4652
public:
4753
/// Creates the Base Defense state.
4854
BaseDefenseState(Game *game, Base *base, Ufo *ufo);
4955
/// Cleans up the Base Defense state.
5056
~BaseDefenseState();
5157
/// Updates the palette.
52-
void init();
58+
void think();
5359
/// Handler for clicking the OK button.
5460
void btnOkClick(Action *action);
55-
/// wait half a second before next action
56-
void delay();
5761
};
5862

5963
}

src/Geoscape/GeoscapeState.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ void GeoscapeState::time5Seconds()
540540
// Game over if there are no more bases.
541541
if (_game->getSavedGame()->getBases()->size() == 0)
542542
{
543-
_game->pushState (new DefeatState(_game));
543+
popup(new DefeatState(_game));
544544
return;
545545
}
546546

@@ -573,11 +573,12 @@ void GeoscapeState::time5Seconds()
573573
if (Base *base = dynamic_cast<Base*>((*i)->getDestination()))
574574
{
575575
base->setInBattlescape(true);
576-
if (base->getDefenses())
576+
base->setupDefenses();
577+
if (base->getDefenses()->size() > 0)
577578
{
578579
popup(new BaseDefenseState(_game, base, *i));
579580
}
580-
else if (base->getSoldiers())
581+
else if (base->getSoldiers()->size() > 0)
581582
{
582583
size_t month = _game->getSavedGame()->getMonthsPassed();
583584
if (month > _game->getRuleset()->getAlienItemLevels().size()-1)

0 commit comments

Comments
 (0)