Code cleanup: Whitespaces at end of lines were removed.
This commit is contained in:
parent
bd46dc892a
commit
f4beaccabe
47 changed files with 434 additions and 434 deletions
22
actions.cpp
22
actions.cpp
|
@ -108,10 +108,10 @@ bool under_leadership(const std::map<gamemap::location,unit>& units,
|
|||
units.find(loc);
|
||||
if(un == units.end())
|
||||
return false;
|
||||
|
||||
|
||||
const int side = un->second.side();
|
||||
const int level = un->second.type().level();
|
||||
|
||||
|
||||
for(int i = 0; i != 6; ++i) {
|
||||
const std::map<gamemap::location,unit>::const_iterator it =
|
||||
units.find(adjacent[i]);
|
||||
|
@ -218,7 +218,7 @@ battle_stats evaluate_battle_stats(
|
|||
res.defend_with = defend != int(defender_attacks.size()) ? defend : -1;
|
||||
|
||||
const bool counterattack = defend != int(defender_attacks.size());
|
||||
|
||||
|
||||
static const std::string drain_string("drain");
|
||||
static const std::string magical_string("magical");
|
||||
|
||||
|
@ -231,7 +231,7 @@ battle_stats evaluate_battle_stats(
|
|||
res.damage_attacker_takes = int(double(
|
||||
a->second.damage_against(defender_attacks[defend]))
|
||||
* combat_modifier(state,units,d->first,d->second.type().alignment()));
|
||||
|
||||
|
||||
if(charge)
|
||||
res.damage_attacker_takes *= 2;
|
||||
|
||||
|
@ -268,12 +268,12 @@ battle_stats evaluate_battle_stats(
|
|||
//offensive marksman attacks always have at least 60% chance to hit
|
||||
if(res.chance_to_hit_defender < 0.6 && attack.special() == marksman_string)
|
||||
res.chance_to_hit_defender = 0.6;
|
||||
|
||||
|
||||
res.damage_defender_takes = int(
|
||||
double(d->second.damage_against(attack))
|
||||
* combat_modifier(state,units,a->first,a->second.type().alignment()))
|
||||
* (charge ? 2 : 1) * (backstab ? 2 : 1);
|
||||
|
||||
|
||||
if(under_leadership(units,attacker))
|
||||
res.damage_defender_takes += res.damage_defender_takes/8 + 1;
|
||||
|
||||
|
@ -315,7 +315,7 @@ void attack(display& gui, const gamemap& map,
|
|||
//if the attacker was invisible, she isn't anymore!
|
||||
static const std::string forest_invisible("ambush");
|
||||
a->second.remove_flag(forest_invisible);
|
||||
|
||||
|
||||
battle_stats stats = evaluate_battle_stats(map,attacker,defender,
|
||||
attack_with,units,state,info);
|
||||
|
||||
|
@ -472,7 +472,7 @@ std::map<gamemap::location,unit>::iterator
|
|||
{
|
||||
for(std::map<gamemap::location,unit>::iterator i = units.begin();
|
||||
i != units.end(); ++i) {
|
||||
if(i->second.side() == side && i->second.can_recruit())
|
||||
if(i->second.side() == side && i->second.can_recruit())
|
||||
return i;
|
||||
}
|
||||
|
||||
|
@ -494,7 +494,7 @@ void calculate_healing(display& disp, const gamemap& map,
|
|||
i->second.type().regenerates())) {
|
||||
healed_units.insert(std::pair<gamemap::location,int>(
|
||||
i->first, game_config::cure_amount));
|
||||
|
||||
|
||||
}
|
||||
|
||||
//otherwise find the maximum healing for the unit
|
||||
|
@ -552,7 +552,7 @@ void calculate_healing(display& disp, const gamemap& map,
|
|||
continue;
|
||||
|
||||
assert(units.find(adjacent[j]) != units.end());
|
||||
|
||||
|
||||
healed_units[adjacent[j]]
|
||||
= minimum(max_healing[adjacent[j]],
|
||||
healed_units[adjacent[j]]+healing_per_unit);
|
||||
|
@ -651,7 +651,7 @@ void calculate_healing(display& disp, const gamemap& map,
|
|||
disp.draw_tile(loc.x,loc.y,NULL,0.5,damage_colour);
|
||||
else
|
||||
disp.draw_tile(loc.x,loc.y);
|
||||
|
||||
|
||||
SDL_Delay(DelayAmount);
|
||||
disp.update_display();
|
||||
}
|
||||
|
|
60
ai.cpp
60
ai.cpp
|
@ -34,12 +34,12 @@ bool recruit(const gamemap& map, const gamemap::location& leader,
|
|||
{
|
||||
log_scope("recruiting troops");
|
||||
std::cerr << "recruiting " << usage << "\n";
|
||||
|
||||
|
||||
std::vector<std::map<std::string,unit_type>::const_iterator> options;
|
||||
|
||||
//record the number of the recruit for replay recording
|
||||
std::vector<int> option_numbers;
|
||||
|
||||
|
||||
//find an available unit that can be recruited, matches the desired
|
||||
//usage type, and comes in under budget
|
||||
const std::set<std::string>& recruits = tm.recruits();
|
||||
|
@ -62,7 +62,7 @@ bool recruit(const gamemap& map, const gamemap::location& leader,
|
|||
const unit_type& u = options[option]->second;
|
||||
tm.spend_gold(u.cost());
|
||||
unit new_unit(&u,team_num,true);
|
||||
|
||||
|
||||
std::cerr << "recruiting a " << u.name() << " for " << u.cost() << " have " << tm.gold() << " left\n";
|
||||
const gamemap::location loc;
|
||||
return recruit_unit(map,team_num,units,new_unit,loc,&disp).empty();
|
||||
|
@ -106,12 +106,12 @@ void move_unit(const game_data& gameinfo, display& disp,
|
|||
disp.set_paths(¤t_paths);
|
||||
|
||||
disp.scroll_to_tiles(from.x,from.y,to.x,to.y);
|
||||
|
||||
|
||||
unit current_unit = u_it->second;
|
||||
units.erase(u_it);
|
||||
|
||||
|
||||
const std::map<location,paths>::iterator p_it = possible_moves.find(from);
|
||||
|
||||
|
||||
if(p_it != possible_moves.end()) {
|
||||
paths& p = p_it->second;
|
||||
std::map<location,paths::route>::iterator rt = p.routes.begin();
|
||||
|
@ -127,7 +127,7 @@ void move_unit(const game_data& gameinfo, display& disp,
|
|||
disp.move_unit(steps,current_unit);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
current_unit.set_movement(0);
|
||||
units.insert(std::pair<location,unit>(to,current_unit));
|
||||
if(map[to.x][to.y] == gamemap::TOWER)
|
||||
|
@ -138,7 +138,7 @@ void move_unit(const game_data& gameinfo, display& disp,
|
|||
|
||||
game_events::fire("moveto",to);
|
||||
}
|
||||
|
||||
|
||||
void do_move(display& disp, const gamemap& map, const game_data& gameinfo,
|
||||
std::map<gamemap::location,unit>& units,
|
||||
std::vector<team>& teams, int team_num, const gamestatus& state,
|
||||
|
@ -151,9 +151,9 @@ void do_move(display& disp, const gamemap& map, const game_data& gameinfo,
|
|||
log_scope("doing ai move");
|
||||
|
||||
team& current_team = teams[team_num-1];
|
||||
|
||||
|
||||
typedef paths::route route;
|
||||
|
||||
|
||||
std::multimap<location,location> srcdst;
|
||||
std::multimap<location,location> dstsrc;
|
||||
|
||||
|
@ -161,7 +161,7 @@ void do_move(display& disp, const gamemap& map, const game_data& gameinfo,
|
|||
|
||||
typedef std::map<location,paths> moves_map;
|
||||
moves_map possible_moves;
|
||||
for(std::map<gamemap::location,unit>::const_iterator un_it = units.begin();
|
||||
for(std::map<gamemap::location,unit>::const_iterator un_it = units.begin();
|
||||
un_it != units.end(); ++un_it) {
|
||||
|
||||
if(un_it->second.side() != team_num) {
|
||||
|
@ -187,8 +187,8 @@ void do_move(display& disp, const gamemap& map, const game_data& gameinfo,
|
|||
un_it->first,paths(map,gameinfo,units,
|
||||
un_it->first,teams,ignore_zocs,teleports)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
for(moves_map::iterator m = possible_moves.begin();
|
||||
m != possible_moves.end(); ++m) {
|
||||
for(std::map<location,route>::iterator rtit =
|
||||
|
@ -203,7 +203,7 @@ void do_move(display& disp, const gamemap& map, const game_data& gameinfo,
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//no moves left, recruitment phase
|
||||
//take stock of our current set of units
|
||||
if(srcdst.empty()) {
|
||||
|
@ -220,7 +220,7 @@ void do_move(display& disp, const gamemap& map, const game_data& gameinfo,
|
|||
leader = i->first;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
unit_types[i->second.type().usage()]++;
|
||||
++num_units;
|
||||
}
|
||||
|
@ -231,7 +231,7 @@ void do_move(display& disp, const gamemap& map, const game_data& gameinfo,
|
|||
const int min_gold = 10 + (cash_flow < 0 ? -cash_flow*10 : 0);
|
||||
|
||||
//count the number of scouts we have currently
|
||||
|
||||
|
||||
const int towers = map.towers().size();
|
||||
int taken_towers = 0;
|
||||
for(int j = 0; j != teams.size(); ++j) {
|
||||
|
@ -239,7 +239,7 @@ void do_move(display& disp, const gamemap& map, const game_data& gameinfo,
|
|||
}
|
||||
|
||||
const int neutral_towers = towers - taken_towers;
|
||||
|
||||
|
||||
//we want at least one scout for every eight neutral towers
|
||||
int scouts_wanted = neutral_towers/8;
|
||||
if(scouts_wanted < 1)
|
||||
|
@ -259,13 +259,13 @@ void do_move(display& disp, const gamemap& map, const game_data& gameinfo,
|
|||
assert(false);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//buy fighters as long as we have room and can afford it
|
||||
while(recruit(map,leader,options[rand()%options.size()].c_str(),
|
||||
gameinfo,team_num,current_team,min_gold,units,disp)) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
recorder.end_turn();
|
||||
return;
|
||||
}
|
||||
|
@ -273,7 +273,7 @@ void do_move(display& disp, const gamemap& map, const game_data& gameinfo,
|
|||
int ticks = SDL_GetTicks();
|
||||
//look for targets of opportunity that we are hoping to kill this turn
|
||||
std::vector<attack_analysis> analysis;
|
||||
|
||||
|
||||
if(consider_combat)
|
||||
analysis = analyze_targets(map,srcdst,dstsrc,units,
|
||||
current_team,team_num,state,gameinfo);
|
||||
|
@ -282,7 +282,7 @@ void do_move(display& disp, const gamemap& map, const game_data& gameinfo,
|
|||
std::cout << "took " << time_taken << " ticks for " << analysis.size() << " positions. Analyzing...\n";
|
||||
|
||||
ticks = SDL_GetTicks();
|
||||
|
||||
|
||||
const int max_sims = 30000;
|
||||
int num_sims = analysis.empty() ? 0 : max_sims/analysis.size();
|
||||
if(num_sims < 8)
|
||||
|
@ -323,7 +323,7 @@ void do_move(display& disp, const gamemap& map, const game_data& gameinfo,
|
|||
const std::map<gamemap::location,unit>::const_iterator tgt =
|
||||
units.find(target_loc);
|
||||
|
||||
const bool defender_human = (tgt != units.end()) ?
|
||||
const bool defender_human = (tgt != units.end()) ?
|
||||
teams[tgt->second.side()-1].is_human() : false;
|
||||
|
||||
move_unit(gameinfo,disp,map,units,from,to,
|
||||
|
@ -351,7 +351,7 @@ void do_move(display& disp, const gamemap& map, const game_data& gameinfo,
|
|||
|
||||
dialogs::advance_unit(gameinfo,units,to,disp,true);
|
||||
dialogs::advance_unit(gameinfo,units,target_loc,disp,!defender_human);
|
||||
|
||||
|
||||
do_move(disp,map,gameinfo,units,teams,team_num,state,consider_combat,
|
||||
additional_targets);
|
||||
return;
|
||||
|
@ -382,13 +382,13 @@ void do_move(display& disp, const gamemap& map, const game_data& gameinfo,
|
|||
leader->second.set_movement(0);
|
||||
leader->second.set_attacked();
|
||||
}
|
||||
|
||||
|
||||
//remove leader from further consideration
|
||||
srcdst.erase(*lead);
|
||||
dstsrc.erase(*lead);
|
||||
}
|
||||
|
||||
//try to acquire towers
|
||||
//try to acquire towers
|
||||
for(std::multimap<location,location>::const_iterator i = dstsrc.begin();
|
||||
i != dstsrc.end(); ++i) {
|
||||
if(map[i->first.x][i->first.y] != gamemap::TOWER)
|
||||
|
@ -401,7 +401,7 @@ void do_move(display& disp, const gamemap& map, const game_data& gameinfo,
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(want_tower) {
|
||||
const std::map<location,unit>::iterator un = units.find(i->second);
|
||||
if(un == units.end()) {
|
||||
|
@ -459,7 +459,7 @@ void do_move(display& disp, const gamemap& map, const game_data& gameinfo,
|
|||
return;
|
||||
}
|
||||
|
||||
std::cout << "finding targets...\n";
|
||||
std::cout << "finding targets...\n";
|
||||
std::vector<target> targets = find_targets(map,units,teams,team_num);
|
||||
targets.insert(targets.end(),additional_targets->begin(),
|
||||
additional_targets->end());
|
||||
|
@ -477,7 +477,7 @@ void do_move(display& disp, const gamemap& map, const game_data& gameinfo,
|
|||
ittg != targets.end(); ++ittg) {
|
||||
assert(map.on_board(ittg->loc));
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(move.first.valid() == false)
|
||||
break;
|
||||
|
@ -495,7 +495,7 @@ void do_move(display& disp, const gamemap& map, const game_data& gameinfo,
|
|||
std::pair<Itor,Itor> del = dstsrc.equal_range(move.second);
|
||||
dstsrc.erase(del.first,del.second);
|
||||
}
|
||||
|
||||
|
||||
do_move(disp,map,gameinfo,units,teams,team_num,state,
|
||||
consider_combat,additional_targets);
|
||||
return;
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
namespace {
|
||||
|
||||
const int max_positions = 10000;
|
||||
|
||||
|
||||
using namespace ai;
|
||||
|
||||
void do_analysis(
|
||||
|
@ -51,10 +51,10 @@ void do_analysis(
|
|||
best_results[i] = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// if(result.size() > max_positions && !cur_analysis.movements.empty())
|
||||
// return;
|
||||
|
||||
|
||||
const double cur_rating = cur_analysis.movements.empty() ? 0 :
|
||||
cur_analysis.rating(0.0);
|
||||
|
||||
|
@ -69,11 +69,11 @@ void do_analysis(
|
|||
for(int i = 0; i != units.size(); ++i) {
|
||||
const location current_unit = units[i];
|
||||
units.erase(units.begin() + i);
|
||||
|
||||
|
||||
for(int j = 0; j != 6; ++j) {
|
||||
if(used_locations[j])
|
||||
continue;
|
||||
|
||||
|
||||
typedef std::multimap<location,location>::const_iterator Itor;
|
||||
std::pair<Itor,Itor> its = dstsrc.equal_range(tiles[j]);
|
||||
while(its.first != its.second) {
|
||||
|
@ -91,7 +91,7 @@ void do_analysis(
|
|||
cur_analysis.analyze(map,units_map,status,data,50);
|
||||
|
||||
if(cur_analysis.rating(0.0) > rating_to_beat) {
|
||||
|
||||
|
||||
result.push_back(cur_analysis);
|
||||
used_locations[j] = true;
|
||||
do_analysis(map,loc,srcdst,dstsrc,tiles,used_locations,
|
||||
|
@ -157,7 +157,7 @@ int choose_weapon(const gamemap& map, std::map<location,unit>& units,
|
|||
|
||||
if(cache_itor != weapon_choice_cache.end()) {
|
||||
assert(*cache_itor == battle);
|
||||
|
||||
|
||||
++cache_hits;
|
||||
cur_stats = cache_itor->stats;
|
||||
|
||||
|
@ -175,7 +175,7 @@ int choose_weapon(const gamemap& map, std::map<location,unit>& units,
|
|||
if((cache_misses%100) == 0) {
|
||||
std::cerr << "cache_stats: " << cache_hits << ":" << cache_misses << " " << weapon_choice_cache.size() << "\n";
|
||||
}
|
||||
|
||||
|
||||
int current_choice = -1;
|
||||
double current_rating = 0.0;
|
||||
const std::vector<attack_type>& attacks = itor->second.attacks();
|
||||
|
@ -243,8 +243,8 @@ void attack_analysis::analyze(const gamemap& map,
|
|||
const int weapon = choose_weapon(map,units,status,info,
|
||||
m->first,target, bat_stats,
|
||||
map[m->second.x][m->second.y]);
|
||||
|
||||
assert(weapon != -1);
|
||||
|
||||
assert(weapon != -1);
|
||||
weapons.push_back(weapon);
|
||||
|
||||
stats.push_back(bat_stats);
|
||||
|
@ -254,7 +254,7 @@ void attack_analysis::analyze(const gamemap& map,
|
|||
for(int j = 0; j != num_sims; ++j) {
|
||||
|
||||
int defenderxp = 0;
|
||||
|
||||
|
||||
int defhp = target_hp;
|
||||
for(int i = 0; i != movements.size() && defhp; ++i) {
|
||||
const battle_stats& stat = stats[i];
|
||||
|
@ -303,7 +303,7 @@ void attack_analysis::analyze(const gamemap& map,
|
|||
if(atthp > hitpoints[i])
|
||||
atthp = hitpoints[i];
|
||||
}
|
||||
|
||||
|
||||
--attacks;
|
||||
}
|
||||
|
||||
|
@ -329,7 +329,7 @@ void attack_analysis::analyze(const gamemap& map,
|
|||
--defends;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(defhp <= 0) {
|
||||
break;
|
||||
} else if(atthp == 0) {
|
||||
|
@ -342,7 +342,7 @@ void attack_analysis::analyze(const gamemap& map,
|
|||
}
|
||||
|
||||
defenderxp += (atthp == 0 ? 10:1)*att->second.type().level();
|
||||
|
||||
|
||||
avg_damage_taken += hitpoints[i] - atthp;
|
||||
}
|
||||
|
||||
|
@ -358,7 +358,7 @@ void attack_analysis::analyze(const gamemap& map,
|
|||
if(defhp > target_hp)
|
||||
defhp = target_hp;
|
||||
}
|
||||
|
||||
|
||||
avg_damage_inflicted += target_hp - defhp;
|
||||
}
|
||||
|
||||
|
@ -422,7 +422,7 @@ std::vector<attack_analysis> analyze_targets(
|
|||
analysis.target = j->first;
|
||||
|
||||
const int ticks = SDL_GetTicks();
|
||||
|
||||
|
||||
do_analysis(map,j->first,srcdst,dstsrc,adjacent,used_locations,
|
||||
unit_locs,units,res,data,status,analysis);
|
||||
|
||||
|
|
|
@ -23,24 +23,24 @@
|
|||
#include <vector>
|
||||
|
||||
namespace ai {
|
||||
|
||||
|
||||
struct attack_analysis
|
||||
{
|
||||
void analyze(const gamemap& map, std::map<location,unit>& units,
|
||||
const gamestatus& status, const game_data& info, int sims);
|
||||
|
||||
double rating(double aggression) const;
|
||||
|
||||
|
||||
gamemap::location target;
|
||||
std::vector<std::pair<gamemap::location,gamemap::location> > movements;
|
||||
std::vector<int> weapons;
|
||||
|
||||
|
||||
//the value of the unit being targeted
|
||||
double target_value;
|
||||
|
||||
//the value on average, of units lost in the combat
|
||||
double avg_losses;
|
||||
|
||||
|
||||
//estimated % chance to kill the unit
|
||||
double chance_to_kill;
|
||||
|
||||
|
|
20
ai_move.cpp
20
ai_move.cpp
|
@ -45,13 +45,13 @@ struct move_cost_calculator
|
|||
return 0.01;
|
||||
++range.first;
|
||||
}
|
||||
|
||||
|
||||
const gamemap::TERRAIN terrain =
|
||||
map_.underlying_terrain(map_[loc.x][loc.y]);
|
||||
|
||||
const double modifier = 1.0;//move_type_.defense_modifier(map_,terrain);
|
||||
const double move_cost = move_type_.movement_cost(map_,terrain);
|
||||
|
||||
|
||||
double enemies = 0;
|
||||
/* //is this stuff responsible for making it take a long time?
|
||||
location adj[7];
|
||||
|
@ -63,7 +63,7 @@ struct move_cost_calculator
|
|||
if(i == 0 && en != units_.end()) {
|
||||
return 1000.0;
|
||||
}
|
||||
|
||||
|
||||
if(en != units_.end() && en->second.side() == enemy_) {
|
||||
enemies += 1.0;
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ private:
|
|||
const unit_movement_type& move_type_;
|
||||
const gamemap::location loc_;
|
||||
const std::multimap<location,location> dstsrc_;
|
||||
|
||||
|
||||
};
|
||||
|
||||
std::vector<target> find_targets(
|
||||
|
@ -149,7 +149,7 @@ std::vector<target> find_targets(
|
|||
if(i->loc == j->loc) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
const double distance = abs(j->loc.x - i->loc.x) +
|
||||
abs(j->loc.y - i->loc.y);
|
||||
new_values.back() += j->value/(distance*distance);
|
||||
|
@ -180,14 +180,14 @@ std::pair<location,location> choose_move(
|
|||
for(ittg = targets.begin(); ittg != targets.end(); ++ittg) {
|
||||
assert(map.on_board(ittg->loc));
|
||||
}
|
||||
|
||||
|
||||
paths::route best_route;
|
||||
std::map<location,unit>::iterator best = units.end();
|
||||
double best_rating = 0.1;
|
||||
std::vector<target>::iterator best_target = targets.end();
|
||||
|
||||
std::map<location,unit>::iterator u;
|
||||
|
||||
|
||||
//find the first eligible unit
|
||||
for(u = units.begin(); u != units.end(); ++u) {
|
||||
if(!(u->second.side() != current_team || u->second.can_recruit() ||
|
||||
|
@ -231,7 +231,7 @@ std::pair<location,location> choose_move(
|
|||
std::cout << "no eligible targets found\n";
|
||||
return std::pair<location,location>();
|
||||
}
|
||||
|
||||
|
||||
//now see if any other unit can put a better bid forward
|
||||
for(++u; u != units.end(); ++u) {
|
||||
if(u->second.side() != current_team || u->second.can_recruit() ||
|
||||
|
@ -275,7 +275,7 @@ std::pair<location,location> choose_move(
|
|||
return std::pair<location,location>(its.first->second,
|
||||
its.first->first);
|
||||
}
|
||||
|
||||
|
||||
++its.first;
|
||||
}
|
||||
}
|
||||
|
@ -284,7 +284,7 @@ std::pair<location,location> choose_move(
|
|||
std::cout << "Could not make good move, staying still\n";
|
||||
return std::pair<location,location>(best->first,best->first);
|
||||
}
|
||||
|
||||
|
||||
std::cout << "Could not find anywhere to move!\n";
|
||||
return std::pair<location,location>();
|
||||
}
|
||||
|
|
18
config.cpp
18
config.cpp
|
@ -91,7 +91,7 @@ void internal_preprocess_file(const std::string& fname,
|
|||
if(c == '"') {
|
||||
in_quotes = !in_quotes;
|
||||
}
|
||||
|
||||
|
||||
if(c == '{') {
|
||||
std::stringstream newfile;
|
||||
for(++i; i != data.end() && *i != '}'; ++i) {
|
||||
|
@ -102,7 +102,7 @@ void internal_preprocess_file(const std::string& fname,
|
|||
break;
|
||||
|
||||
const std::string fname = newfile.str();
|
||||
|
||||
|
||||
//if this is a known pre-processing symbol, then we insert
|
||||
//it, otherwise we assume it's a file name to load
|
||||
if(defines_map.count(fname) != 0) {
|
||||
|
@ -151,7 +151,7 @@ void internal_preprocess_file(const std::string& fname,
|
|||
static const std::string hash_ifdef("#ifdef");
|
||||
static const std::string hash_else("#else");
|
||||
static const std::string hash_endif("#endif");
|
||||
|
||||
|
||||
if(data.end() - i > hash_ifdef.size() &&
|
||||
std::equal(hash_ifdef.begin(),hash_ifdef.end(),i)) {
|
||||
i += hash_ifdef.size();
|
||||
|
@ -197,7 +197,7 @@ void internal_preprocess_file(const std::string& fname,
|
|||
if(i == data.end())
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
for(; i != data.end() && *i != '\n'; ++i) {
|
||||
}
|
||||
|
||||
|
@ -281,14 +281,14 @@ void config::read(const std::string& data)
|
|||
std::stack<config*> elements;
|
||||
elements.push(this);
|
||||
element_names.push("");
|
||||
|
||||
|
||||
enum { ELEMENT_NAME, IN_ELEMENT, VARIABLE_NAME, VALUE }
|
||||
state = IN_ELEMENT;
|
||||
std::string var;
|
||||
std::string value;
|
||||
|
||||
bool in_quotes = false;
|
||||
|
||||
|
||||
for(std::string::const_iterator i = data.begin(); i != data.end(); ++i) {
|
||||
const char c = *i;
|
||||
switch(state) {
|
||||
|
@ -311,13 +311,13 @@ void config::read(const std::string& data)
|
|||
throw error("Unexpected terminating tag\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
state = IN_ELEMENT;
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
config* const new_config = new config();
|
||||
elements.top()->children[value].push_back(new_config);
|
||||
elements.push(new_config);
|
||||
|
|
|
@ -32,16 +32,16 @@ struct config
|
|||
~config();
|
||||
|
||||
config& operator=(const config& cfg);
|
||||
|
||||
|
||||
void read(const std::string& data); //throws config::error
|
||||
std::string write() const;
|
||||
|
||||
|
||||
std::map<std::string,std::string> values;
|
||||
std::map<std::string,std::vector<config*> > children;
|
||||
|
||||
static std::vector<std::string> split(const std::string& val);
|
||||
static bool has_value(const std::string& values, const std::string& val);
|
||||
|
||||
|
||||
void clear();
|
||||
|
||||
struct error {
|
||||
|
|
12
dialogs.cpp
12
dialogs.cpp
|
@ -39,18 +39,18 @@ void advance_unit(const game_data& info,
|
|||
}
|
||||
|
||||
int res = 0;
|
||||
|
||||
|
||||
if(options.empty()) {
|
||||
return;
|
||||
} else if(random_choice) {
|
||||
res = rand()%options.size();
|
||||
} else if(options.size() > 1) {
|
||||
|
||||
|
||||
res = gui::show_dialog(gui,NULL,string_table["advance_unit_heading"],
|
||||
string_table["advance_unit_message"],
|
||||
gui::OK_ONLY, &options, &sample_units);
|
||||
}
|
||||
|
||||
|
||||
//when the unit advances, it fades to white, and then switches to the
|
||||
//new unit, then fades back to the normal colour
|
||||
double intensity;
|
||||
|
@ -60,13 +60,13 @@ void advance_unit(const game_data& info,
|
|||
gui.update_display();
|
||||
SDL_Delay(30);
|
||||
}
|
||||
|
||||
|
||||
recorder.choose_option(res);
|
||||
|
||||
::advance_unit(info,units,loc,options[res]);
|
||||
|
||||
gui.invalidate_unit();
|
||||
|
||||
|
||||
for(intensity = 0.0; intensity <= 1.0; intensity += 0.05) {
|
||||
gui.set_advancing_unit(loc,intensity);
|
||||
gui.draw(false);
|
||||
|
@ -75,7 +75,7 @@ void advance_unit(const game_data& info,
|
|||
}
|
||||
|
||||
gui.set_advancing_unit(gamemap::location(),0.0);
|
||||
|
||||
|
||||
gui.invalidate_all();
|
||||
gui.draw();
|
||||
}
|
||||
|
|
156
display.cpp
156
display.cpp
|
@ -87,7 +87,7 @@ display::display(unit_map& units, CVideo& video, const gamemap& map,
|
|||
gameStatusRect_.w = 0;
|
||||
unitDescriptionRect_.w = 0;
|
||||
unitProfileRect_.w = 0;
|
||||
|
||||
|
||||
|
||||
//clear the screen contents
|
||||
SDL_Surface* const disp = screen_.getSurface();
|
||||
|
@ -146,7 +146,7 @@ gamemap::location display::hex_clicked_on(int xclick, int yclick)
|
|||
{
|
||||
if(xclick > mapx())
|
||||
return gamemap::location();
|
||||
|
||||
|
||||
const double xtile = xpos_/(zoom_*0.75) +
|
||||
static_cast<double>(xclick)/(zoom_*0.75) - 0.25;
|
||||
const double ytile = ypos_/zoom_ + static_cast<double>(yclick)/zoom_
|
||||
|
@ -247,7 +247,7 @@ void display::scroll_to_tile(int x, int y, SCROLL_TYPE scroll_type)
|
|||
const double divisor = static_cast<double>(num_moves);
|
||||
|
||||
double xdiff = 0.0, ydiff = 0.0;
|
||||
|
||||
|
||||
for(int i = 0; i != num_moves; ++i) {
|
||||
check_keys(*this);
|
||||
xdiff += xmove/divisor;
|
||||
|
@ -257,7 +257,7 @@ void display::scroll_to_tile(int x, int y, SCROLL_TYPE scroll_type)
|
|||
if((i%4) != 0 && i != num_moves-1 && turbo()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
scroll(xdiff,ydiff);
|
||||
draw();
|
||||
|
||||
|
@ -278,7 +278,7 @@ void display::scroll_to_tiles(int x1, int y1, int x2, int y2,
|
|||
const double xpos2 = static_cast<double>(x2)*zoom_*0.75 - xpos_;
|
||||
const double ypos2 = static_cast<double>(y2)*zoom_ - ypos_ +
|
||||
((x2 % 2) == 1 ? zoom_/2.0 : 0.0);
|
||||
|
||||
|
||||
const double diffx = fabs(xpos1 - xpos2);
|
||||
const double diffy = fabs(ypos1 - ypos2);
|
||||
|
||||
|
@ -297,7 +297,7 @@ void display::bounds_check_position()
|
|||
const double max_zoom = 200.0;
|
||||
|
||||
zoom_ = floor(zoom_);
|
||||
|
||||
|
||||
if(zoom_ < min_zoom)
|
||||
zoom_ = min_zoom;
|
||||
|
||||
|
@ -312,7 +312,7 @@ void display::bounds_check_position()
|
|||
|
||||
if(ypos_ + static_cast<double>(y()) > yend)
|
||||
ypos_ -= ypos_ + static_cast<double>(y()) - yend;
|
||||
|
||||
|
||||
if(xpos_ < 0.0)
|
||||
xpos_ = 0.0;
|
||||
|
||||
|
@ -379,10 +379,10 @@ void display::draw(bool update,bool force)
|
|||
if(wait_time > 0) {
|
||||
SDL_Delay(wait_time);
|
||||
}
|
||||
|
||||
|
||||
if(update) {
|
||||
lastDraw_ = SDL_GetTicks();
|
||||
|
||||
|
||||
if(wait_time >= 0 || drawSkips_ >= max_skips || force)
|
||||
update_display();
|
||||
else
|
||||
|
@ -395,9 +395,9 @@ void display::update_display()
|
|||
{
|
||||
if(updatesLocked_ > 0)
|
||||
return;
|
||||
|
||||
|
||||
for(std::vector<SDL_Rect>::const_iterator i = updateRects_.begin();
|
||||
i != updateRects_.end(); ++i) {
|
||||
i != updateRects_.end(); ++i) {
|
||||
screen_.update(i->x,i->y,i->w,i->h);
|
||||
}
|
||||
|
||||
|
@ -406,7 +406,7 @@ void display::update_display()
|
|||
|
||||
void display::draw_sidebar()
|
||||
{
|
||||
|
||||
|
||||
if(invalidateUnit_) {
|
||||
//we display the unit the mouse is over if it is over a unit
|
||||
//otherwise we display the unit that is selected
|
||||
|
@ -439,12 +439,12 @@ void display::draw_game_status(int x, int y)
|
|||
|
||||
const int bgcolour = 0;
|
||||
const int colour = 0xffffff;
|
||||
|
||||
|
||||
gamestatus::TIME timeofday = status_.timeofday();
|
||||
if(mouseoverHex_.valid()) {
|
||||
timeofday = timeofday_at(status_,units_,mouseoverHex_);
|
||||
}
|
||||
|
||||
|
||||
if(lastTimeOfDay_ != (int)timeofday) {
|
||||
lastTimeOfDay_ = (int)timeofday;
|
||||
|
||||
|
@ -486,7 +486,7 @@ void display::draw_game_status(int x, int y)
|
|||
}
|
||||
|
||||
const int income = teams_[currentTeam_].income() - nunits;
|
||||
|
||||
|
||||
std::stringstream details;
|
||||
details << string_table["turn"] << ": " << status_.turn() << "/"
|
||||
<< status_.number_of_turns() << "\n" << string_table["gold"] << ": "
|
||||
|
@ -512,7 +512,7 @@ void display::draw_game_status(int x, int y)
|
|||
const std::string& name1 = lang_name.empty() ? name : lang_name;
|
||||
const std::string& name2 = underlying_lang_name.empty() ?
|
||||
underlying_name : underlying_lang_name;
|
||||
|
||||
|
||||
if(name1 != name2)
|
||||
details << name1 << " (" << name2 << ")\n";
|
||||
else
|
||||
|
@ -566,7 +566,7 @@ void display::draw_unit_details(int x, int y, const gamemap::location& loc,
|
|||
SDL_BlitSurface(background,&srcrect,screen,&profile_rect);
|
||||
update_rect(profile_rect);
|
||||
}
|
||||
|
||||
|
||||
std::string status = string_table["healthy"];
|
||||
if(map_.on_board(loc) &&
|
||||
u.invisible(map_.underlying_terrain(map_[loc.x][loc.y]))) {
|
||||
|
@ -590,7 +590,7 @@ void display::draw_unit_details(int x, int y, const gamemap::location& loc,
|
|||
<< "\n-(" << string_table["level"] << ""
|
||||
<< u.type().level() << ")\n"
|
||||
<< status << "\n"
|
||||
<< unit_type::alignment_description(u.type().alignment())
|
||||
<< unit_type::alignment_description(u.type().alignment())
|
||||
<< "\n"
|
||||
<< u.traits_description() << "\n"
|
||||
<< (lang_ability.empty() ? u.type().ability() : lang_ability)<<"\n"
|
||||
|
@ -601,11 +601,11 @@ void display::draw_unit_details(int x, int y, const gamemap::location& loc,
|
|||
<< string_table["moves"] << ": " << u.movement_left() << "/"
|
||||
<< u.total_movement()
|
||||
<< "\n";
|
||||
|
||||
|
||||
const std::vector<attack_type>& attacks = u.attacks();
|
||||
for(std::vector<attack_type>::const_iterator at_it = attacks.begin();
|
||||
at_it != attacks.end(); ++at_it) {
|
||||
|
||||
|
||||
const std::string& lang_weapon
|
||||
= string_table["weapon_name_" + at_it->name()];
|
||||
const std::string& lang_type
|
||||
|
@ -613,7 +613,7 @@ void display::draw_unit_details(int x, int y, const gamemap::location& loc,
|
|||
const std::string& lang_special
|
||||
= string_table["weapon_special_" + at_it->special()];
|
||||
details << "\n"
|
||||
<< (lang_weapon.empty() ? at_it->name():lang_weapon) << " ("
|
||||
<< (lang_weapon.empty() ? at_it->name():lang_weapon) << " ("
|
||||
<< (lang_type.empty() ? at_it->type():lang_type) << ")\n"
|
||||
<< (lang_special.empty() ? at_it->special():lang_special)<<"\n"
|
||||
<< at_it->damage() << "-" << at_it->num_attacks() << " -- "
|
||||
|
@ -634,7 +634,7 @@ void display::draw_unit_details(int x, int y, const gamemap::location& loc,
|
|||
|
||||
if(profile == NULL)
|
||||
return;
|
||||
|
||||
|
||||
blit_surface(x,y,profile);
|
||||
|
||||
profile_rect.x = x;
|
||||
|
@ -700,7 +700,7 @@ void display::draw_minimap(int x, int y, int w, int h)
|
|||
const int yloc = y - north->h;
|
||||
|
||||
blit_surface(xloc, yloc, north);
|
||||
|
||||
|
||||
if(south != NULL) {
|
||||
blit_surface(xloc, y+h, south);
|
||||
}
|
||||
|
@ -736,7 +736,7 @@ void display::draw_minimap(int x, int y, int w, int h)
|
|||
|
||||
const int xbox = static_cast<int>(scaling*xpos_/(zoom_*0.75));
|
||||
const int ybox = static_cast<int>(scaling*ypos_/zoom_);
|
||||
|
||||
|
||||
const int wbox = static_cast<int>(scaling*mapx()/(zoom_*0.75) - scaling);
|
||||
const int hbox = static_cast<int>(scaling*this->y()/zoom_ - scaling);
|
||||
|
||||
|
@ -770,7 +770,7 @@ void display::draw_terrain_palette(int x, int y, gamemap::TERRAIN selected)
|
|||
invalid_rect.x = x;
|
||||
invalid_rect.y = y;
|
||||
invalid_rect.w = 0;
|
||||
|
||||
|
||||
SDL_Surface* const screen = screen_.getSurface();
|
||||
|
||||
std::vector<gamemap::TERRAIN> terrains = map_.get_terrain_precedence();
|
||||
|
@ -835,7 +835,7 @@ void display::draw_tile(int x, int y, SDL_Surface* unit_image,
|
|||
|
||||
if(xpos > mapx() || ypos > this->y())
|
||||
return;
|
||||
|
||||
|
||||
int xend = xpos + static_cast<int>(zoom_);
|
||||
int yend = int(get_location_y(gamemap::location(x,y+1)));
|
||||
|
||||
|
@ -887,7 +887,7 @@ void display::draw_tile(int x, int y, SDL_Surface* unit_image,
|
|||
terrain = map_[x][y];
|
||||
|
||||
IMAGE_TYPE image_type = SCALED;
|
||||
|
||||
|
||||
//find if this tile should be greyed
|
||||
if(pathsList_ != NULL && pathsList_->routes.find(gamemap::location(x,y)) ==
|
||||
pathsList_->routes.end()) {
|
||||
|
@ -897,7 +897,7 @@ void display::draw_tile(int x, int y, SDL_Surface* unit_image,
|
|||
units_.count(gamemap::location(x,y)) == 1) {
|
||||
image_type = BRIGHTENED;
|
||||
}
|
||||
|
||||
|
||||
int r = 0, g = 0, b = 0;
|
||||
|
||||
SDL_Surface* surface = getTerrain(terrain,image_type,x,y);
|
||||
|
@ -917,7 +917,7 @@ void display::draw_tile(int x, int y, SDL_Surface* unit_image,
|
|||
overlaps.push_back(overlay_surface);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int ysrc = 0, xsrc = 0;
|
||||
if(ypos < 0) {
|
||||
ysrc -= ypos;
|
||||
|
@ -941,7 +941,7 @@ void display::draw_tile(int x, int y, SDL_Surface* unit_image,
|
|||
SDL_Surface* energy_image = NULL;
|
||||
|
||||
double unit_energy = 0.0;
|
||||
|
||||
|
||||
const short energy_loss_colour = 0;
|
||||
short energy_colour = 0;
|
||||
|
||||
|
@ -974,7 +974,7 @@ void display::draw_tile(int x, int y, SDL_Surface* unit_image,
|
|||
energy_file = "moved-energy.png";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
energy_image = getImage(energy_file);
|
||||
unit_energy = double(it->second.hitpoints()) /
|
||||
double(it->second.max_hitpoints());
|
||||
|
@ -1014,7 +1014,7 @@ void display::draw_tile(int x, int y, SDL_Surface* unit_image,
|
|||
|
||||
face_left = it->second.facing_left();
|
||||
}
|
||||
|
||||
|
||||
const std::pair<int,int>& energy_bar_loc = calculate_energy_bar();
|
||||
double total_energy = double(energy_bar_loc.second - energy_bar_loc.first);
|
||||
|
||||
|
@ -1062,7 +1062,7 @@ void display::draw_tile(int x, int y, SDL_Surface* unit_image,
|
|||
const int neoffset = ne_xpos+ne_xoffset;
|
||||
const int seoffset = se_xpos+se_xoffset;
|
||||
const int minoffset = minimum<int>(neoffset,seoffset);
|
||||
|
||||
|
||||
//FIXME: make it work with ne_ypos being <= 0
|
||||
if(ne_ypos > 0 && xdst + len >= neoffset) {
|
||||
len = neoffset - xdst;
|
||||
|
@ -1073,7 +1073,7 @@ void display::draw_tile(int x, int y, SDL_Surface* unit_image,
|
|||
if(len < 0)
|
||||
len = 0;
|
||||
}
|
||||
|
||||
|
||||
const int srcy = minimum<int>(yloc,surface->h-1);
|
||||
short* startsrc = reinterpret_cast<short*>(surface->pixels) +
|
||||
srcy*(surface->w+xpad) + (xoffset > xsrc ? xoffset:xsrc);
|
||||
|
@ -1150,7 +1150,7 @@ void display::draw_tile(int x, int y, SDL_Surface* unit_image,
|
|||
0x0001 : 0xFFFF;
|
||||
highlight_ratio = advancingAmount_;
|
||||
}
|
||||
|
||||
|
||||
draw_unit(xpos-xsrc,ypos-ysrc,unit_image,face_left,false,
|
||||
highlight_ratio,blend_with);
|
||||
}
|
||||
|
@ -1160,7 +1160,7 @@ void display::draw_tile(int x, int y, SDL_Surface* unit_image,
|
|||
for(j = ypos; j != yend; ++j) {
|
||||
const int yloc = ysrc+j-ypos;
|
||||
const int xoffset = abs(yloc - static_cast<int>(zoom_/2.0))/2;
|
||||
|
||||
|
||||
int xdst = xpos;
|
||||
if(xoffset > xsrc) {
|
||||
xdst += xoffset - xsrc;
|
||||
|
@ -1173,16 +1173,16 @@ void display::draw_tile(int x, int y, SDL_Surface* unit_image,
|
|||
|
||||
short* startdst =
|
||||
reinterpret_cast<short*>(dst->pixels) + j*dst->w + xdst;
|
||||
|
||||
|
||||
const Pixel replace_energy =
|
||||
Pixel(SDL_MapRGB(energy_image->format,0xFF,0xFF,0xFF));
|
||||
const short new_energy = yloc >= show_energy_after ?
|
||||
energy_colour : energy_loss_colour;
|
||||
|
||||
|
||||
const int skip = yloc >= energy_bar_loc.first ? skip_energy_rows:0;
|
||||
|
||||
short* startenergy = NULL;
|
||||
|
||||
|
||||
const int energy_w = energy_image->w + ((energy_image->w%2) == 1 ? 1:0);
|
||||
if(yloc + skip < energy_image->h) {
|
||||
startenergy = reinterpret_cast<short*>(energy_image->pixels) +
|
||||
|
@ -1206,7 +1206,7 @@ void display::draw_tile(int x, int y, SDL_Surface* unit_image,
|
|||
}
|
||||
}
|
||||
|
||||
++startdst;
|
||||
++startdst;
|
||||
|
||||
if(startenergy != NULL)
|
||||
++startenergy;
|
||||
|
@ -1240,7 +1240,7 @@ std::vector<SDL_Surface*> display::getAdjacentTerrain(int x, int y,
|
|||
gamemap::location loc(x,y);
|
||||
|
||||
const gamemap::TERRAIN current_terrain = map_.on_board(loc) ? map_[x][y]:0;
|
||||
|
||||
|
||||
std::vector<bool> done(true,6);
|
||||
gamemap::location adjacent[6];
|
||||
get_adjacent_tiles(loc,adjacent);
|
||||
|
@ -1250,7 +1250,7 @@ std::vector<SDL_Surface*> display::getAdjacentTerrain(int x, int y,
|
|||
(int)map_[adjacent[i].x][adjacent[i].y] :
|
||||
(int)gamemap::VOID_TERRAIN;
|
||||
}
|
||||
|
||||
|
||||
const std::vector<gamemap::TERRAIN>& precedence =
|
||||
map_.get_terrain_precedence();
|
||||
std::vector<gamemap::TERRAIN>::const_iterator terrain =
|
||||
|
@ -1260,7 +1260,7 @@ std::vector<SDL_Surface*> display::getAdjacentTerrain(int x, int y,
|
|||
terrain = precedence.begin();
|
||||
else
|
||||
++terrain;
|
||||
|
||||
|
||||
for(; terrain != precedence.end(); ++terrain){
|
||||
//find somewhere that doesn't have overlap to use as a starting point
|
||||
int start;
|
||||
|
@ -1353,24 +1353,24 @@ void display::blit_surface(int x, int y, SDL_Surface* surface)
|
|||
|
||||
SDL_LockSurface(surface);
|
||||
SDL_LockSurface(target);
|
||||
|
||||
|
||||
if(x < 0)
|
||||
x = 0;
|
||||
|
||||
if(y < 0)
|
||||
y = 0;
|
||||
|
||||
|
||||
//lines are padded to always fit on 4-byte boundaries, so see if there
|
||||
//is padding at the beginning of every line
|
||||
const int padding = (surface->w%2) == 1 ? 1:0;
|
||||
const int surface_width = surface->w + padding;
|
||||
|
||||
|
||||
const short* src = reinterpret_cast<short*>(surface->pixels) +
|
||||
srcy*surface_width + srcx;
|
||||
short* dst = reinterpret_cast<short*>(target->pixels) + y*target->w + x;
|
||||
|
||||
static const short transperant = 0;
|
||||
|
||||
|
||||
for(int i = 0; i != srch; ++i) {
|
||||
const short* s = src + i*surface_width + padding;
|
||||
const short* const end = s + srcw;
|
||||
|
@ -1379,7 +1379,7 @@ void display::blit_surface(int x, int y, SDL_Surface* surface)
|
|||
if(*s != transperant) {
|
||||
*d = *s;
|
||||
}
|
||||
|
||||
|
||||
++s;
|
||||
++d;
|
||||
}
|
||||
|
@ -1395,9 +1395,9 @@ SDL_Surface* display::getImage(const std::string& filename,
|
|||
return getImageTinted(filename,GREY_IMAGE);
|
||||
else if(type == BRIGHTENED)
|
||||
return getImageTinted(filename,BRIGHTEN_IMAGE);
|
||||
|
||||
|
||||
std::map<std::string,SDL_Surface*>::iterator i;
|
||||
|
||||
|
||||
if(type == SCALED) {
|
||||
i = scaledImages_.find(filename);
|
||||
if(i != scaledImages_.end())
|
||||
|
@ -1446,7 +1446,7 @@ SDL_Surface* display::getImage(const std::string& filename,
|
|||
|
||||
if(new_surface == NULL)
|
||||
return NULL;
|
||||
|
||||
|
||||
scaledImages_.insert(std::pair<std::string,SDL_Surface*>(filename,
|
||||
new_surface));
|
||||
return new_surface;
|
||||
|
@ -1456,27 +1456,27 @@ SDL_Surface* display::getImageTinted(const std::string& filename, TINT tint)
|
|||
{
|
||||
std::map<std::string,SDL_Surface*>& image_map =
|
||||
tint == GREY_IMAGE ? greyedImages_ : brightenedImages_;
|
||||
|
||||
|
||||
const std::map<std::string,SDL_Surface*>::iterator itor =
|
||||
image_map.find(filename);
|
||||
|
||||
if(itor != image_map.end())
|
||||
return itor->second;
|
||||
|
||||
|
||||
SDL_Surface* const base = getImage(filename,SCALED);
|
||||
if(base == NULL)
|
||||
return NULL;
|
||||
|
||||
SDL_Surface* const surface =
|
||||
SDL_Surface* const surface =
|
||||
SDL_CreateRGBSurface(SDL_SWSURFACE,base->w,base->h,
|
||||
base->format->BitsPerPixel,
|
||||
base->format->Rmask,
|
||||
base->format->Gmask,
|
||||
base->format->Bmask,
|
||||
base->format->Amask);
|
||||
|
||||
|
||||
image_map.insert(std::pair<std::string,SDL_Surface*>(filename,surface));
|
||||
|
||||
|
||||
short* begin = reinterpret_cast<short*>(base->pixels);
|
||||
const short* const end = begin + base->h*(base->w + (base->w%2));
|
||||
short* dest = reinterpret_cast<short*>(surface->pixels);
|
||||
|
@ -1484,17 +1484,17 @@ SDL_Surface* display::getImageTinted(const std::string& filename, TINT tint)
|
|||
const int rmax = 0xFF;
|
||||
const int gmax = 0xFF;
|
||||
const int bmax = 0xFF;
|
||||
|
||||
|
||||
while(begin != end) {
|
||||
Uint8 red, green, blue;
|
||||
SDL_GetRGB(*begin,base->format,&red,&green,&blue);
|
||||
int r = int(red), g = int(green), b = int(blue);
|
||||
|
||||
|
||||
if(tint == GREY_IMAGE) {
|
||||
const double greyscale = (double(r)/(double)rmax +
|
||||
double(g)/(double)gmax +
|
||||
double(b)/(double)bmax)/3.0;
|
||||
|
||||
|
||||
r = int(rmax*greyscale);
|
||||
g = int(gmax*greyscale);
|
||||
b = int(bmax*greyscale);
|
||||
|
@ -1540,7 +1540,7 @@ SDL_Surface* display::getMinimap(int w, int h)
|
|||
short* data = reinterpret_cast<short*>(minimap_->pixels);
|
||||
for(int y = 0; y != map_.y(); ++y) {
|
||||
for(int x = 0; x != map_.x(); ++x) {
|
||||
|
||||
|
||||
*data = map_.get_terrain_info(map_[x][y]).get_rgb().
|
||||
format(surface->format);
|
||||
++data;
|
||||
|
@ -1617,7 +1617,7 @@ bool display::unit_attack_ranged(const gamemap::location& a,
|
|||
const int begin_at = attack.get_first_frame();
|
||||
const int end_at = maximum((damage+1)*time_resolution+missile_impact,
|
||||
maximum(attack.get_last_frame(),real_last_missile));
|
||||
|
||||
|
||||
const double xsrc = get_location_x(a);
|
||||
const double ysrc = get_location_y(a);
|
||||
const double xdst = get_location_x(b);
|
||||
|
@ -1625,7 +1625,7 @@ bool display::unit_attack_ranged(const gamemap::location& a,
|
|||
|
||||
gamemap::location update_tiles[6];
|
||||
get_adjacent_tiles(a,update_tiles);
|
||||
|
||||
|
||||
const bool vflip = b.y > a.y || b.y == a.y && (a.x%2) == 0;
|
||||
const bool hflip = b.x < a.x;
|
||||
const attack_type::FRAME_DIRECTION dir =
|
||||
|
@ -1692,7 +1692,7 @@ bool display::unit_attack_ranged(const gamemap::location& a,
|
|||
|
||||
const std::string* missile_image
|
||||
= attack.get_frame(missile_frame,attack_type::MISSILE_FRAME,dir);
|
||||
|
||||
|
||||
static const std::string default_missile("missile-n.png");
|
||||
static const std::string default_diag_missile("missile-ne.png");
|
||||
if(missile_image == NULL) {
|
||||
|
@ -1713,13 +1713,13 @@ bool display::unit_attack_ranged(const gamemap::location& a,
|
|||
draw_unit(xpos,ypos,img,!hflip,vflip);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const int wait_time = ticks + time_resolution - SDL_GetTicks();
|
||||
if(wait_time > 0 && !turbo() && !update_locked())
|
||||
SDL_Delay(wait_time);
|
||||
|
||||
ticks = SDL_GetTicks();
|
||||
|
||||
|
||||
update_display();
|
||||
}
|
||||
|
||||
|
@ -1827,7 +1827,7 @@ bool display::unit_attack(const gamemap::location& a,
|
|||
for(int j = 0; j != 6; ++j) {
|
||||
draw_tile(update_tiles[j].x,update_tiles[j].y);
|
||||
}
|
||||
|
||||
|
||||
int defender_colour = 0;
|
||||
double defender_alpha = 1.0;
|
||||
|
||||
|
@ -1848,7 +1848,7 @@ bool display::unit_attack(const gamemap::location& a,
|
|||
}
|
||||
|
||||
draw_tile(b.x,b.y,NULL,defender_alpha,defender_colour);
|
||||
|
||||
|
||||
const std::string* unit_image = attack.get_frame(i);
|
||||
if(unit_image == NULL)
|
||||
unit_image = &attacker.image();
|
||||
|
@ -1868,7 +1868,7 @@ bool display::unit_attack(const gamemap::location& a,
|
|||
SDL_Delay(wait_time);
|
||||
|
||||
ticks = SDL_GetTicks();
|
||||
|
||||
|
||||
update_display();
|
||||
}
|
||||
|
||||
|
@ -1968,7 +1968,7 @@ void display::move_unit_between(const gamemap::location& a,
|
|||
if(wait_time > 0 && !turbo()) {
|
||||
SDL_Delay(wait_time);
|
||||
}
|
||||
|
||||
|
||||
ticks = SDL_GetTicks();
|
||||
|
||||
if(wait_time >= 0 || skips == 4 || (i+1.0) >= nsteps) {
|
||||
|
@ -1992,11 +1992,11 @@ void display::draw_unit(int x, int y, const SDL_Surface* image,
|
|||
const int h = this->y()-1;
|
||||
if(x > w || y > h)
|
||||
return;
|
||||
|
||||
|
||||
const int image_w = image->w + ((image->w%2) == 1 ? 1 : 0);
|
||||
|
||||
|
||||
SDL_Surface* const screen = screen_.getSurface();
|
||||
|
||||
|
||||
const Pixel* src = reinterpret_cast<const short*>(image->pixels);
|
||||
|
||||
const int endy = (y + image->h) < h ? (y + image->h) : h;
|
||||
|
@ -2005,7 +2005,7 @@ void display::draw_unit(int x, int y, const SDL_Surface* image,
|
|||
return;
|
||||
|
||||
const int len = endx - x;
|
||||
|
||||
|
||||
if(y < 0) {
|
||||
//this is adding to src, since y is negative
|
||||
src -= image_w*y;
|
||||
|
@ -2082,7 +2082,7 @@ const std::pair<int,int>& display::calculate_energy_bar()
|
|||
|
||||
int first_row = -1;
|
||||
int last_row = -1;
|
||||
|
||||
|
||||
const SDL_Surface* const image = getImage("unmoved-energy.png");
|
||||
const short* const begin = reinterpret_cast<short*>(image->pixels);
|
||||
|
||||
|
@ -2179,7 +2179,7 @@ struct inside_rect {
|
|||
|
||||
inside_rect(const SDL_Rect& a) : a(a)
|
||||
{}
|
||||
|
||||
|
||||
bool operator()(const SDL_Rect& b) const
|
||||
{
|
||||
if(a.x <= b.x && a.y <= b.y && a.x+a.w >= b.x+b.w && a.y+a.h >= b.y+b.h)
|
||||
|
@ -2196,7 +2196,7 @@ struct outside_rect {
|
|||
|
||||
outside_rect(const SDL_Rect& b) : b(b)
|
||||
{}
|
||||
|
||||
|
||||
bool operator()(const SDL_Rect& a) const
|
||||
{
|
||||
if(a.x <= b.x && a.y <= b.y && a.x+a.w >= b.x+b.w && a.y+a.h >= b.y+b.h)
|
||||
|
@ -2215,7 +2215,7 @@ void display::update_rect(const SDL_Rect& rect)
|
|||
if(std::find_if(updateRects_.begin(),updateRects_.end(),outside_rect(rect))
|
||||
!= updateRects_.end())
|
||||
return;
|
||||
|
||||
|
||||
updateRects_.push_back(rect);
|
||||
}
|
||||
|
||||
|
@ -2272,4 +2272,4 @@ void display::debug_highlight(const gamemap::location& loc, double amount)
|
|||
void display::clear_debug_highlights()
|
||||
{
|
||||
debugHighlights_.clear();
|
||||
}
|
||||
}
|
||||
|
|
20
display.hpp
20
display.hpp
|
@ -32,7 +32,7 @@ class display
|
|||
public:
|
||||
typedef std::map<gamemap::location,unit> unit_map;
|
||||
typedef short Pixel;
|
||||
|
||||
|
||||
display(unit_map& units, CVideo& video,
|
||||
const gamemap& map, const gamestatus& status,
|
||||
const std::vector<team>& t);
|
||||
|
@ -48,7 +48,7 @@ public:
|
|||
void scroll_to_tile(int x, int y, SCROLL_TYPE scroll_type=SCROLL);
|
||||
void scroll_to_tiles(int x1, int y1, int x2, int y2,
|
||||
SCROLL_TYPE scroll_type=SCROLL);
|
||||
|
||||
|
||||
void redraw_everything();
|
||||
void draw(bool update=true,bool force=false);
|
||||
|
||||
|
@ -73,13 +73,13 @@ public:
|
|||
double alpha=1.0, short blend_to=0);
|
||||
|
||||
CVideo& video() { return screen_; }
|
||||
|
||||
|
||||
enum IMAGE_TYPE { UNSCALED, SCALED, GREYED, BRIGHTENED };
|
||||
SDL_Surface* getImage(const std::string& filename,IMAGE_TYPE type=SCALED);
|
||||
|
||||
//blits a surface with black as alpha
|
||||
void blit_surface(int x, int y, SDL_Surface* surface);
|
||||
|
||||
|
||||
void invalidate_all();
|
||||
void invalidate_game_status();
|
||||
void invalidate_unit();
|
||||
|
@ -112,11 +112,11 @@ public:
|
|||
|
||||
static void debug_highlight(const gamemap::location& loc, double amount);
|
||||
static void clear_debug_highlights();
|
||||
|
||||
|
||||
private:
|
||||
display(const display&);
|
||||
void operator=(const display&);
|
||||
|
||||
|
||||
void move_unit_between(const gamemap::location& a,
|
||||
const gamemap::location& b,
|
||||
const unit& u);
|
||||
|
@ -130,7 +130,7 @@ private:
|
|||
bool unit_attack_ranged(const gamemap::location& a,
|
||||
const gamemap::location& b,
|
||||
int damage, const attack_type& attack);
|
||||
|
||||
|
||||
void draw_sidebar();
|
||||
SDL_Rect get_minimap_location(int x, int y, int w, int h);
|
||||
void draw_minimap(int x, int y, int w, int h);
|
||||
|
@ -153,7 +153,7 @@ private:
|
|||
SDL_Surface* getMinimap(int w, int h);
|
||||
|
||||
void clearImageCache();
|
||||
|
||||
|
||||
CVideo& screen_;
|
||||
mutable CKey keys_;
|
||||
double xpos_, ypos_, zoom_;
|
||||
|
@ -166,12 +166,12 @@ private:
|
|||
|
||||
std::map<std::string,SDL_Surface*> images_, scaledImages_,
|
||||
greyedImages_, brightenedImages_;
|
||||
|
||||
|
||||
//function which finds the start and end rows on the energy bar image
|
||||
//where white pixels are substituted for the colour of the energy
|
||||
const std::pair<int,int>& calculate_energy_bar();
|
||||
std::pair<int,int> energy_bar_count_;
|
||||
|
||||
|
||||
SDL_Surface* minimap_;
|
||||
bool minimapDecorationsDrawn_;
|
||||
|
||||
|
|
6
font.cpp
6
font.cpp
|
@ -103,7 +103,7 @@ SDL_Rect draw_text_line(display* gui, const SDL_Rect& area, int size,
|
|||
res.x = 0; res.y = 0; res.w = 0; res.h = 0;
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
SDL_Surface* const surface = TTF_RenderText_Blended(font,text.c_str(),col);
|
||||
if(surface == NULL) {
|
||||
std::cerr << "Could not render ttf: '" << text << "'\n";
|
||||
|
@ -117,7 +117,7 @@ SDL_Rect draw_text_line(display* gui, const SDL_Rect& area, int size,
|
|||
dest.y = y;
|
||||
dest.w = surface->w;
|
||||
dest.h = surface->h;
|
||||
|
||||
|
||||
if(dest.x + dest.w > area.x + area.w) {
|
||||
dest.w = area.x + area.w - dest.x;
|
||||
}
|
||||
|
@ -173,7 +173,7 @@ SDL_Rect draw_text(display* gui, const SDL_Rect& area, int size,
|
|||
sz -= 2;
|
||||
++i1;
|
||||
}
|
||||
|
||||
|
||||
if(i1 != i2) {
|
||||
const std::string new_string(i1,i2);
|
||||
const SDL_Rect rect =
|
||||
|
|
18
game.cpp
18
game.cpp
|
@ -82,7 +82,7 @@ LEVEL_RESULT play_game(display& disp, game_state& state, config& game_config,
|
|||
return QUIT;
|
||||
} catch(gamestatus::game_error& e) {
|
||||
std::cerr << "An error occurred while playing the game: "
|
||||
<< e.message << "\n";
|
||||
<< e.message << "\n";
|
||||
return QUIT;
|
||||
} catch(gamemap::incorrect_format_exception& e) {
|
||||
std::cerr << "The game map could not be loaded: " << e.msg_ << "\n";
|
||||
|
@ -112,7 +112,7 @@ LEVEL_RESULT play_game(display& disp, game_state& state, config& game_config,
|
|||
if(i+1 < scenarios.size()) {
|
||||
state.label = scenarios[i+1]->values["name"];
|
||||
state.scenario = i+1;
|
||||
|
||||
|
||||
const int should_save = gui::show_dialog(disp,NULL,"",
|
||||
string_table["save_game_message"],
|
||||
gui::YES_NO,NULL,NULL,
|
||||
|
@ -140,7 +140,7 @@ int play_game(int argc, char** argv)
|
|||
std::map<std::string,std::string> defines_map;
|
||||
defines_map["NORMAL"] = "";
|
||||
config game_config(preprocess_file("data/game.cfg", &defines_map));
|
||||
|
||||
|
||||
const std::vector<config*>& units = game_config.children["units"];
|
||||
if(units.empty()) {
|
||||
std::cerr << "Could not find units configuration\n";
|
||||
|
@ -160,10 +160,10 @@ int play_game(int argc, char** argv)
|
|||
std::cerr << "Language data not found\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool test_mode = false;
|
||||
int video_flags = preferences::fullscreen() ? FULL_SCREEN : 0;
|
||||
|
||||
|
||||
for(int arg = 1; arg != argc; ++arg) {
|
||||
const std::string val(argv[arg]);
|
||||
if(val == "-windowed") {
|
||||
|
@ -176,7 +176,7 @@ int play_game(int argc, char** argv)
|
|||
}
|
||||
|
||||
const std::pair<int,int>& resolution = preferences::resolution();
|
||||
|
||||
|
||||
const int bpp = video.modePossible(resolution.first,resolution.second,
|
||||
16,video_flags);
|
||||
|
||||
|
@ -228,13 +228,13 @@ int play_game(int argc, char** argv)
|
|||
play_game(disp,state,game_config,units_data,video);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
gui::TITLE_RESULT res = gui::show_title(disp);
|
||||
if(res == gui::QUIT_GAME) {
|
||||
return 0;
|
||||
} else if(res == gui::LOAD_GAME) {
|
||||
srand(SDL_GetTicks());
|
||||
|
||||
|
||||
const std::vector<std::string>& games = get_saves_list();
|
||||
|
||||
if(games.empty()) {
|
||||
|
@ -354,7 +354,7 @@ int play_game(int argc, char** argv)
|
|||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
//make a new game config item based on the difficulty level
|
||||
config game_config(preprocess_file("data/game.cfg", &defines_map));
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ bool conditional_passed(game_state& state_of_game,
|
|||
|
||||
if(units == NULL)
|
||||
return false;
|
||||
|
||||
|
||||
std::map<gamemap::location,unit>::const_iterator itor;
|
||||
for(itor = units->begin(); itor != units->end(); ++itor) {
|
||||
if(itor->second.matches_filter(**u)) {
|
||||
|
@ -67,7 +67,7 @@ bool conditional_passed(game_state& state_of_game,
|
|||
values.find("numerical_not_equals") == values.end()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -154,7 +154,7 @@ public:
|
|||
{}
|
||||
|
||||
const std::string& name() const { return name_; }
|
||||
|
||||
|
||||
bool first_time_only() const { return first_time_only_; }
|
||||
|
||||
void disable() { disabled_ = true; }
|
||||
|
@ -169,7 +169,7 @@ public:
|
|||
}
|
||||
|
||||
void handle_event(const queued_event& event_info, config* cfg=NULL);
|
||||
|
||||
|
||||
private:
|
||||
std::string name_;
|
||||
bool first_time_only_;
|
||||
|
@ -178,7 +178,7 @@ private:
|
|||
};
|
||||
|
||||
std::multimap<std::string,event_handler> events_map;
|
||||
|
||||
|
||||
void event_handler::handle_event(const queued_event& event_info, config* cfg)
|
||||
{
|
||||
if(cfg == NULL)
|
||||
|
@ -236,7 +236,7 @@ void event_handler::handle_event(const queued_event& event_info, config* cfg)
|
|||
handle_event(event_info,*cmd);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//if we are assigning a role to a unit from the available units list
|
||||
std::vector<config*>& assign_role = cfg->children["role"];
|
||||
for(std::vector<config*>::iterator rl = assign_role.begin();
|
||||
|
@ -262,7 +262,7 @@ void event_handler::handle_event(const queued_event& event_info, config* cfg)
|
|||
|
||||
if(itor != units->end())
|
||||
break;
|
||||
|
||||
|
||||
std::vector<unit>::iterator ui;
|
||||
//iterate over the units, and try to find one that matches
|
||||
for(ui = state_of_game->available_units.begin();
|
||||
|
@ -283,7 +283,7 @@ void event_handler::handle_event(const queued_event& event_info, config* cfg)
|
|||
if(ti != types.end())
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
std::vector<config*>& remove_overlays = cfg->children["removeitem"];
|
||||
for(std::vector<config*>::iterator rm = remove_overlays.begin();
|
||||
rm != remove_overlays.end(); ++rm) {
|
||||
|
@ -291,7 +291,7 @@ void event_handler::handle_event(const queued_event& event_info, config* cfg)
|
|||
if(!loc.valid()) {
|
||||
loc = event_info.loc1;
|
||||
}
|
||||
|
||||
|
||||
screen->remove_overlay(loc);
|
||||
}
|
||||
|
||||
|
@ -304,7 +304,7 @@ void event_handler::handle_event(const queued_event& event_info, config* cfg)
|
|||
if(!img.empty())
|
||||
screen->add_overlay(loc,img);
|
||||
}
|
||||
|
||||
|
||||
//changing the terrain
|
||||
std::vector<config*>& terrain_changes = cfg->children["terrain"];
|
||||
for(std::vector<config*>::iterator tc = terrain_changes.begin();
|
||||
|
@ -317,14 +317,14 @@ void event_handler::handle_event(const queued_event& event_info, config* cfg)
|
|||
screen->invalidate_all();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//if we should spawn a new unit on the map somewhere
|
||||
std::vector<config*>& new_units = cfg->children["unit"];
|
||||
for(std::vector<config*>::iterator ui = new_units.begin();
|
||||
ui != new_units.end(); ++ui) {
|
||||
unit new_unit(*game_data_ptr,**ui);
|
||||
gamemap::location loc(**ui);
|
||||
|
||||
|
||||
if(game_map->on_board(loc)) {
|
||||
loc = find_vacant_tile(*game_map,*units,loc);
|
||||
units->insert(std::pair<gamemap::location,unit>(loc,new_unit));
|
||||
|
@ -348,7 +348,7 @@ void event_handler::handle_event(const queued_event& event_info, config* cfg)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::vector<config*>& objects = cfg->children["object"];
|
||||
for(std::vector<config*>::iterator obj = objects.begin();
|
||||
obj != objects.end(); ++obj) {
|
||||
|
@ -366,17 +366,17 @@ void event_handler::handle_event(const queued_event& event_info, config* cfg)
|
|||
const std::string& caption_lang = string_table[id + "_name"];
|
||||
if(caption_lang.empty() == false)
|
||||
caption = caption_lang;
|
||||
|
||||
|
||||
const std::map<gamemap::location,unit>::iterator u =
|
||||
units->find(event_info.loc1);
|
||||
|
||||
if(u == units->end())
|
||||
continue;
|
||||
|
||||
|
||||
std::string text;
|
||||
|
||||
|
||||
std::vector<config*>& filters = (*obj)->children["filter"];
|
||||
|
||||
|
||||
if(filters.empty() || u->second.matches_filter(*filters[0])) {
|
||||
const std::string& lang = string_table[id];
|
||||
if(!lang.empty())
|
||||
|
@ -410,7 +410,7 @@ void event_handler::handle_event(const queued_event& event_info, config* cfg)
|
|||
//this will redraw the unit, with its new stats
|
||||
screen->draw();
|
||||
}
|
||||
|
||||
|
||||
std::vector<config*>& messages = cfg->children["message"];
|
||||
for(std::vector<config*>::iterator msg = messages.begin();
|
||||
msg != messages.end(); ++msg) {
|
||||
|
@ -438,13 +438,13 @@ void event_handler::handle_event(const queued_event& event_info, config* cfg)
|
|||
|
||||
std::string image = (*msg)->values["image"];
|
||||
std::string caption;
|
||||
|
||||
|
||||
const std::string& lang_caption = string_table[id + "_caption"];
|
||||
if(!lang_caption.empty())
|
||||
caption = lang_caption;
|
||||
else
|
||||
caption = (*msg)->values["caption"];
|
||||
|
||||
|
||||
if(speaker != units->end()) {
|
||||
screen->highlight_hex(speaker->first);
|
||||
screen->scroll_to_tile(speaker->first.x,speaker->first.y);
|
||||
|
@ -513,7 +513,7 @@ void event_handler::handle_event(const queued_event& event_info, config* cfg)
|
|||
std::vector<config*>& dead_units = cfg->children["kill"];
|
||||
for(std::vector<config*>::iterator du = dead_units.begin();
|
||||
du != dead_units.end(); ++du) {
|
||||
|
||||
|
||||
for(std::map<gamemap::location,unit>::iterator i = units->begin();
|
||||
i != units->end(); ++i) {
|
||||
while(i->second.matches_filter(**du) && i != units->end()) {
|
||||
|
@ -521,7 +521,7 @@ void event_handler::handle_event(const queued_event& event_info, config* cfg)
|
|||
i = units->begin();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::vector<unit>& avail_units = state_of_game->available_units;
|
||||
for(std::vector<unit>::iterator j = avail_units.begin();
|
||||
j != avail_units.end(); ++j) {
|
||||
|
@ -539,7 +539,7 @@ void event_handler::handle_event(const queued_event& event_info, config* cfg)
|
|||
events_map.insert(std::pair<std::string,event_handler>(
|
||||
new_handler.name(),new_handler));
|
||||
}
|
||||
|
||||
|
||||
std::vector<config*>& end_level = cfg->children["endlevel"];
|
||||
if(end_level.empty() == false) {
|
||||
config* const end_info = end_level[0];
|
||||
|
@ -624,7 +624,7 @@ bool process_event(event_handler& handler, const queued_event& ev)
|
|||
{
|
||||
if(handler.disabled())
|
||||
return false;
|
||||
|
||||
|
||||
std::map<gamemap::location,unit>::iterator unit1 = units->find(ev.loc1);
|
||||
std::map<gamemap::location,unit>::iterator unit2 = units->find(ev.loc2);
|
||||
|
||||
|
@ -674,7 +674,7 @@ manager::manager(config& cfg, display& gui_, gamemap& map_,
|
|||
events_map.insert(std::pair<std::string,event_handler>(
|
||||
new_handler.name(), new_handler));
|
||||
}
|
||||
|
||||
|
||||
screen = &gui_;
|
||||
game_map = &map_;
|
||||
units = &units_;
|
||||
|
|
|
@ -52,7 +52,7 @@ HOTKEY_COMMAND string_to_command(const std::string& str)
|
|||
struct hotkey {
|
||||
explicit hotkey(config& cfg);
|
||||
|
||||
HOTKEY_COMMAND action;
|
||||
HOTKEY_COMMAND action;
|
||||
int keycode;
|
||||
bool alt, ctrl, shift;
|
||||
mutable bool lastres;
|
||||
|
@ -62,7 +62,7 @@ hotkey::hotkey(config& cfg) : lastres(false)
|
|||
{
|
||||
std::map<std::string,std::string>& m = cfg.values;
|
||||
action = string_to_command(m["command"]);
|
||||
|
||||
|
||||
keycode = m["key"].empty() ? 0 : m["key"][0];
|
||||
alt = (m["alt"] == "yes");
|
||||
ctrl = (m["ctrl"] == "yes");
|
||||
|
|
24
intro.cpp
24
intro.cpp
|
@ -43,10 +43,10 @@ void show_intro(display& screen, config& data)
|
|||
if(image_name.empty() == false) {
|
||||
image = screen.getImage(image_name,display::UNSCALED);
|
||||
}
|
||||
|
||||
|
||||
int textx = 200;
|
||||
int texty = 400;
|
||||
|
||||
int texty = 400;
|
||||
|
||||
if(image != NULL) {
|
||||
SDL_Rect dstrect;
|
||||
dstrect.x = screen.x()/2 - image->w/2;
|
||||
|
@ -73,7 +73,7 @@ void show_intro(display& screen, config& data)
|
|||
const int max_length = 60;
|
||||
std::stringstream stream;
|
||||
int cur_length = 0;
|
||||
|
||||
|
||||
for(std::string::const_iterator j = story.begin(); j!=story.end();++j){
|
||||
char c = *j;
|
||||
if(c == ' ' && cur_length >= max_length)
|
||||
|
@ -108,7 +108,7 @@ void show_intro(display& screen, config& data)
|
|||
const bool right_button = mouse_flags&SDL_BUTTON_RMASK;
|
||||
const bool left_button = mouse_flags&SDL_BUTTON_LMASK;
|
||||
|
||||
|
||||
|
||||
if(key[KEY_ESCAPE] ||
|
||||
skip_button.process(mousex,mousey,left_button))
|
||||
return;
|
||||
|
@ -143,7 +143,7 @@ void show_map_scene(display& screen, config& data)
|
|||
std::vector<config*>& dots = cfg.children["dot"];
|
||||
|
||||
const std::string& image_file = cfg.values["image"];
|
||||
|
||||
|
||||
SDL_Surface* const image = screen.getImage(image_file,display::UNSCALED);
|
||||
SDL_Surface* const dot_image =
|
||||
screen.getImage("misc/dot.png",display::UNSCALED);
|
||||
|
@ -170,7 +170,7 @@ void show_map_scene(display& screen, config& data)
|
|||
|
||||
CKey key;
|
||||
|
||||
|
||||
|
||||
for(std::vector<config*>::iterator d = dots.begin(); d != dots.end(); ++d){
|
||||
const std::string& xloc = (*d)->values["x"];
|
||||
const std::string& yloc = (*d)->values["y"];
|
||||
|
@ -183,7 +183,7 @@ void show_map_scene(display& screen, config& data)
|
|||
if((*d)->values["type"] == "cross") {
|
||||
img = cross_image;
|
||||
}
|
||||
|
||||
|
||||
int xdot = x - img->w/2;
|
||||
int ydot = y - img->h/2;
|
||||
|
||||
|
@ -198,7 +198,7 @@ void show_map_scene(display& screen, config& data)
|
|||
dot_rect.y = ydot;
|
||||
dot_rect.w = img->w;
|
||||
dot_rect.h = img->h;
|
||||
|
||||
|
||||
SDL_BlitSurface(img,NULL,image,&dot_rect);
|
||||
|
||||
SDL_BlitSurface(image,NULL,screen.video().getSurface(),&dstrect);
|
||||
|
@ -207,7 +207,7 @@ void show_map_scene(display& screen, config& data)
|
|||
if(key[KEY_ESCAPE]) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
SDL_Delay(50);
|
||||
|
||||
int a, b;
|
||||
|
@ -220,7 +220,7 @@ void show_map_scene(display& screen, config& data)
|
|||
if(key[KEY_ESCAPE]) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
screen.video().update(0,0,screen.x(),screen.y());
|
||||
}
|
||||
|
||||
|
@ -236,7 +236,7 @@ void show_map_scene(display& screen, config& data)
|
|||
|
||||
SDL_BlitSurface(image,NULL,screen.video().getSurface(),&dstrect);
|
||||
screen.video().update(0,0,screen.x(),screen.y());
|
||||
|
||||
|
||||
bool last_state = true;
|
||||
for(;;) {
|
||||
int a, b;
|
||||
|
|
2
key.hpp
2
key.hpp
|
@ -18,7 +18,7 @@
|
|||
class CKey {
|
||||
public:
|
||||
CKey();
|
||||
|
||||
|
||||
int operator[](int);
|
||||
void SetEnabled(bool enable);
|
||||
private:
|
||||
|
|
|
@ -92,7 +92,7 @@ void process_config(const std::string& element_name, const config& cfg,
|
|||
|
||||
std::string name = name_it->second;
|
||||
name.erase(std::remove(name.begin(),name.end(),' '),name.end());
|
||||
|
||||
|
||||
out.insert(std::pair<string,string>(name,name_it->second));
|
||||
|
||||
const map<string,string>::const_iterator description_it =
|
||||
|
|
2
map.cpp
2
map.cpp
|
@ -133,7 +133,7 @@ gamemap::gamemap(config& cfg, const std::string& data) : tiles_(1)
|
|||
if(c == TOWER) {
|
||||
towers_.push_back(location(x,y));
|
||||
}
|
||||
|
||||
|
||||
tiles_.back().push_back(c);
|
||||
|
||||
++y;
|
||||
|
|
14
map.hpp
14
map.hpp
|
@ -23,7 +23,7 @@
|
|||
class gamemap
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
typedef char TERRAIN;
|
||||
|
||||
enum { VOID_TERRAIN = ' ', CASTLE = 'C', TOWER = 't', FOREST = 'f' };
|
||||
|
@ -35,7 +35,7 @@ public:
|
|||
const std::string& terrain_name(TERRAIN terrain) const;
|
||||
const std::string& underlying_terrain_name(TERRAIN terrain) const;
|
||||
TERRAIN underlying_terrain(TERRAIN terrain) const;
|
||||
|
||||
|
||||
struct incorrect_format_exception {
|
||||
incorrect_format_exception(const char* msg) : msg_(msg) {}
|
||||
const char* const msg_;
|
||||
|
@ -61,17 +61,17 @@ public:
|
|||
|
||||
static location null_location;
|
||||
};
|
||||
|
||||
|
||||
gamemap(config& cfg,
|
||||
const std::string& data); //throw(incorrect_format_exception)
|
||||
|
||||
|
||||
std::string write() const;
|
||||
|
||||
int x() const;
|
||||
int y() const;
|
||||
|
||||
|
||||
const std::vector<TERRAIN>& operator[](int index) const;
|
||||
|
||||
|
||||
const location& starting_position(int n) const;
|
||||
int num_starting_positions() const;
|
||||
bool is_starting_position(const location& loc) const;
|
||||
|
@ -92,7 +92,7 @@ private:
|
|||
std::vector<TERRAIN> terrainPrecedence_;
|
||||
std::map<TERRAIN,terrain_type> letterToTerrain_;
|
||||
std::map<std::string,terrain_type> terrain_;
|
||||
|
||||
|
||||
std::vector<std::vector<TERRAIN> > tiles_;
|
||||
std::vector<location> towers_;
|
||||
location startingPositions_[10];
|
||||
|
|
68
menu.cpp
68
menu.cpp
|
@ -32,7 +32,7 @@ void draw_dialog_frame(int x, int y, int w, int h, display& disp)
|
|||
SDL_Surface* const scr = disp.video().getSurface();
|
||||
|
||||
const display::Pixel border_colour = SDL_MapRGB(scr->format,200,0,0);
|
||||
|
||||
|
||||
draw_solid_tinted_rectangle(x-border_size,y-border_size,
|
||||
w+border_size,h+border_size,0,0,0,0.6,scr);
|
||||
draw_solid_tinted_rectangle(x,y,w+border_size,h+border_size,0,0,0,0.6,scr);
|
||||
|
@ -100,7 +100,7 @@ void draw_solid_tinted_rectangle(int x, int y, int w, int h,
|
|||
|
||||
++beg;
|
||||
}
|
||||
|
||||
|
||||
p += target->w;
|
||||
--h;
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ namespace {
|
|||
const int max_menu_items = 18;
|
||||
const int menu_font_size = 16;
|
||||
const int menu_cell_padding = 10;
|
||||
|
||||
|
||||
class menu
|
||||
{
|
||||
display* display_;
|
||||
|
@ -143,7 +143,7 @@ class menu
|
|||
const SDL_Rect res =
|
||||
font::draw_text(NULL,area,menu_font_size,
|
||||
font::NORMAL_COLOUR,items_[row][col],x_,y_);
|
||||
|
||||
|
||||
if(col == column_widths_.size()) {
|
||||
column_widths_.push_back(res.w + menu_cell_padding);
|
||||
} else if(res.w > column_widths_[col] - menu_cell_padding) {
|
||||
|
@ -155,12 +155,12 @@ class menu
|
|||
|
||||
return column_widths_;
|
||||
}
|
||||
|
||||
|
||||
void draw_item(int item) {
|
||||
SDL_Rect rect = get_item_rect(item);
|
||||
if(rect.w == 0)
|
||||
return;
|
||||
|
||||
|
||||
short* const dstptr = reinterpret_cast<short*>(
|
||||
display_->video().getSurface()->pixels) +
|
||||
rect.y*display_->x() + x_;
|
||||
|
@ -181,7 +181,7 @@ class menu
|
|||
SDL_Rect area = {0,0,display_->x(),display_->y()};
|
||||
|
||||
const std::vector<int>& widths = column_widths();
|
||||
|
||||
|
||||
int xpos = rect.x;
|
||||
for(int i = 0; i != items_[item].size(); ++i) {
|
||||
font::draw_text(display_,area,menu_font_size,font::NORMAL_COLOUR,
|
||||
|
@ -192,7 +192,7 @@ class menu
|
|||
|
||||
void draw() {
|
||||
drawn_ = true;
|
||||
|
||||
|
||||
for(int i = 0; i != items_.size(); ++i)
|
||||
draw_item(i);
|
||||
|
||||
|
@ -219,7 +219,7 @@ class menu
|
|||
if(item < first_item_on_screen_ ||
|
||||
item >= first_item_on_screen_ + max_menu_items) {
|
||||
return empty_rect;
|
||||
}
|
||||
}
|
||||
|
||||
const std::map<int,SDL_Rect>::const_iterator i = itemRects_.find(item);
|
||||
if(i != itemRects_.end())
|
||||
|
@ -230,7 +230,7 @@ class menu
|
|||
const SDL_Rect& prev = get_item_rect(item-1);
|
||||
y = prev.y + prev.h;
|
||||
}
|
||||
|
||||
|
||||
static const SDL_Rect area = {0,0,display_->x(),display_->y()};
|
||||
|
||||
SDL_Rect res = font::draw_text(NULL,area,menu_font_size,
|
||||
|
@ -245,7 +245,7 @@ class menu
|
|||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
int items_start() const
|
||||
{
|
||||
if(items_.size() > max_menu_items)
|
||||
|
@ -253,7 +253,7 @@ class menu
|
|||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int items_end() const
|
||||
{
|
||||
if(items_.size() > max_menu_items)
|
||||
|
@ -266,7 +266,7 @@ class menu
|
|||
{
|
||||
return items_end() - items_start();
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
menu(display& disp, const std::vector<std::string>& items,
|
||||
bool click_selects=false)
|
||||
|
@ -302,7 +302,7 @@ public:
|
|||
|
||||
return height_;
|
||||
}
|
||||
|
||||
|
||||
int width() const {
|
||||
if(width_ == -1) {
|
||||
const std::vector<int>& widths = column_widths();
|
||||
|
@ -342,7 +342,7 @@ public:
|
|||
|
||||
draw();
|
||||
}
|
||||
|
||||
|
||||
const bool down = downarrow_.process(x,y,button);
|
||||
if(down && first_item_on_screen_ + max_menu_items < items_.size()) {
|
||||
itemRects_.clear();
|
||||
|
@ -350,7 +350,7 @@ public:
|
|||
draw();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(up_arrow && !click_selects_ && selected_ > 0) {
|
||||
--selected_;
|
||||
if(selected_ < first_item_on_screen_) {
|
||||
|
@ -399,7 +399,7 @@ public:
|
|||
const int starting_selected = selected_;
|
||||
|
||||
const int hit_item = hit(x,y);
|
||||
|
||||
|
||||
if(click_selects_) {
|
||||
selected_ = hit_item;
|
||||
if(button && !previous_button_)
|
||||
|
@ -411,7 +411,7 @@ public:
|
|||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(button && hit_item != -1){
|
||||
selected_ = hit_item;
|
||||
}
|
||||
|
@ -472,7 +472,7 @@ int show_dialog(display& disp, SDL_Surface* image,
|
|||
}
|
||||
|
||||
menu menu_(disp,menu_items,type == MESSAGE);
|
||||
|
||||
|
||||
const int border_size = 6;
|
||||
const short text_colour = 0xFFFF;
|
||||
const short border_colour = 0xF000;
|
||||
|
@ -564,7 +564,7 @@ int show_dialog(display& disp, SDL_Surface* image,
|
|||
if(button_heights > 0) {
|
||||
button_heights += button_height_padding;
|
||||
}
|
||||
|
||||
|
||||
if(cur_line > longest_line)
|
||||
longest_line = cur_line;
|
||||
|
||||
|
@ -637,7 +637,7 @@ int show_dialog(display& disp, SDL_Surface* image,
|
|||
if(menu_.height() > 0)
|
||||
menu_.set_loc(xloc+total_image_width+left_padding+image_h_padding,
|
||||
yloc+top_padding+text_size.h);
|
||||
|
||||
|
||||
draw_dialog_frame(xloc,yloc,total_width,total_height,disp);
|
||||
|
||||
if(image != NULL) {
|
||||
|
@ -650,7 +650,7 @@ int show_dialog(display& disp, SDL_Surface* image,
|
|||
if(caption_size.w < image->w) {
|
||||
center_font = image->w/2 - caption_size.w/2;
|
||||
}
|
||||
|
||||
|
||||
font::draw_text(&disp, clipRect, caption_font_size,
|
||||
font::NORMAL_COLOUR, caption,
|
||||
xloc+left_padding+center_font,
|
||||
|
@ -681,15 +681,15 @@ int show_dialog(display& disp, SDL_Surface* image,
|
|||
font::NORMAL_COLOUR, text_widget_label,
|
||||
xloc + left_padding,text_widget_y);
|
||||
}
|
||||
|
||||
|
||||
screen.update(0,0,scr->w,scr->h);
|
||||
|
||||
|
||||
CKey key;
|
||||
|
||||
bool left_button = true, right_button = true, key_down = true,
|
||||
up_arrow = false, down_arrow = false,
|
||||
page_up = false, page_down = false;
|
||||
|
||||
|
||||
disp.invalidate_all();
|
||||
|
||||
int cur_selection = -1;
|
||||
|
@ -699,7 +699,7 @@ int show_dialog(display& disp, SDL_Surface* image,
|
|||
unit_profile_rect.w = 0;
|
||||
|
||||
bool first_time = true;
|
||||
|
||||
|
||||
for(;;) {
|
||||
int mousex, mousey;
|
||||
const int mouse_flags = SDL_GetMouseState(&mousex,&mousey);
|
||||
|
@ -752,7 +752,7 @@ int show_dialog(display& disp, SDL_Surface* image,
|
|||
}
|
||||
|
||||
first_time = false;
|
||||
|
||||
|
||||
if(menu_.height() > 0) {
|
||||
const int res = menu_.process(mousex,mousey,new_left_button,
|
||||
!up_arrow && new_up_arrow,
|
||||
|
@ -788,7 +788,7 @@ int show_dialog(display& disp, SDL_Surface* image,
|
|||
if(button_it->process(mousex,mousey,left_button)) {
|
||||
if(text_widget_text != NULL && use_textbox)
|
||||
*text_widget_text = text_widget.text();
|
||||
|
||||
|
||||
//if the menu is not used, then return the index of the
|
||||
//button pressed, otherwise return the index of the menu
|
||||
//item selected if the last button is not pressed, and
|
||||
|
@ -806,7 +806,7 @@ int show_dialog(display& disp, SDL_Surface* image,
|
|||
|
||||
SDL_PumpEvents();
|
||||
}
|
||||
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -822,7 +822,7 @@ TITLE_RESULT show_title(display& screen)
|
|||
|
||||
const int x = screen.x()/2 - title_surface->w/2;
|
||||
const int y = 100;
|
||||
|
||||
|
||||
screen.blit_surface(x,y,title_surface);
|
||||
|
||||
button tutorial_button(screen,string_table["tutorial_button"]);
|
||||
|
@ -856,9 +856,9 @@ TITLE_RESULT show_title(display& screen)
|
|||
quit_button.draw();
|
||||
language_button.draw();
|
||||
screen.video().update(0,0,screen.x(),screen.y());
|
||||
|
||||
|
||||
CKey key;
|
||||
|
||||
|
||||
for(;;) {
|
||||
int mousex, mousey;
|
||||
const int mouse_flags = SDL_GetMouseState(&mousex,&mousey);
|
||||
|
@ -874,7 +874,7 @@ TITLE_RESULT show_title(display& screen)
|
|||
|
||||
if(load_button.process(mousex,mousey,left_button))
|
||||
return LOAD_GAME;
|
||||
|
||||
|
||||
if(multi_button.process(mousex,mousey,left_button))
|
||||
return MULTIPLAYER;
|
||||
|
||||
|
@ -886,7 +886,7 @@ TITLE_RESULT show_title(display& screen)
|
|||
|
||||
if(language_button.process(mousex,mousey,left_button))
|
||||
return CHANGE_LANGUAGE;
|
||||
|
||||
|
||||
SDL_PumpEvents();
|
||||
|
||||
SDL_Delay(20);
|
||||
|
|
2
menu.hpp
2
menu.hpp
|
@ -31,7 +31,7 @@ void draw_rectangle(int x, int y, int w, int h, short colour, SDL_Surface* tg);
|
|||
void draw_solid_tinted_rectangle(int x, int y, int w, int h,
|
||||
int r, int g, int b,
|
||||
double alpha, SDL_Surface* target);
|
||||
|
||||
|
||||
enum DIALOG_TYPE { MESSAGE, OK_ONLY, YES_NO, OK_CANCEL };
|
||||
|
||||
//if a menu is given, then returns -1 if the dialog was cancelled, and the
|
||||
|
|
|
@ -44,7 +44,7 @@ void play_multiplayer(display& disp, game_data& units_data, config& cfg,
|
|||
state.label = level.values["name"];
|
||||
|
||||
state.scenario = res;
|
||||
|
||||
|
||||
std::vector<config*>& sides = level.children["side"];
|
||||
std::vector<config*>& possible_sides = cfg.children["multiplayer_side"];
|
||||
if(sides.empty() || possible_sides.empty()) {
|
||||
|
@ -74,13 +74,13 @@ void play_multiplayer(display& disp, game_data& units_data, config& cfg,
|
|||
}
|
||||
|
||||
sides_list.push_back(string_table["start_game"]);
|
||||
|
||||
|
||||
res = gui::show_dialog(disp,NULL,"",string_table["configure_sides"],
|
||||
gui::MESSAGE,&sides_list);
|
||||
|
||||
if(res >= 0 && res < sides.size()) {
|
||||
std::vector<std::string> choices;
|
||||
|
||||
|
||||
for(int n = 0; n != 2; ++n) {
|
||||
for(std::vector<config*>::iterator i = possible_sides.begin();
|
||||
i != possible_sides.end(); ++i) {
|
||||
|
@ -111,7 +111,7 @@ void play_multiplayer(display& disp, game_data& units_data, config& cfg,
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
state.starting_pos = level;
|
||||
|
||||
recorder.set_save_info(state);
|
||||
|
|
10
pathfind.cpp
10
pathfind.cpp
|
@ -48,7 +48,7 @@ gamemap::location find_vacant(const gamemap& map,
|
|||
if(map.on_board(res))
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
return gamemap::location();
|
||||
}
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ bool tiles_adjacent(const gamemap::location& a, const gamemap::location& b)
|
|||
//two tiles are adjacent if y is different by 1, and x by 0, or if
|
||||
//x is different by 1 and y by 0, or if x and y are each different by 1,
|
||||
//and the x value of the hex with the greater y value is odd
|
||||
|
||||
|
||||
const int xdiff = abs(a.x - b.x);
|
||||
const int ydiff = abs(a.y - b.y);
|
||||
return ydiff == 1 && a.x == b.x || xdiff == 1 && a.y == b.y ||
|
||||
|
@ -148,11 +148,11 @@ void find_routes(const gamemap& map, const game_data& gamedata,
|
|||
if(!teams[u.side()-1].owns_tower(*t) ||
|
||||
units.find(*t) != units.end())
|
||||
continue;
|
||||
|
||||
|
||||
locs.push_back(*t);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//iterate over all adjacent tiles
|
||||
for(int i = 0; i != locs.size(); ++i) {
|
||||
const gamemap::location& currentloc = locs[i];
|
||||
|
@ -230,7 +230,7 @@ paths::paths(const gamemap& map, const game_data& gamedata,
|
|||
route new_route;
|
||||
new_route.move_left = -1;
|
||||
routes.insert(std::pair<gamemap::location,route>(
|
||||
adjacent[j],new_route));
|
||||
adjacent[j],new_route));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ struct paths
|
|||
std::vector<gamemap::location> steps;
|
||||
int move_left;
|
||||
};
|
||||
|
||||
|
||||
std::map<gamemap::location,route> routes;
|
||||
};
|
||||
|
||||
|
@ -59,7 +59,7 @@ struct node {
|
|||
{
|
||||
f = g + h;
|
||||
}
|
||||
|
||||
|
||||
node* parent;
|
||||
gamemap::location loc;
|
||||
double g, h, f;
|
||||
|
@ -77,7 +77,7 @@ paths::route a_star_search(const gamemap::location& src,
|
|||
std::list<node> open_list, closed_list;
|
||||
|
||||
open_list.push_back(node(src,dst,0.0,NULL));
|
||||
|
||||
|
||||
while(!open_list.empty()) {
|
||||
|
||||
//find the lowest estimated cost node on the open list
|
||||
|
@ -96,7 +96,7 @@ paths::route a_star_search(const gamemap::location& src,
|
|||
|
||||
//move the lowest element from the open list to the closed list
|
||||
closed_list.splice(closed_list.begin(),open_list,lowest);
|
||||
|
||||
|
||||
//find nodes we can go to from this node
|
||||
location locs[6];
|
||||
get_adjacent_tiles(lowest->loc,locs);
|
||||
|
|
|
@ -28,7 +28,7 @@ LEVEL_RESULT play_level(game_data& gameinfo, config& terrain_config,
|
|||
{
|
||||
const int num_turns = atoi(level->values["turns"].c_str());
|
||||
gamestatus status(num_turns);
|
||||
|
||||
|
||||
gamemap map(terrain_config,read_file("data/maps/" + level->values["map"]));
|
||||
|
||||
CKey key;
|
||||
|
@ -36,7 +36,7 @@ LEVEL_RESULT play_level(game_data& gameinfo, config& terrain_config,
|
|||
units_map units;
|
||||
|
||||
std::vector<team> teams;
|
||||
|
||||
|
||||
std::vector<config*>& unit_cfg = level->children["side"];
|
||||
for(std::vector<config*>::iterator ui = unit_cfg.begin();
|
||||
ui != unit_cfg.end(); ++ui) {
|
||||
|
@ -52,7 +52,7 @@ LEVEL_RESULT play_level(game_data& gameinfo, config& terrain_config,
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::string gold = (*ui)->values["gold"];
|
||||
if(gold.empty())
|
||||
gold = "100";
|
||||
|
@ -81,7 +81,7 @@ LEVEL_RESULT play_level(game_data& gameinfo, config& terrain_config,
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
display gui(units,video,map,status,teams);
|
||||
const preferences::display_manager prefs_disp_manager(&gui);
|
||||
|
||||
|
@ -93,7 +93,7 @@ LEVEL_RESULT play_level(game_data& gameinfo, config& terrain_config,
|
|||
|
||||
show_map_scene(gui,*level);
|
||||
}
|
||||
|
||||
|
||||
const std::string& music = level->values["music"];
|
||||
if(!music.empty()) {
|
||||
sound::play_music(music);
|
||||
|
@ -109,23 +109,23 @@ LEVEL_RESULT play_level(game_data& gameinfo, config& terrain_config,
|
|||
gui.add_overlay(gamemap::location(**overlay),
|
||||
(*overlay)->values["image"]);
|
||||
}
|
||||
|
||||
|
||||
const double scroll_speed = 30.0;
|
||||
const double zoom_amount = 5.0;
|
||||
|
||||
|
||||
for(units_map::iterator i = units.begin(); i != units.end(); ++i) {
|
||||
i->second.new_turn();
|
||||
}
|
||||
|
||||
|
||||
bool left_button = false, right_button = false;
|
||||
|
||||
|
||||
gamemap::location selected_hex;
|
||||
|
||||
gui.scroll_to_tile(map.starting_position(1).x,map.starting_position(1).y,
|
||||
display::WARP);
|
||||
|
||||
bool replaying = (recorder.empty() == false);
|
||||
|
||||
|
||||
std::cout << "starting main loop\n";
|
||||
for(bool first_time = true; true; first_time = false) {
|
||||
try {
|
||||
|
@ -140,13 +140,13 @@ LEVEL_RESULT play_level(game_data& gameinfo, config& terrain_config,
|
|||
for(std::vector<team>::iterator team_it = teams.begin();
|
||||
team_it != teams.end(); ++team_it) {
|
||||
const int player_number = (team_it - teams.begin()) + 1;
|
||||
|
||||
|
||||
calculate_healing(gui,map,units,player_number);
|
||||
|
||||
//scroll the map to the leader
|
||||
const units_map::iterator leader =
|
||||
find_leader(units,player_number);
|
||||
|
||||
|
||||
if(leader != units.end() && !recorder.skipping()) {
|
||||
gui.scroll_to_tile(leader->first.x,leader->first.y);
|
||||
}
|
||||
|
@ -167,7 +167,7 @@ LEVEL_RESULT play_level(game_data& gameinfo, config& terrain_config,
|
|||
} else if(!replaying) {
|
||||
ai::do_move(gui,map,gameinfo,units,teams,
|
||||
player_number,status);
|
||||
|
||||
|
||||
gui.invalidate_unit();
|
||||
gui.invalidate_game_status();
|
||||
gui.invalidate_all();
|
||||
|
@ -204,7 +204,7 @@ LEVEL_RESULT play_level(game_data& gameinfo, config& terrain_config,
|
|||
update_locker lock_display(gui,recorder.skipping());
|
||||
game_events::fire(event_stream.str());
|
||||
}
|
||||
|
||||
|
||||
std::map<int,int> expenditure;
|
||||
for(units_map::iterator i = units.begin();
|
||||
i != units.end(); ++i) {
|
||||
|
@ -238,7 +238,7 @@ LEVEL_RESULT play_level(game_data& gameinfo, config& terrain_config,
|
|||
game_events::fire("victory");
|
||||
} catch(end_level_exception&) {
|
||||
}
|
||||
|
||||
|
||||
//add all the units that survived the scenario
|
||||
for(std::map<gamemap::location,unit>::iterator un =
|
||||
units.begin(); un != units.end(); ++un) {
|
||||
|
@ -248,7 +248,7 @@ LEVEL_RESULT play_level(game_data& gameinfo, config& terrain_config,
|
|||
push_back(un->second);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const int remaining_gold = teams[0].gold();
|
||||
const int finishing_bonus_per_turn =
|
||||
map.towers().size()*game_config::tower_income;
|
||||
|
@ -256,7 +256,7 @@ LEVEL_RESULT play_level(game_data& gameinfo, config& terrain_config,
|
|||
const int finishing_bonus = end_level.gold_bonus ?
|
||||
(finishing_bonus_per_turn * turns_left) : 0;
|
||||
state_of_game.gold = (remaining_gold+finishing_bonus)/2;
|
||||
|
||||
|
||||
gui::show_dialog(gui,NULL,string_table["victory_heading"],
|
||||
string_table["victory_message"],gui::OK_ONLY);
|
||||
std::stringstream report;
|
||||
|
@ -272,7 +272,7 @@ LEVEL_RESULT play_level(game_data& gameinfo, config& terrain_config,
|
|||
<< string_table["gold"] << ": "
|
||||
<< (remaining_gold+finishing_bonus);
|
||||
}
|
||||
|
||||
|
||||
report << "\n" << string_table["fifty_percent"] << "\n"
|
||||
<< string_table["retained_gold"] << ": "
|
||||
<< state_of_game.gold;
|
||||
|
@ -286,7 +286,7 @@ LEVEL_RESULT play_level(game_data& gameinfo, config& terrain_config,
|
|||
"or from a different version of the game",gui::OK_ONLY);
|
||||
return DEFEAT;
|
||||
}
|
||||
|
||||
|
||||
} //end for(;;)
|
||||
|
||||
return QUIT;
|
||||
|
|
72
playturn.cpp
72
playturn.cpp
|
@ -42,7 +42,7 @@ void play_turn(game_data& gameinfo, game_state& state_of_game,
|
|||
gui.invalidate_all();
|
||||
gui.draw();
|
||||
gui.update_display();
|
||||
|
||||
|
||||
team& current_team = teams[team_num-1];
|
||||
|
||||
const double scroll_speed = 30.0;
|
||||
|
@ -57,9 +57,9 @@ void play_turn(game_data& gameinfo, game_state& state_of_game,
|
|||
++menu_items_ptr) {
|
||||
menu.push_back(string_table[*menu_items_ptr]);
|
||||
}
|
||||
|
||||
|
||||
typedef std::map<gamemap::location,unit> units_map;
|
||||
|
||||
|
||||
gamemap::location next_unit;
|
||||
|
||||
bool left_button = false, right_button = false;
|
||||
|
@ -78,9 +78,9 @@ void play_turn(game_data& gameinfo, game_state& state_of_game,
|
|||
const int mouse_flags = SDL_GetMouseState(&mousex,&mousey);
|
||||
const bool new_left_button = mouse_flags & SDL_BUTTON_LMASK;
|
||||
const bool new_right_button = mouse_flags & SDL_BUTTON_RMASK;
|
||||
|
||||
|
||||
gamemap::location new_hex = gui.hex_clicked_on(mousex,mousey);
|
||||
|
||||
|
||||
//highlight the hex that is currently moused over
|
||||
if(new_hex != last_hex) {
|
||||
gui.highlight_hex(new_hex);
|
||||
|
@ -112,7 +112,7 @@ void play_turn(game_data& gameinfo, game_state& state_of_game,
|
|||
}
|
||||
|
||||
last_hex = new_hex;
|
||||
|
||||
|
||||
if(!left_button && new_left_button) {
|
||||
const gamemap::location& hex = gui.hex_clicked_on(mousex,mousey);
|
||||
|
||||
|
@ -128,7 +128,7 @@ void play_turn(game_data& gameinfo, game_state& state_of_game,
|
|||
if(route != current_paths.routes.end() && enemy != units.end() &&
|
||||
hex != selected_hex &&
|
||||
enemy->second.side() != u->second.side()) {
|
||||
|
||||
|
||||
const unit_type& type = u->second.type();
|
||||
const unit_type& enemy_type = enemy->second.type();
|
||||
const std::vector<attack_type>& attacks = u->second.attacks();
|
||||
|
@ -150,7 +150,7 @@ void play_turn(game_data& gameinfo, game_state& state_of_game,
|
|||
const std::string& lang_range =
|
||||
string_table[stats.range == "Melee" ?
|
||||
"short_range" : "long_range"];
|
||||
|
||||
|
||||
const std::string& lang_defend_name =
|
||||
string_table["weapon_name_"+stats.defend_name];
|
||||
const std::string& lang_defend_type =
|
||||
|
@ -164,7 +164,7 @@ void play_turn(game_data& gameinfo, game_state& state_of_game,
|
|||
stats.defend_name : lang_defend_name;
|
||||
const std::string& defend_type = lang_defend_type.empty() ?
|
||||
stats.defend_type : lang_defend_type;
|
||||
|
||||
|
||||
const std::string& range = lang_range.empty() ?
|
||||
stats.range : lang_range;
|
||||
|
||||
|
@ -179,7 +179,7 @@ void play_turn(game_data& gameinfo, game_state& state_of_game,
|
|||
<< ") " << stats.damage_attacker_takes << "-"
|
||||
<< stats.ndefends << " "
|
||||
<< int(ceil(100.0*stats.chance_to_hit_attacker)) << "%";
|
||||
|
||||
|
||||
items.push_back(att.str());
|
||||
units_list.push_back(enemy->second);
|
||||
}
|
||||
|
@ -224,7 +224,7 @@ void play_turn(game_data& gameinfo, game_state& state_of_game,
|
|||
dialogs::advance_unit(gameinfo,units,hex,gui);
|
||||
|
||||
selected_hex = gamemap::location();
|
||||
|
||||
|
||||
gui.invalidate_unit();
|
||||
gui.draw(); //clear the screen
|
||||
|
||||
|
@ -238,7 +238,7 @@ void play_turn(game_data& gameinfo, game_state& state_of_game,
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//otherwise we're just trying to move to a hex
|
||||
else if(selected_hex.valid() && selected_hex != hex &&
|
||||
enemy == units.end() &&
|
||||
|
@ -317,7 +317,7 @@ void play_turn(game_data& gameinfo, game_state& state_of_game,
|
|||
} else {
|
||||
gui.set_paths(NULL);
|
||||
current_paths = paths();
|
||||
|
||||
|
||||
selected_hex = hex;
|
||||
gui.select_hex(hex);
|
||||
|
||||
|
@ -331,7 +331,7 @@ void play_turn(game_data& gameinfo, game_state& state_of_game,
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
left_button = new_left_button;
|
||||
|
||||
if(!right_button && new_right_button) {
|
||||
|
@ -346,11 +346,11 @@ void play_turn(game_data& gameinfo, game_state& state_of_game,
|
|||
if(un != units.end()) {
|
||||
menu.push_back(string_table["describe_unit"]);
|
||||
}
|
||||
|
||||
|
||||
const int res = gui::show_dialog(gui,NULL,"",
|
||||
string_table["options"]+":\n",
|
||||
gui::MESSAGE,&menu);
|
||||
|
||||
|
||||
const std::string result = res != -1 ? menu[res] : "";
|
||||
|
||||
if(un != units.end()) {
|
||||
|
@ -374,7 +374,7 @@ void play_turn(game_data& gameinfo, game_state& state_of_game,
|
|||
SDL_Surface* const unit_image =
|
||||
gui.getImage(un->second.type().image_profile(),
|
||||
display::UNSCALED);
|
||||
|
||||
|
||||
const int res = gui::show_dialog(gui,unit_image,
|
||||
un->second.type().language_name(),
|
||||
description,gui::MESSAGE,&options,&units_list);
|
||||
|
@ -389,11 +389,11 @@ void play_turn(game_data& gameinfo, game_state& state_of_game,
|
|||
command = HOTKEY_ATTACK_RESISTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
else if(result == string_table["preferences"]) {
|
||||
preferences::show_preferences_dialog(gui);
|
||||
}
|
||||
|
||||
|
||||
else if(result == string_table["end_turn"]) {
|
||||
recorder.end_turn();
|
||||
return;
|
||||
|
@ -405,7 +405,7 @@ void play_turn(game_data& gameinfo, game_state& state_of_game,
|
|||
const std::string& id = level->values["id"];
|
||||
const std::string& lang_objectives =
|
||||
string_table[id + "_objectives"];
|
||||
|
||||
|
||||
const std::string& objectives = lang_objectives.empty() ?
|
||||
level->values["objectives"] : lang_objectives;
|
||||
gui::show_dialog(
|
||||
|
@ -420,7 +420,7 @@ void play_turn(game_data& gameinfo, game_state& state_of_game,
|
|||
std::sort(state_of_game.available_units.begin(),
|
||||
state_of_game.available_units.end(),
|
||||
compare_unit_values());
|
||||
|
||||
|
||||
gui.draw(); //clear the old menu
|
||||
if(state_of_game.available_units.empty()) {
|
||||
gui::show_dialog(gui,NULL,"",string_table["no_recall"]);
|
||||
|
@ -450,7 +450,7 @@ void play_turn(game_data& gameinfo, game_state& state_of_game,
|
|||
gui::OK_CANCEL,&options,
|
||||
&state_of_game.available_units);
|
||||
if(res >= 0) {
|
||||
|
||||
|
||||
const std::string err = recruit_unit(map,team_num,
|
||||
units,state_of_game.available_units[res],
|
||||
last_hex,&gui);
|
||||
|
@ -475,7 +475,7 @@ void play_turn(game_data& gameinfo, game_state& state_of_game,
|
|||
else if(result == string_table["recruit"]) {
|
||||
|
||||
std::vector<unit> sample_units;
|
||||
|
||||
|
||||
gui.draw(); //clear the old menu
|
||||
std::vector<std::string> item_keys;
|
||||
std::vector<std::string> items;
|
||||
|
@ -491,7 +491,7 @@ void play_turn(game_data& gameinfo, game_state& state_of_game,
|
|||
assert(false);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
const unit_type& type = u_type->second;
|
||||
std::stringstream description;
|
||||
|
||||
|
@ -510,14 +510,14 @@ void play_turn(game_data& gameinfo, game_state& state_of_game,
|
|||
const std::map<std::string,unit_type>::const_iterator
|
||||
u_type = gameinfo.unit_types.find(name);
|
||||
assert(u_type != gameinfo.unit_types.end());
|
||||
|
||||
|
||||
if(u_type->second.cost() > current_team.gold()) {
|
||||
gui::show_dialog(gui,NULL,"",
|
||||
string_table["not_enough_gold_to_recruit"],
|
||||
gui::OK_ONLY);
|
||||
} else {
|
||||
recorder.add_recruit(recruit_res,last_hex);
|
||||
|
||||
|
||||
//create a unit with traits
|
||||
unit new_unit(&(u_type->second),team_num,true);
|
||||
const std::string& msg =
|
||||
|
@ -539,7 +539,7 @@ void play_turn(game_data& gameinfo, game_state& state_of_game,
|
|||
string_table["hp"] + "," +
|
||||
string_table["xp"] + "," +
|
||||
string_table["moves"] + "," +
|
||||
string_table["location"];
|
||||
string_table["location"];
|
||||
|
||||
std::vector<std::string> items;
|
||||
items.push_back(heading);
|
||||
|
@ -549,7 +549,7 @@ void play_turn(game_data& gameinfo, game_state& state_of_game,
|
|||
i != units.end(); ++i) {
|
||||
if(i->second.side() != team_num)
|
||||
continue;
|
||||
|
||||
|
||||
std::stringstream row;
|
||||
row << i->second.name() << "," << i->second.hitpoints()
|
||||
<< "/" << i->second.max_hitpoints() << ","
|
||||
|
@ -572,7 +572,7 @@ void play_turn(game_data& gameinfo, game_state& state_of_game,
|
|||
gui::OK_ONLY,&items,&units_list);
|
||||
} else if(result == string_table["save_game"]) {
|
||||
std::stringstream stream;
|
||||
stream << string_table["scenario"]
|
||||
stream << string_table["scenario"]
|
||||
<< " " << (state_of_game.scenario+1)
|
||||
<< " " << string_table["turn"]
|
||||
<< " " << status.turn();
|
||||
|
@ -593,7 +593,7 @@ void play_turn(game_data& gameinfo, game_state& state_of_game,
|
|||
}
|
||||
|
||||
right_button = new_right_button;
|
||||
|
||||
|
||||
if(key[KEY_UP] || mousey == 0)
|
||||
gui.scroll(0.0,-scroll_speed);
|
||||
|
||||
|
@ -655,7 +655,7 @@ void play_turn(game_data& gameinfo, game_state& state_of_game,
|
|||
items.push_back(string_table["terrain"] + "," +
|
||||
string_table["movement"] + "," +
|
||||
string_table["defense"]);
|
||||
|
||||
|
||||
const unit_type& type = un->second.type();
|
||||
const unit_movement_type& move_type =
|
||||
type.movement_type();
|
||||
|
@ -668,9 +668,9 @@ void play_turn(game_data& gameinfo, game_state& state_of_game,
|
|||
const std::string& name = map.terrain_name(*t);
|
||||
const std::string& lang_name = string_table[name];
|
||||
const int moves = move_type.movement_cost(map,*t);
|
||||
|
||||
|
||||
const double defense = move_type.defense_modifier(map,*t);
|
||||
|
||||
|
||||
const int def = int(100.0-ceil(100.0*defense));
|
||||
|
||||
std::stringstream str;
|
||||
|
@ -679,7 +679,7 @@ void play_turn(game_data& gameinfo, game_state& state_of_game,
|
|||
str << moves;
|
||||
else
|
||||
str << "--";
|
||||
|
||||
|
||||
str << "," << def << "%";
|
||||
|
||||
items.push_back(str.str());
|
||||
|
@ -705,7 +705,7 @@ void play_turn(game_data& gameinfo, game_state& state_of_game,
|
|||
redo_stack.clear();
|
||||
un->second.set_movement(0);
|
||||
gui.draw_tile(selected_hex.x,selected_hex.y);
|
||||
|
||||
|
||||
gui.set_paths(NULL);
|
||||
current_paths = paths();
|
||||
recorder.add_movement(selected_hex,selected_hex);
|
||||
|
@ -830,7 +830,7 @@ void play_turn(game_data& gameinfo, game_state& state_of_game,
|
|||
undo_stack.push_back(redo_stack.back());
|
||||
redo_stack.pop_back();
|
||||
}
|
||||
|
||||
|
||||
gui.draw();
|
||||
|
||||
game_events::pump();
|
||||
|
|
|
@ -38,7 +38,7 @@ struct paths_wiper
|
|||
{}
|
||||
|
||||
~paths_wiper() { gui_.set_paths(NULL); }
|
||||
|
||||
|
||||
private:
|
||||
display& gui_;
|
||||
};
|
||||
|
|
|
@ -210,7 +210,7 @@ void show_preferences_dialog(display& disp)
|
|||
|
||||
disp.invalidate_all();
|
||||
disp.draw();
|
||||
|
||||
|
||||
SDL_Rect clip_rect = {0,0,disp.x(),disp.y()};
|
||||
SDL_Rect title_rect = font::draw_text(NULL,clip_rect,16,font::NORMAL_COLOUR,
|
||||
string_table["preferences"],0,0);
|
||||
|
@ -226,16 +226,16 @@ void show_preferences_dialog(display& disp)
|
|||
SDL_Rect music_rect = {0,0,0,0};
|
||||
music_rect = font::draw_text(NULL,clip_rect,14,font::NORMAL_COLOUR,
|
||||
music_label,0,0);
|
||||
|
||||
|
||||
SDL_Rect sound_rect = {0,0,0,0};
|
||||
sound_rect = font::draw_text(NULL,clip_rect,14,font::NORMAL_COLOUR,
|
||||
sound_label,0,0);
|
||||
|
||||
|
||||
const int text_right = xpos + maximum(music_rect.w,sound_rect.w) + 5;
|
||||
|
||||
const int music_pos = ypos + title_rect.h + 20;
|
||||
const int sound_pos = music_pos + 50;
|
||||
|
||||
|
||||
music_rect.x = text_right - music_rect.w;
|
||||
music_rect.y = music_pos;
|
||||
|
||||
|
@ -360,7 +360,7 @@ void show_video_mode_dialog(display& disp)
|
|||
{
|
||||
std::vector<std::pair<int,int> > resolutions;
|
||||
std::vector<std::string> options;
|
||||
|
||||
|
||||
CVideo& video = disp.video();
|
||||
SDL_Rect** modes = SDL_ListModes(video.getSurface()->format,FULL_SCREEN);
|
||||
if(reinterpret_cast<int>(modes) == -1 || modes == NULL)
|
||||
|
|
36
replay.cpp
36
replay.cpp
|
@ -138,7 +138,7 @@ void replay::add_pos(const std::string& type,
|
|||
config* const move = new config();
|
||||
config* const src = new config();
|
||||
config* const dst = new config();
|
||||
|
||||
|
||||
char buf[100];
|
||||
sprintf(buf,"%d",a.x+1);
|
||||
src->values["x"] = buf;
|
||||
|
@ -219,7 +219,7 @@ int replay::get_random()
|
|||
const int res = rand();
|
||||
char buf[100];
|
||||
sprintf(buf,"%d",res);
|
||||
|
||||
|
||||
current_ = new config();
|
||||
current_->values["value"] = buf;
|
||||
random.push_back(current_);
|
||||
|
@ -266,12 +266,12 @@ bool do_replay(display& disp, const gamemap& map, const game_data& gameinfo,
|
|||
game_state& state_of_game)
|
||||
{
|
||||
update_locker lock_update(disp,recorder.skipping());
|
||||
|
||||
|
||||
//a list of units that have promoted from the last attack
|
||||
std::deque<gamemap::location> advancing_units;
|
||||
|
||||
|
||||
team& current_team = teams[team_num-1];
|
||||
|
||||
|
||||
for(;;) {
|
||||
config* const cfg = recorder.get_next_action();
|
||||
|
||||
|
@ -298,18 +298,18 @@ bool do_replay(display& disp, const gamemap& map, const game_data& gameinfo,
|
|||
std::cerr << "illegal advancement type\n";
|
||||
throw replay::error();
|
||||
}
|
||||
|
||||
|
||||
advance_unit(gameinfo,units,advancing_units.front(),options[val]);
|
||||
|
||||
|
||||
advancing_units.pop_front();
|
||||
}
|
||||
|
||||
|
||||
//if there is nothing more in the records
|
||||
else if(cfg == NULL) {
|
||||
recorder.set_skip(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//if there is an end turn directive
|
||||
else if(cfg->children.find("end_turn") != cfg->children.end()) {
|
||||
recorder.next_skip();
|
||||
|
@ -359,7 +359,7 @@ bool do_replay(display& disp, const gamemap& map, const game_data& gameinfo,
|
|||
assert(!it->second.empty());
|
||||
|
||||
config* const move = it->second.front();
|
||||
|
||||
|
||||
assert(!move->children["destination"].empty());
|
||||
assert(!move->children["source"].empty());
|
||||
|
||||
|
@ -373,10 +373,10 @@ bool do_replay(display& disp, const gamemap& map, const game_data& gameinfo,
|
|||
<< dst.x << "," << dst.y << "\n";
|
||||
throw replay::error();
|
||||
}
|
||||
|
||||
|
||||
const bool ignore_zocs = u->second.type().is_skirmisher();
|
||||
const bool teleport = u->second.type().teleports();
|
||||
|
||||
|
||||
paths paths_list(map,gameinfo,units,src,teams,ignore_zocs,teleport);
|
||||
paths_wiper wiper(disp);
|
||||
|
||||
|
@ -400,7 +400,7 @@ bool do_replay(display& disp, const gamemap& map, const game_data& gameinfo,
|
|||
|
||||
if(!recorder.skipping())
|
||||
disp.move_unit(rt->second.steps,current_unit);
|
||||
|
||||
|
||||
current_unit.set_movement(rt->second.move_left);
|
||||
units.insert(std::pair<gamemap::location,unit>(dst,current_unit));
|
||||
if(map[dst.x][dst.y] == gamemap::TOWER) {
|
||||
|
@ -420,7 +420,7 @@ bool do_replay(display& disp, const gamemap& map, const game_data& gameinfo,
|
|||
assert(!it->second.empty());
|
||||
|
||||
config* const move = it->second.front();
|
||||
|
||||
|
||||
assert(!move->children["destination"].empty());
|
||||
assert(!move->children["source"].empty());
|
||||
|
||||
|
@ -440,7 +440,7 @@ bool do_replay(display& disp, const gamemap& map, const game_data& gameinfo,
|
|||
std::cerr << "illegal weapon type in attack\n";
|
||||
throw replay::error();
|
||||
}
|
||||
|
||||
|
||||
std::map<gamemap::location,unit>::const_iterator tgt =
|
||||
units.find(dst);
|
||||
|
||||
|
@ -448,12 +448,12 @@ bool do_replay(display& disp, const gamemap& map, const game_data& gameinfo,
|
|||
std::cerr << "unfound defender for attack\n";
|
||||
throw replay::error();
|
||||
}
|
||||
|
||||
|
||||
game_events::fire("attack",src,dst);
|
||||
|
||||
u = units.find(src);
|
||||
tgt = units.find(dst);
|
||||
|
||||
|
||||
if(u != units.end() && tgt != units.end()) {
|
||||
attack(disp,map,src,dst,weapon_num,units,state,gameinfo,false);
|
||||
const int res = check_victory(units);
|
||||
|
@ -462,7 +462,7 @@ bool do_replay(display& disp, const gamemap& map, const game_data& gameinfo,
|
|||
else if(res > 1)
|
||||
throw end_level_exception(DEFEAT);
|
||||
}
|
||||
|
||||
|
||||
u = units.find(src);
|
||||
tgt = units.find(dst);
|
||||
|
||||
|
|
|
@ -53,14 +53,14 @@ class scoped_resource
|
|||
{
|
||||
T resource;
|
||||
ReleasePolicy release;
|
||||
|
||||
|
||||
//prohibited operations
|
||||
scoped_resource(const scoped_resource&);
|
||||
scoped_resource& operator=(const scoped_resource&);
|
||||
public:
|
||||
typedef T resource_type;
|
||||
typedef ReleasePolicy release_type;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
|
|
|
@ -27,7 +27,7 @@ SDL_Surface* scale_surface(SDL_Surface* surface, int w, int h)
|
|||
static_cast<double>(w);
|
||||
const double yratio = static_cast<double>(surface->h)/
|
||||
static_cast<double>(h);
|
||||
|
||||
|
||||
const int srcxpad = (surface->w%2) == 1 ? 1:0;
|
||||
const int dstxpad = (dest->w%2) == 1 ? 1:0;
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ struct pixel_data
|
|||
pixel_data(config& cfg) {
|
||||
read(cfg);
|
||||
}
|
||||
|
||||
|
||||
int format(SDL_PixelFormat* fmt) const {
|
||||
return SDL_MapRGB(fmt,r,g,b);
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ struct pixel_data
|
|||
g = ((pixel&fmt->Gmask) >> fmt->Gshift);
|
||||
b = ((pixel&fmt->Bmask) >> fmt->Bshift);
|
||||
}
|
||||
|
||||
|
||||
void read(config& cfg) {
|
||||
const std::string& red = cfg.values["red"];
|
||||
const std::string& green = cfg.values["green"];
|
||||
|
@ -77,7 +77,7 @@ struct pixel_data
|
|||
else
|
||||
b = atoi(blue.c_str());
|
||||
}
|
||||
|
||||
|
||||
int r, g, b;
|
||||
};
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#include <string>
|
||||
|
||||
namespace sound {
|
||||
|
||||
|
||||
struct manager {
|
||||
manager();
|
||||
~manager();
|
||||
|
@ -27,7 +27,7 @@ void play_sound(const std::string& file);
|
|||
|
||||
void set_music_volume(double vol);
|
||||
void set_sound_volume(double vol);
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
2
team.cpp
2
team.cpp
|
@ -147,7 +147,7 @@ bool team::is_enemy(int n) const
|
|||
//if enemies aren't listed, then everyone is an enemy
|
||||
if(info_.enemies.empty())
|
||||
return true;
|
||||
|
||||
|
||||
return std::find(info_.enemies.begin(),info_.enemies.end(),n) !=
|
||||
info_.enemies.end();
|
||||
}
|
||||
|
|
2
team.hpp
2
team.hpp
|
@ -46,7 +46,7 @@ public:
|
|||
|
||||
std::vector<target> targets;
|
||||
};
|
||||
|
||||
|
||||
team(config& cfg, int gold=100);
|
||||
void get_tower(const gamemap::location&);
|
||||
void lose_tower(const gamemap::location&);
|
||||
|
|
|
@ -28,7 +28,7 @@ public:
|
|||
const std::string& name() const;
|
||||
char letter() const;
|
||||
char type() const;
|
||||
|
||||
|
||||
pixel_data get_rgb() const;
|
||||
|
||||
bool is_alias() const;
|
||||
|
|
20
unit.cpp
20
unit.cpp
|
@ -204,7 +204,7 @@ void unit::new_level()
|
|||
|
||||
//reapply all permanent modifications
|
||||
apply_modifications();
|
||||
|
||||
|
||||
heal_all();
|
||||
statusFlags_.clear();
|
||||
}
|
||||
|
@ -293,7 +293,7 @@ bool unit::matches_filter(config& cfg) const
|
|||
}
|
||||
|
||||
const std::string& this_type = this->type().name();
|
||||
|
||||
|
||||
//the type could be a comma-seperated list of types
|
||||
if(type.empty() == false && type != this_type) {
|
||||
|
||||
|
@ -304,11 +304,11 @@ bool unit::matches_filter(config& cfg) const
|
|||
std::search(type.begin(),type.end(),this_type.begin(),this_type.end()) !=
|
||||
type.end()) {
|
||||
const std::vector<std::string>& vals = config::split(type);
|
||||
|
||||
|
||||
if(std::find(vals.begin(),vals.end(),this_type) == vals.end()) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -335,7 +335,7 @@ bool unit::matches_filter(config& cfg) const
|
|||
|
||||
if(role.empty() == false && role_ != role)
|
||||
return false;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -482,7 +482,7 @@ const std::string& unit::image() const
|
|||
case STATE_ATTACKING: {
|
||||
if(attackType_ == NULL)
|
||||
return type_->image();
|
||||
|
||||
|
||||
const std::string* const img =
|
||||
attackType_->get_frame(attackingMilliseconds_);
|
||||
|
||||
|
@ -535,18 +535,18 @@ bool unit::is_guardian() const
|
|||
void unit::add_modification(const std::string& type, config& mod, bool no_add)
|
||||
{
|
||||
const std::string& span = mod.values["duration"];
|
||||
|
||||
|
||||
if(no_add == false && (span.empty() || span == "forever"))
|
||||
modifications_.children[type].push_back(new config(mod));
|
||||
|
||||
const std::vector<config*>& effects = mod.children["effect"];
|
||||
for(std::vector<config*>::const_iterator i = effects.begin();
|
||||
i != effects.end(); ++i) {
|
||||
|
||||
|
||||
const std::string& apply_to = (*i)->values["apply_to"];
|
||||
|
||||
if(apply_to == "new_attack") {
|
||||
attacks_.push_back(attack_type(**i));
|
||||
attacks_.push_back(attack_type(**i));
|
||||
} else if(apply_to == "attack") {
|
||||
for(std::vector<attack_type>::iterator a = attacks_.begin();
|
||||
a != attacks_.end(); ++a) {
|
||||
|
@ -573,7 +573,7 @@ void unit::add_modification(const std::string& type, config& mod, bool no_add)
|
|||
|
||||
if(maxHitpoints_ < 1)
|
||||
maxHitpoints_ = 1;
|
||||
|
||||
|
||||
if(heal_full.empty() == false && heal_full != "no") {
|
||||
heal_all();
|
||||
}
|
||||
|
|
6
unit.hpp
6
unit.hpp
|
@ -63,7 +63,7 @@ public:
|
|||
void set_flag(const std::string& flag);
|
||||
void remove_flag(const std::string& flag);
|
||||
bool has_flag(const std::string& flag) const;
|
||||
|
||||
|
||||
void read(game_data& data, config& cfg);
|
||||
|
||||
void write(config& cfg) const;
|
||||
|
@ -85,7 +85,7 @@ public:
|
|||
|
||||
bool facing_left() const;
|
||||
void set_facing_left(bool newval);
|
||||
|
||||
|
||||
const std::string& traits_description() const;
|
||||
|
||||
int value() const;
|
||||
|
@ -104,7 +104,7 @@ private:
|
|||
STATE state_;
|
||||
const attack_type* attackType_;
|
||||
int attackingMilliseconds_;
|
||||
|
||||
|
||||
int hitpoints_;
|
||||
int maxHitpoints_, backupMaxHitpoints_;
|
||||
int experience_;
|
||||
|
|
|
@ -67,7 +67,7 @@ attack_type::attack_type(config& cfg)
|
|||
sound.on_miss = (*i)->values["sound_miss"];
|
||||
if(sound.on_miss.empty())
|
||||
sound.on_miss = sound.on_hit;
|
||||
|
||||
|
||||
if(sound.on_miss == "null")
|
||||
sound.on_miss = "";
|
||||
|
||||
|
@ -237,7 +237,7 @@ int unit_movement_type::movement_cost(const gamemap& map,
|
|||
if(i != moveCosts_.end()) {
|
||||
return i->second;
|
||||
}
|
||||
|
||||
|
||||
const std::vector<config*>& v = cfg_.children["movement costs"];
|
||||
if(v.empty())
|
||||
return 1;
|
||||
|
@ -268,7 +268,7 @@ double unit_movement_type::defense_modifier(const gamemap& map,
|
|||
if(i != defenseMods_.end()) {
|
||||
return i->second;
|
||||
}
|
||||
|
||||
|
||||
const std::vector<config*>& v = cfg_.children["defense"];
|
||||
if(v.empty())
|
||||
return 1;
|
||||
|
@ -414,7 +414,7 @@ const std::string& unit_type::unit_description() const
|
|||
const std::string& lang_desc = string_table[id() + "_description"];
|
||||
if(lang_desc.empty() == false)
|
||||
return lang_desc;
|
||||
|
||||
|
||||
const std::string& desc = cfg_.values["unit_description"];
|
||||
if(desc.empty())
|
||||
return default_val;
|
||||
|
|
|
@ -26,7 +26,7 @@ class attack_type
|
|||
{
|
||||
public:
|
||||
enum RANGE { SHORT_RANGE, LONG_RANGE };
|
||||
|
||||
|
||||
attack_type(config& cfg);
|
||||
const std::string& name() const;
|
||||
const std::string& type() const;
|
||||
|
@ -129,7 +129,7 @@ public:
|
|||
int hitpoints() const;
|
||||
std::vector<attack_type> attacks() const;
|
||||
const unit_movement_type& movement_type() const;
|
||||
|
||||
|
||||
int experience_needed() const;
|
||||
std::vector<std::string> advances_to() const;
|
||||
const std::string& usage() const;
|
||||
|
|
30
video.cpp
30
video.cpp
|
@ -31,19 +31,19 @@ int main( int argc, char** argv )
|
|||
}
|
||||
SDL_Init(SDL_INIT_VIDEO);
|
||||
CVideo video;
|
||||
|
||||
|
||||
printf( "args: %s, %s, %s\n", argv[1], argv[2], argv[3] );
|
||||
|
||||
|
||||
printf( "(%d,%d,%d)\n", strtoul(argv[1],0,10), strtoul(argv[2],0,10),
|
||||
strtoul(argv[3],0,10) );
|
||||
|
||||
|
||||
if( video.setMode( strtoul(argv[1],0,10), strtoul(argv[2],0,10),
|
||||
strtoul(argv[3],0,10), FULL_SCREEN ) ) {
|
||||
printf( "video mode possible\n" );
|
||||
} else printf( "video mode NOT possible\n" );
|
||||
printf( "%d, %d, %d\n", video.getx(), video.gety(),
|
||||
video.getBitsPerPixel() );
|
||||
|
||||
|
||||
for( int s = 0; s < 50; s++ ) {
|
||||
video.lock();
|
||||
for( int i = 0; i < video.getx(); i++ )
|
||||
|
@ -78,7 +78,7 @@ CVideo::CVideo( int x, int y, int bits_per_pixel, int flags, const char* text )
|
|||
if(res < 0) {
|
||||
throw error();
|
||||
}
|
||||
|
||||
|
||||
setMode( x, y, bits_per_pixel, flags );
|
||||
|
||||
for(int i = 0; i != sizeof(text_); ++i) {
|
||||
|
@ -100,7 +100,7 @@ int CVideo::modePossible( int x, int y, int bits_per_pixel, int flags )
|
|||
int CVideo::setMode( int x, int y, int bits_per_pixel, int flags )
|
||||
{
|
||||
const int res = SDL_VideoModeOK( x, y, bits_per_pixel, flags );
|
||||
|
||||
|
||||
if( res == 0 )
|
||||
return 0;
|
||||
|
||||
|
@ -206,10 +206,10 @@ void CVideo::setPixel( int x, int y, int p )
|
|||
static char* p3 = ((char*)&pixel)+2;
|
||||
static short* sp = ((short*)&pixel);
|
||||
pixel = p;
|
||||
|
||||
|
||||
if( x < 0 || x >= backBuffer->w || y < 0 || y >= backBuffer->h )
|
||||
return;
|
||||
|
||||
|
||||
switch( backBuffer->format->BytesPerPixel ) {
|
||||
case 1:
|
||||
*((char*)backBuffer->pixels+y*backBuffer->w+x) = *p1;
|
||||
|
@ -237,23 +237,23 @@ void CVideo::update( int x, int y, int w, int h )
|
|||
{
|
||||
if( w == 0 || h == 0 )
|
||||
return;
|
||||
|
||||
|
||||
if( x < 0 ) {
|
||||
w += x;
|
||||
x = 0;
|
||||
}
|
||||
|
||||
|
||||
if( y < 0 ) {
|
||||
h += y;
|
||||
y = 0;
|
||||
}
|
||||
|
||||
|
||||
if( x+w > frameBuffer->w )
|
||||
w = frameBuffer->w - x;
|
||||
|
||||
|
||||
if( y+h > frameBuffer->h )
|
||||
h = frameBuffer->h - y;
|
||||
|
||||
|
||||
SRectangle rect = {x,y,w,h};
|
||||
SDL_BlitSurface( backBuffer, &rect, frameBuffer, &rect );
|
||||
SDL_UpdateRect( frameBuffer, x, y, w, h );
|
||||
|
@ -302,12 +302,12 @@ int CVideo::drawText(int x, int y, int pixel, int bg, const char* text, int sz)
|
|||
if(*text == '@') {
|
||||
colour = good_colour;
|
||||
} else if(*text == '#') {
|
||||
colour = bad_colour;
|
||||
colour = bad_colour;
|
||||
} else if(*text == '\n') {
|
||||
colour = pixel;
|
||||
y += 8*sz;
|
||||
x = startx;
|
||||
} else {
|
||||
} else {
|
||||
drawChar(x,y,colour,bg == pixel ? colour : bg,*text,sz);
|
||||
x += 8*sz;
|
||||
}
|
||||
|
|
10
video.hpp
10
video.hpp
|
@ -27,10 +27,10 @@ class CVideo {
|
|||
CVideo(const char* text);
|
||||
CVideo( int x, int y, int bits_per_pixel, int flags, const char* text );
|
||||
~CVideo();
|
||||
|
||||
|
||||
int modePossible( int x, int y, int bits_per_pixel, int flags );
|
||||
int setMode( int x, int y, int bits_per_pixel, int flags );
|
||||
|
||||
|
||||
//functions to get the dimensions of the current video-mode
|
||||
int getx() const;
|
||||
int gety() const;
|
||||
|
@ -39,7 +39,7 @@ class CVideo {
|
|||
int getRedMask();
|
||||
int getGreenMask();
|
||||
int getBlueMask();
|
||||
|
||||
|
||||
//functions to access the screen
|
||||
void* getAddress();
|
||||
void lock();
|
||||
|
@ -50,7 +50,7 @@ class CVideo {
|
|||
int convertColour(int r, int g, int b);
|
||||
void update( int x, int y, int w, int h );
|
||||
void update( SRectangle* area );
|
||||
|
||||
|
||||
SDL_Surface* getSurface( void );
|
||||
|
||||
int drawText(int x, int y, int pixel, int bg, const char* text,int size=1);
|
||||
|
@ -58,7 +58,7 @@ class CVideo {
|
|||
bool isFullScreen() const;
|
||||
|
||||
struct error {};
|
||||
|
||||
|
||||
private:
|
||||
|
||||
void drawChar(int x, int y, int pixel, int bg, char c, int size=1);
|
||||
|
|
|
@ -19,7 +19,7 @@ namespace gui {
|
|||
const int font_size = 14;
|
||||
const int horizontal_padding = 10;
|
||||
const int vertical_padding = 10;
|
||||
|
||||
|
||||
button::button(display& disp, const std::string& label, button::TYPE type,
|
||||
const std::string& button_image_name) :
|
||||
label_(label), display_(&disp),
|
||||
|
@ -42,7 +42,7 @@ button::button(display& disp, const std::string& label, button::TYPE type,
|
|||
active_image = disp.getImage("buttons/" + button_image_name +
|
||||
"-button-active.png",display::UNSCALED);
|
||||
}
|
||||
|
||||
|
||||
if(pressed_image == NULL)
|
||||
pressed_image = button_image;
|
||||
|
||||
|
@ -87,7 +87,7 @@ button& button::operator=(const button& b)
|
|||
|
||||
if(pressedImage_ != NULL)
|
||||
SDL_FreeSurface(pressedImage_);
|
||||
|
||||
|
||||
label_ = b.label_;
|
||||
display_ = b.display_;
|
||||
image_ = scale_surface(b.image_,b.image_->w,b.image_->h);
|
||||
|
@ -101,7 +101,7 @@ button& button::operator=(const button& b)
|
|||
button_ = b.button_;
|
||||
state_ = b.state_;
|
||||
type_ = b.type_;
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -147,7 +147,7 @@ void button::draw()
|
|||
display_->blit_surface(x_,y_,image);
|
||||
font::draw_text(display_,clipArea,font_size,
|
||||
font::NORMAL_COLOUR,label_,textx,texty);
|
||||
|
||||
|
||||
display_->video().update(x_,y_,width(),height());
|
||||
}
|
||||
|
||||
|
@ -191,11 +191,11 @@ bool button::process(int mousex, int mousey, bool button)
|
|||
mouse_state = UP;
|
||||
|
||||
button_ = button;
|
||||
|
||||
|
||||
const STATE start_state = state_;
|
||||
|
||||
if(type_ == TYPE_PRESS) {
|
||||
|
||||
|
||||
switch(state_) {
|
||||
case UNINIT:
|
||||
state_ = NORMAL;
|
||||
|
|
|
@ -25,12 +25,12 @@ class button
|
|||
{
|
||||
public:
|
||||
struct error {};
|
||||
|
||||
|
||||
enum TYPE { TYPE_PRESS, TYPE_CHECK };
|
||||
|
||||
button(display& disp, const std::string& label, TYPE type=TYPE_PRESS,
|
||||
const std::string& button_image="");
|
||||
|
||||
|
||||
button(const button& b);
|
||||
button& operator=(const button& b);
|
||||
|
||||
|
@ -60,7 +60,7 @@ private:
|
|||
|
||||
enum STATE { UNINIT, NORMAL, ACTIVE, PRESSED };
|
||||
STATE state_;
|
||||
|
||||
|
||||
TYPE type_;
|
||||
|
||||
bool hit(int x, int y) const;
|
||||
|
|
|
@ -128,7 +128,7 @@ SDL_Rect slider::slider_area() const
|
|||
const int hpadding = image_->w/2;
|
||||
if(hpadding*2 >= area_.w)
|
||||
return default_value;
|
||||
|
||||
|
||||
const int position = int(value_*double(area_.w - hpadding*2));
|
||||
const int xpos = area_.x + position;
|
||||
SDL_Rect res = {xpos,area_.y,image_->w,image_->h};
|
||||
|
|
|
@ -53,12 +53,12 @@ void textbox::draw_cursor(int pos) const
|
|||
{
|
||||
const bool show_cursor = (SDL_GetTicks()%1000) > 500;
|
||||
static const short cursor_colour = 0xFFFF;
|
||||
|
||||
|
||||
if(show_cursor) {
|
||||
short* dst = reinterpret_cast<short*>(
|
||||
disp_.video().getSurface()->pixels) + y_*disp_.x() +
|
||||
x_ + pos;
|
||||
|
||||
|
||||
for(int i = 0; i != height(); ++i, dst += disp_.x()) {
|
||||
*dst = cursor_colour;
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ void textbox::draw() const
|
|||
int pos = 1;
|
||||
std::string str(1,'x');
|
||||
static const SDL_Rect clip = {0,0,1024,768};
|
||||
|
||||
|
||||
//draw the text
|
||||
for(int i = firstOnScreen_; i < text_.size(); ++i) {
|
||||
str[0] = text_[i];
|
||||
|
@ -95,7 +95,7 @@ void textbox::draw() const
|
|||
|
||||
font::draw_text(&disp_,clip,font_size,font::NORMAL_COLOUR,str,
|
||||
x_ + pos, y_);
|
||||
|
||||
|
||||
pos += area.w;
|
||||
|
||||
if(cursor_ == i+1)
|
||||
|
@ -143,7 +143,7 @@ void textbox::process()
|
|||
if(islower(character) && (key_[KEY_LSHIFT] || key_[KEY_RSHIFT])) {
|
||||
character = toupper(character);
|
||||
}
|
||||
|
||||
|
||||
const bool val = key_[c];
|
||||
if(val && !previousKeyState_[c-INPUT_CHAR_START]) {
|
||||
text_.insert(text_.begin()+cursor_,character);
|
||||
|
@ -152,7 +152,7 @@ void textbox::process()
|
|||
|
||||
previousKeyState_[c-INPUT_CHAR_START] = val;
|
||||
}
|
||||
|
||||
|
||||
draw();
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace gui {
|
|||
#define INPUT_CHAR_START (' ')
|
||||
#define INPUT_CHAR_END ('~' + 1)
|
||||
#define CHAR_LENGTH (INPUT_CHAR_END - INPUT_CHAR_START)
|
||||
|
||||
|
||||
class textbox
|
||||
{
|
||||
display& disp_;
|
||||
|
@ -39,7 +39,7 @@ class textbox
|
|||
bool lastLArrow_, lastRArrow_, lastDelete_, lastBackspace_;
|
||||
|
||||
void draw_cursor(int pos) const;
|
||||
|
||||
|
||||
public:
|
||||
textbox(display& disp, int width, const std::string& text="");
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue