allow some slots to be empty in a multiplayer game

This commit is contained in:
Dave White 2004-05-26 19:41:53 +00:00
parent 60ac5ca351
commit 0ace5f099e
11 changed files with 83 additions and 25 deletions

View file

@ -121,45 +121,54 @@ road_windiness=3
#road costs
[road_cost]
terrain=g
cost=1
cost=10
convert_to=r
[/road_cost]
[road_cost]
terrain=d
cost=2
cost=25
convert_to=r
[/road_cost]
[road_cost]
terrain=f
cost=3
cost=20
convert_to=r
[/road_cost]
[road_cost]
terrain=c
cost=10
cost=50
convert_to_bridge=|,/,\
convert_to=C
[/road_cost]
[road_cost]
terrain=h
cost=5
cost=30
convert_to=r
[/road_cost]
[road_cost]
terrain=m
cost=10
cost=50
convert_to=r
[/road_cost]
#road going through snow is covered over by
#the snow (presumably the road was built when
#it wasn't snowing)
[road_cost]
terrain=S
cost=20
convert_to=S
[/road_cost]
#define MIN_COST_ROAD X
[road_cost]
terrain={X}
cost=0.2
cost=2
convert_to={X}
[/road_cost]
#enddef
@ -170,15 +179,6 @@ road_windiness=3
{MIN_COST_ROAD \}
{MIN_COST_ROAD C}
#road going through snow is covered over by
#the snow (presumably the road was built when
#it wasn't snowing)
[road_cost]
terrain=S
cost=2
convert_to=S
[/road_cost]
[village]
terrain=g

View file

@ -339,6 +339,7 @@ kilobytes="KB"
human_controlled="Local Player"
ai_controlled="Computer Player"
network_controlled="Network Player"
null_controlled="Empty"
remote_host="Choose host to connect to"
connection_failed="Could not connect to the remote host"
connection_timeout="Connection timed out"

View file

@ -19,6 +19,7 @@
#include "game_events.hpp"
#include "key.hpp"
#include "language.hpp"
#include "log.hpp"
#include "map.hpp"
#include "pathfind.hpp"
#include "playlevel.hpp"
@ -546,6 +547,8 @@ void attack(display& gui, const gamemap& map,
static const std::string poison_string("poison");
while(stats.nattacks > 0 || stats.ndefends > 0) {
std::cerr << "start of attack loop...\n";
if(stats.nattacks > 0) {
const int ran_num = get_random();
bool hits = (ran_num%100) < stats.chance_to_hit_defender;
@ -585,10 +588,13 @@ void attack(display& gui, const gamemap& map,
hits ? stats.damage_defender_takes : 0,
a->second.attacks()[attack_with]);
std::cerr << "done attacking\n";
attack_stats.attack_result(hits ? (dies ? statistics::attack_context::KILLS : statistics::attack_context::HITS)
: statistics::attack_context::MISSES);
if(ran_results == NULL) {
log_scope("setting random results");
config cfg;
cfg["hits"] = (hits ? "yes" : "no");
cfg["dies"] = (dies ? "yes" : "no");
@ -681,6 +687,8 @@ void attack(display& gui, const gamemap& map,
}
if(stats.ndefends > 0) {
std::cerr << "doing defender attack...\n";
const int ran_num = get_random();
bool hits = (ran_num%100) < stats.chance_to_hit_attacker;

View file

@ -32,6 +32,8 @@ private:
std::map<int,effect> haloes;
int halo_id = 1;
bool hide_halo = false;
static const SDL_Rect empty_rect = {0,0,0,0};
effect::effect(int xpos, int ypos, const std::string& img)
@ -133,6 +135,16 @@ manager::~manager()
disp = old;
}
halo_hider::halo_hider() : old(hide_halo)
{
hide_halo = true;
}
halo_hider::~halo_hider()
{
hide_halo = old;
}
int add(int x, int y, const std::string& image)
{
const int id = halo_id++;
@ -147,6 +159,10 @@ void remove(int handle)
void render()
{
if(hide_halo) {
return;
}
for(std::map<int,effect>::iterator i = haloes.begin(); i != haloes.end(); ++i) {
i->second.render();
}
@ -154,6 +170,10 @@ void render()
void unrender()
{
if(hide_halo) {
return;
}
for(std::map<int,effect>::reverse_iterator i = haloes.rbegin(); i != haloes.rend(); ++i) {
i->second.unrender();
}

View file

@ -17,6 +17,14 @@ private:
display* const old;
};
struct halo_hider
{
halo_hider();
~halo_hider();
private:
bool old;
};
///function to add a haloing effect using 'image'
///centered on (x,y)
///returns the handle to the halo object

View file

@ -132,6 +132,10 @@ public:
return lobby::QUIT;
}
if(menu_ != NULL) {
menu_->process(mousex,mousey,button,false,false,false,false);
}
config reply;
const network::connection res = network::receive_data(reply);
if(res) {

View file

@ -256,6 +256,7 @@ void mp_connect::lists_init()
player_types_.push_back(string_table["network_controlled"]);
player_types_.push_back(string_table["human_controlled"]);
player_types_.push_back(string_table["ai_controlled"]);
player_types_.push_back(string_table["null_controlled"]);
player_types_.push_back("-----");
player_types_.push_back(preferences::login());
@ -462,7 +463,7 @@ void mp_connect::gui_update()
}
} else if (side["controller"] == "human") {
if (side["description"] == preferences::login()) {
combos_type_[n].set_selected(4);
combos_type_[n].set_selected(5);
} else if (side["description"] != "") {
//When loading a game and you use a name not originally used during
//the initial game, mark that original slot as network
@ -472,6 +473,8 @@ void mp_connect::gui_update()
}
} else if (side["controller"] == "ai") {
combos_type_[n].set_selected(2);
} else if(side["controller"] == "null") {
combos_type_[n].set_selected(3);
}
//Player Race
@ -556,15 +559,18 @@ lobby::RESULT mp_connect::process()
if(combos_type_[n].selected() == 0) {
side["controller"] = "network";
side["description"] = "";
}else if(combos_type_[n].selected() == 1){
} else if(combos_type_[n].selected() == 1){
side["controller"] = "human";
side["description"] = "";
}else if(combos_type_[n].selected() == 2){
} else if(combos_type_[n].selected() == 2){
side["controller"] = "ai";
side["description"] = string_table["ai_controlled"];
}else if(combos_type_[n].selected() == 3){
} else if(combos_type_[n].selected() == 3) {
side["controller"] = "null";
side["description"] = "";
} else if(combos_type_[n].selected() == 4){
combos_type_[n].set_selected(old_select);
}else if(combos_type_[n].selected() == 4){
} else if(combos_type_[n].selected() == 5){
side["controller"] = "human";
side["description"] = preferences::login();
for(size_t m = 0; m != combos_type_.size(); ++m) {

View file

@ -207,7 +207,7 @@ LEVEL_RESULT play_level(game_data& gameinfo, const config& game_config,
teams.push_back(team(**ui,ngold));
//if this side tag describes the leader of the side
if((**ui)["no_leader"] != "yes") {
if((**ui)["no_leader"] != "yes" && (**ui)["controller"] != "null") {
unit new_unit(gameinfo, **ui);
//search the recall list for leader units, and if there is
@ -410,8 +410,9 @@ LEVEL_RESULT play_level(game_data& gameinfo, const config& game_config,
player_number = (team_it - teams.begin()) + 1;
//if a side is dead, don't do their turn
if(team_units(units,player_number) == 0)
if(team_it->is_empty() || team_units(units,player_number) == 0) {
continue;
}
if(is_observer(teams)) {
gui.set_team(size_t(player_number-1));

View file

@ -18,6 +18,7 @@
#include "cursor.hpp"
#include "display.hpp"
#include "font.hpp"
#include "halo.hpp"
#include "network.hpp"
#include "unit.hpp"
#include "video.hpp"
@ -37,7 +38,7 @@ extern const int ButtonVPadding;
bool in_dialog();
struct dialog_manager : private cursor::setter, private font::floating_label_hider {
struct dialog_manager : private cursor::setter, private font::floating_label_hider, private halo::halo_hider {
dialog_manager();
~dialog_manager();

View file

@ -87,6 +87,8 @@ team::team_info::team_info(const config& cfg)
controller = HUMAN;
else if(cfg["controller"] == "network")
controller = NETWORK;
else if(cfg["controller"] == "null")
controller = EMPTY;
else
controller = AI;
@ -177,6 +179,7 @@ void team::team_info::write(config& cfg) const
case AI: cfg["controller"] = "ai"; break;
case HUMAN: cfg["controller"] = "human"; break;
case NETWORK: cfg["controller"] = "network"; break;
case EMPTY: cfg["controller"] = "null"; break;
default: assert(false);
}
@ -380,6 +383,11 @@ bool team::is_network() const
return info_.controller == team_info::NETWORK;
}
bool team::is_empty() const
{
return info_.controller == team_info::EMPTY;
}
void team::make_human()
{
info_.controller = team_info::HUMAN;

View file

@ -72,7 +72,7 @@ public:
std::string description;
enum CONTROLLER { HUMAN, AI, NETWORK };
enum CONTROLLER { HUMAN, AI, NETWORK, EMPTY };
CONTROLLER controller;
std::string ai_algorithm;
config ai_params;
@ -116,6 +116,7 @@ public:
bool is_human() const;
bool is_network() const;
bool is_ai() const;
bool is_empty() const;
void make_human();
void make_network();