File: game_mode_editor.cpp

package info (click to toggle)
warmux 1%3A11.04.1%2Brepack2-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, sid
  • size: 126,388 kB
  • sloc: cpp: 186,040; xml: 8,909; sh: 3,358; makefile: 1,052; ansic: 713
file content (162 lines) | stat: -rw-r--r-- 7,082 bytes parent folder | download | duplicates (4)
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
/******************************************************************************
 *  Warmux is a convivial mass murder game.
 *  Copyright (C) 2001-2011 Warmux Team.
 *
 *  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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 ******************************************************************************
 * Game mode editor
 *****************************************************************************/

#include <vector>

#include "menu/game_mode_editor.h"

#include "game/config.h"
#include "game/game_mode.h"
#include "gui/combo_box.h"
#include "gui/question.h"
#include "gui/spin_button_picture.h"

const uint TPS_TOUR_MIN = 10;
const uint TPS_TOUR_MAX = 240;
static bool warned = false;

GameModeEditor::GameModeEditor(uint max_line_width, const Point2i& option_size, bool _draw_border) :
  GridBox(4, 4, 0, _draw_border)
{
  (void)max_line_width;
  // ################################################
  // ##  GAME OPTIONS
  // ################################################
  std::string selected_gamemode = Config::GetInstance()->GetGameMode();

  opt_game_mode = new ComboBox(_("Game mode"), "menu/game_mode", option_size,
                               GameMode::ListGameModes(), selected_gamemode);
  AddWidget(opt_game_mode);

  opt_duration_turn = new SpinButtonWithPicture(_("Duration of a turn"), "menu/timing_turn",
                                                option_size,
                                                TPS_TOUR_MIN, 10,
                                                TPS_TOUR_MIN, TPS_TOUR_MAX);
  AddWidget(opt_duration_turn);

  std::vector<std::pair<std::string, std::string> > character_selections;
  character_selections.push_back(std::pair<std::string, std::string>("always", _("Always")));
  character_selections.push_back(std::pair<std::string, std::string>("before_action", _("Before action")));
  character_selections.push_back(std::pair<std::string, std::string>("never", _("Never")));

  opt_allow_character_selection = new ComboBox(_("Character switching"),
                                               "menu/character_selection",
                                               option_size,
                                               character_selections, "always");
  AddWidget(opt_allow_character_selection);

  /* Characters energy */
  opt_energy_ini = new SpinButtonWithPicture(_("Initial energy"), "menu/init_energy",
                                             option_size,
                                             10, 10,
                                             10, 500);
  AddWidget(opt_energy_ini);

  opt_energy_max = new SpinButtonWithPicture(_("Max energy"), "menu/max_energy",
                                             option_size,
                                             10, 10,
                                             10, 500);
  AddWidget(opt_energy_max);


  /* some death mode options */

  opt_time_before_death_mode = new SpinButtonWithPicture(_("Duration before death mode"), "menu/timing_death",
                                                         option_size,
                                                         200, 50,
                                                         200, 3000);
  AddWidget(opt_time_before_death_mode);

  opt_damage_during_death_mode = new SpinButtonWithPicture(_("Damage per turn during death mode"),
                                                           "menu/death_energy",
                                                           option_size,
                                                           1, 1,
                                                           1, 20);
  AddWidget(opt_damage_during_death_mode);

  opt_gravity = new SpinButtonWithPicture(_("Gravity"), "menu/gravity",
                                          option_size,
                                          10, 5,
                                          10, 60);
  AddWidget(opt_gravity);

  LoadGameMode();
}

void GameModeEditor::LoadGameMode()
{
  std::string mode = opt_game_mode->GetValue();
  Config::GetInstance()->SetGameMode(mode);
  GameMode * game_mode = GameMode::GetInstance();
  game_mode->Load();

  if (game_mode->allow_character_selection == GameMode::ALWAYS) {
    opt_allow_character_selection->SetChoice(0); // "always"
  } else if (game_mode->allow_character_selection == GameMode::BEFORE_FIRST_ACTION) {
    opt_allow_character_selection->SetChoice(1); // "before_action"
  } else if (game_mode->allow_character_selection == GameMode::NEVER) {
    opt_allow_character_selection->SetChoice(2); // "never"
  } else {
    ASSERT(false);
  }

  opt_duration_turn->SetValue(game_mode->duration_turn, true);
  opt_energy_ini->SetValue(game_mode->character.init_energy, true);
  opt_energy_max->SetValue(game_mode->character.max_energy, true);
  opt_time_before_death_mode->SetValue(game_mode->duration_before_death_mode, true);
  opt_damage_during_death_mode->SetValue(game_mode->damage_per_turn_during_death_mode, true);
  opt_gravity->SetValue((int)(game_mode->gravity), true);

  NeedRedrawing();

  if (!warned && mode == "blitz") {
    Question puppy_attention_span(Question::WARNING);
    puppy_attention_span.Set(_("The blitz mode does not reset the time between each team turn. "
                               "A team looses when it has no players left or its time has ran out."),
                             true, 0);
    puppy_attention_span.Ask();
    warned = true;
  }
}

void GameModeEditor::ValidGameMode() const
{
  GameMode * game_mode = GameMode::GetInstance();
  game_mode->Load();

  if (opt_allow_character_selection->GetValue() == "always") {
    game_mode->allow_character_selection = GameMode::ALWAYS;
  } else if (opt_allow_character_selection->GetValue() == "before_action") {
    game_mode->allow_character_selection = GameMode::BEFORE_FIRST_ACTION;
  } else if (opt_allow_character_selection->GetValue() == "never") {
    game_mode->allow_character_selection = GameMode::NEVER;
  } else {
    ASSERT(false);
  }

  game_mode->duration_turn = opt_duration_turn->GetValue();
  game_mode->character.init_energy = opt_energy_ini->GetValue();
  game_mode->character.max_energy = opt_energy_max->GetValue();
  game_mode->duration_before_death_mode = opt_time_before_death_mode->GetValue();
  game_mode->damage_per_turn_during_death_mode = opt_damage_during_death_mode->GetValue();
  game_mode->gravity = opt_gravity->GetValue();
}