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
|
/* HiringPanel.cpp
Copyright (c) 2014 by Michael Zahniser
Endless Sky 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 3 of the License, or (at your option) any later version.
Endless Sky 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, see <https://www.gnu.org/licenses/>.
*/
#include "HiringPanel.h"
#include "Command.h"
#include "GameData.h"
#include "Information.h"
#include "Interface.h"
#include "PlayerInfo.h"
#include "Screen.h"
#include "Ship.h"
#include "UI.h"
#include <algorithm>
using namespace std;
HiringPanel::HiringPanel(PlayerInfo &player)
: player(player), maxHire(0), maxFire(0)
{
SetTrapAllEvents(false);
}
void HiringPanel::Step()
{
DoHelp("hiring");
}
void HiringPanel::Draw()
{
const Ship *flagship = player.Flagship();
const Interface *hiring = GameData::Interfaces().Get(Screen::Width() < 1280 ? "hiring (small screen)" : "hiring");
Information info;
int flagshipBunks = 0;
int flagshipRequired = 0;
int flagshipExtra = 0;
int flagshipUnused = 0;
if(flagship)
{
flagshipBunks = flagship->Attributes().Get("bunks");
flagshipRequired = flagship->RequiredCrew();
flagshipExtra = flagship->Crew() - flagshipRequired;
flagshipUnused = flagshipBunks - flagship->Crew();
}
info.SetString("flagship bunks", to_string(flagshipBunks));
info.SetString("flagship required", to_string(flagshipRequired));
info.SetString("flagship extra", to_string(flagshipExtra));
info.SetString("flagship unused", to_string(flagshipUnused));
// Sum up the statistics for all your ships. You still pay the crew of
// disabled or out-of-system ships, but any parked ships have no crew costs.
int fleetBunks = 0;
int fleetRequired = 0;
for(const shared_ptr<Ship> &ship : player.Ships())
if(!ship->IsParked())
{
fleetBunks += static_cast<int>(ship->Attributes().Get("bunks"));
fleetRequired += ship->RequiredCrew();
}
int passengers = player.Cargo().Passengers();
int fleetUnused = fleetBunks - fleetRequired - flagshipExtra;
info.SetString("fleet bunks", to_string(fleetBunks));
info.SetString("fleet required", to_string(fleetRequired));
info.SetString("fleet unused", to_string(fleetUnused));
info.SetString("passengers", to_string(passengers));
static const int DAILY_SALARY = 100;
int salary = DAILY_SALARY * (fleetRequired - (flagship ? 1 : 0));
int extraSalary = DAILY_SALARY * flagshipExtra;
info.SetString("salary required", to_string(salary));
info.SetString("salary extra", to_string(extraSalary));
int modifier = Modifier();
if(modifier > 1)
info.SetString("modifier", "x " + to_string(modifier));
maxFire = max(flagshipExtra, 0);
maxHire = max(min(flagshipUnused, fleetUnused - passengers), 0);
if(maxHire)
info.SetCondition("can hire");
if(maxFire)
info.SetCondition("can fire");
hiring->Draw(info, this);
}
bool HiringPanel::KeyDown(SDL_Keycode key, Uint16 mod, const Command &command, bool isNewPress)
{
if(command.Has(Command::HELP))
{
DoHelp("hiring", true);
return true;
}
if(!player.Flagship())
return false;
if(key == 'h' || key == SDLK_EQUALS || key == SDLK_KP_PLUS || key == SDLK_PLUS
|| key == SDLK_RETURN || key == SDLK_SPACE)
{
player.Flagship()->AddCrew(min(maxHire, Modifier()));
player.UpdateCargoCapacities();
}
else if(key == 'f' || key == SDLK_MINUS || key == SDLK_KP_MINUS || key == SDLK_BACKSPACE || key == SDLK_DELETE)
{
player.Flagship()->AddCrew(-min(maxFire, Modifier()));
player.UpdateCargoCapacities();
}
else
return false;
UI::PlaySound(UI::UISound::NORMAL);
return true;
}
|