initial commit, lordsawar source, slightly modified
[lordsawar] / src / GameScenarioOptions.cpp
1 // Copyright (C) 2008 Ben Asselstine
2 //
3 //  This program is free software; you can redistribute it and/or modify
4 //  it under the terms of the GNU General Public License as published by
5 //  the Free Software Foundation; either version 3 of the License, or
6 //  (at your option) any later version.
7 //
8 //  This program is distributed in the hope that it will be useful,
9 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 //  GNU Library General Public License for more details.
12 //
13 //  You should have received a copy of the GNU General Public License
14 //  along with this program; if not, write to the Free Software
15 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
16 //  02110-1301, USA.
17
18 #include <iostream>
19 #include <fstream>
20 #include <stdlib.h>
21 #include <errno.h>
22 #include <sigc++/functors/mem_fun.h>
23
24 #include "GameScenarioOptions.h"
25
26 using namespace std;
27
28 #define debug(x) {cerr<<__FILE__<<": "<<__LINE__<<": "<<x<<endl<<flush;}
29 //#define debug(x)
30
31 bool GameScenarioOptions::s_see_opponents_stacks = false;
32 bool GameScenarioOptions::s_see_opponents_production = false;
33 GameParameters::QuestPolicy GameScenarioOptions::s_play_with_quests = GameParameters::ONE_QUEST_PER_PLAYER;
34 bool GameScenarioOptions::s_hidden_map = false;
35 bool GameScenarioOptions::s_diplomacy = false;
36 bool GameScenarioOptions::s_cusp_of_war = false;
37 GameParameters::NeutralCities GameScenarioOptions::s_neutral_cities = GameParameters::AVERAGE;
38 GameParameters::RazingCities GameScenarioOptions::s_razing_cities = GameParameters::ALWAYS;
39 bool GameScenarioOptions::s_intense_combat = false;
40 bool GameScenarioOptions::s_military_advisor = false;
41 bool GameScenarioOptions::s_random_turns = false;
42 bool GameScenarioOptions::s_surrender_already_offered = false;
43 unsigned int GameScenarioOptions::s_round = 0;
44
45 GameScenarioOptions::GameScenarioOptions()
46 {
47 }
48
49
50 GameScenarioOptions::~GameScenarioOptions()
51 {
52
53
54 int GameScenarioOptions::calculate_difficulty_rating(GameParameters g)
55 {
56   float total_difficulty = 0;
57   int max_player_difficulty = 73;
58   int players_on = 0;
59   for (std::vector<GameParameters::Player>::iterator it = g.players.begin(); 
60        it != g.players.end(); it++)
61     {
62       if ((*it).type != GameParameters::Player::OFF)
63         players_on++;
64
65     }
66   int players_off = g.players.size() - players_on;
67
68   //find out how much each player is worth
69   float player_difficulty;
70   player_difficulty = (float) max_player_difficulty / (float) players_off;
71   if (players_on != 0)
72     player_difficulty = (float)max_player_difficulty / (float)players_on;
73
74   //go through all players, adding up difficulty points for each
75   for (std::vector<GameParameters::Player>::iterator i = g.players.begin(); 
76        i != g.players.end(); i++)
77     {
78       if ((*i).type == GameParameters::Player::HUMAN || 
79           ((*i).type == GameParameters::Player::HARD))
80         total_difficulty += player_difficulty;
81       else if ((*i).type == GameParameters::Player::EASY)
82         total_difficulty += player_difficulty;
83       //FIXME: when the hard player gets better, switch this.
84       //total_difficulty += (player_difficulty * 0.325);
85       //else if ((*i).type == GameParameters::Player::EASIER)
86       //total_difficulty += (player_difficulty * 0.655);
87     }
88   if (g.diplomacy)
89     total_difficulty += (float) 3.0;
90   if (g.hidden_map)
91     total_difficulty += (float) 3.0;
92   if (g.play_with_quests)
93     total_difficulty += (float) 3.0;
94   if (g.see_opponents_production == false)
95     total_difficulty += (float) 2.0;
96   if (g.see_opponents_stacks == false)
97     total_difficulty += (float) 2.0;
98   if (g.neutral_cities == GameParameters::STRONG)
99     total_difficulty += (float) 3.0;
100   else if (g.neutral_cities == GameParameters::ACTIVE)
101     total_difficulty += (float) 5.0;
102   else if (g.neutral_cities == GameParameters::DEFENSIVE)
103     total_difficulty += (float) 6.0;
104   if (g.razing_cities == GameParameters::ON_CAPTURE)
105     total_difficulty += (float) 3.0;
106   else if (g.razing_cities == GameParameters::NEVER)
107     total_difficulty += (float) 6.0;
108   if (g.cusp_of_war == true)
109     total_difficulty += (float) 2.0;
110   return (int) total_difficulty;
111 }
112