made [teleport] work properly

This commit is contained in:
uid68803 2003-12-30 06:02:10 +00:00
parent dcdaa8c3bc
commit fcfbf1e884
19 changed files with 185 additions and 59 deletions

View file

@ -36,7 +36,7 @@
[message]
id=msg_kalenz_die
speaker=unit
message=Argh! I am finished with!
message=Argh! I am finished!
[/message]
[endlevel]
result=defeat

View file

@ -1,3 +1,107 @@
[multiplayer]
name="Accross The River"
map_data="ffffffffffffffgggggggggggggggggggggggg
ffffffffffffffffgggggggggggggggCgggtgg
ffffffffffffffffggggggggggggggC1Cggggg
fftfffffffffffffffggggtgggggggCCCggggg
ffffffffffffffffffgggggggggggggggggggg
fffffffffffffffffggggggggggggggggggggg
ffffffffffffffffffgggggggggggggggggggg
fffffgfgfffffftfffffgggggggggggggggRgg
fffffgggggffffffffffffffgggggggggggggg
fffgggggggfffffffffffffffgggggggtggggg
ggggtggggggfffffffffffffffgggggggggggg
ggggggggggggffffffffffffffgggggggggggm
gggggggggggggffffffffffcccccggggggggmm
mmgggggggtggggggfccccccccccccggggggmrm
mmmmmmgggggggggccccccccggggcccgggmmmrm
mmmmmmmggggggccccgggggggggggcccgmmmrrm
mmmmmmmmgggccccgggggggggtggggccgmmrmmm
mmmmmmmcgcccccgggggggggggggggcccccCcmm
mmmmmccccccgccccgggggggggggccccccccccc
ccmccccmcgggggccccggvggggccccggmmmcmcc
cccccmCmmgggggggccgggggccccfgggmmmmmmm
mmcmmrrmmgggggggccccgggccfffggggmmmmmm
mmmrrmmmgggggggggfcccccccffgggggggmmmm
mmmrmmmggggggggfffffcccffffgvgggggmmmm
mmmrmgggggggggfffffffffffffgggggggggmg
mmmgggggggvggfffffffffffffffgggggggggg
gggggggRgggggfffffffffffffffgggggggggg
gggggggggggggfffffffvffffffgggggvggfgf
gggggggggggggffffffffffffffggggggfffff
ggggggggggggggffffffffffffffgfgfffffff
gggCggggggggggffffffffffffffffffffffff
ggC2Cgggggggggggffffffffffffffffffffff
ggCCCggggggggggggfffffffffffffffffffff
gvgggggggggggvgggfffffffffffffffffffff
ggggggggggggggggggffffffffvfffffffffff
ggggggggggggggggggggffffffffffffffffff
"
turns=90
id=multiplayer_test
{DAWN}
{MORNING}
{AFTERNOON}
{DUSK}
{FIRST_WATCH}
{SECOND_WATCH}
[side]
side=1
enemy=2
canrecruit=1
controller=human
[/side]
[side]
side=2
enemy=1
canrecruit=1
controller=human
[/side]
[event]
name=moveto
[filter]
x=35
y=18
side=1
[/filter]
[command]
[teleport]
[filter]
x=35
y=18
side=1
[/filter]
x=8
y=27
[/teleport]
[/command]
[/event]
[event]
name=moveto
[filter]
x=7
y=21
side=2
[/filter]
[command]
[teleport]
[filter]
x=7
y=21
side=2
[/filter]
x=36
y=8
[/teleport]
[/command]
[/event]
[/multiplayer]
[multiplayer]
name=The Isle of Anduin
map=map1

View file

@ -533,7 +533,7 @@ The main cage where they keep most of the mermen is in the south-east!"
[message]
id=msg3_18
description=Konrad
message=Now where is Delfador? I hope he's ok!
message=Now where is Delfador? I hope he's safe!
[/message]
[unit]
x=18
@ -544,12 +544,12 @@ The main cage where they keep most of the mermen is in the south-east!"
[message]
id=msg3_19
description=Delfador
message=Ok indeed, friend.
message=I am perfectly safe, friend!
[/message]
[message]
id=msg3_20
description=Konrad
message=There you are! I am so glad you are alright! Now we may have a little rest.
message=There you are! I am so glad you are all right! Now we may have a little rest.
[/message]
[message]
id=msg3_21

View file

@ -217,7 +217,7 @@ We heard the news that the orcs were attacking the elvish woods and some of them
[message]
id=msg1b_10
description=Seimus
message="I could offer you a ship - I sent it to the open sea with the elder and the children, but it should arrive back in port soon."
message="I could offer you a ship - I sent it to the open sea with the elderly, the women, and the children, but it should arrive back in port soon."
[/message]
[message]

View file

@ -196,7 +196,7 @@ Defeat:
[message]
id=msg1_8
description=Urug-Telfar
message="Attack the Elves men, take their villages, let us claim this land for the Queen!"
message="Attack the Elves, my grunts, take their villages, let us claim this land for the Queen!"
[/message]
#on hard level, the enemies will specifically target Delfador and Konrad

View file

@ -150,7 +150,7 @@ Defeat:
[message]
id=msg6_6
description=Li'sar
message="This is taking too much time, I best call some reinforcements!"
message="This is taking too much time, I'd best call some reinforcements!"
[/message]
[/event]
[event]

View file

@ -295,7 +295,7 @@ Defeat:
[message]
id=msg5_21
description=Delfador
message=The Council has met, and we have decided: we must capture the Sceptre of Fire
message=The Council has met, and we have decided: we must capture the Sceptre of Fire.
[/message]
[message]

View file

@ -1,5 +1,5 @@
[theme]
name=default
name=Default
[resolution]
width=800
height=600

View file

@ -12,7 +12,7 @@ alignment=chaotic
advanceto=Necromancer
cost=17
usage=archer
unit_description="Dabbling in black magic, the dark adepts are phycotic fanatics who use it's powers to cause death and destruction."
unit_description="Dabbling in black magic, the dark adepts are phycotic fanatics who use its powers to cause death and destruction."
get_hit_sound=groan.wav
[attack]
name=magic

View file

@ -12,7 +12,7 @@ advanceto=null
cost=94
usage=healer
ability=cures
unit_description="Female elves that are devoted to nature and their faerie side slowly transform in Shides. Dragonfly wings sprout from her back and change them in beutifull creatures capable of gliding unencumbered in the elven forests."
unit_description="Female elves that are devoted to nature and their faerie side slowly transform in Shydes. Dragonfly wings sprout from her back and change them in beutifull creatures capable of gliding unencumbered in the elven forests."
get_hit_sound=groan.wav
[attack]

View file

@ -12,7 +12,7 @@ advanceto=null
cost=100
ability=leadership
usage=fighter
unit_description="The great leaders of the human armies, generals are responsible for the protection of large and/or important areas in the human kingdoms. The generals can coordinate the attacks of level 1 and 2 units, increasing their fighting efficiency."
unit_description="The great leaders of the human armies, generals are responsible for the protection of large or important areas in the human kingdoms. The generals can coordinate the attacks of level 1 and 2 units, increasing their fighting efficiency."
get_hit_sound=groan.wav
[attack]
name=sword

View file

@ -1013,8 +1013,7 @@ size_t move_unit(display* disp, const gamemap& map,
if(event_mutated) {
undo_stack->clear();
} else {
undo_stack->push_back(undo_action(steps,starting_moves,
orig_tower_owner));
undo_stack->push_back(undo_action(steps,starting_moves,orig_tower_owner));
}
}

View file

@ -256,26 +256,28 @@ void event_handler::handle_event_command(const queued_event& event_info, const s
//teleport a unit from one location to another
else if(cmd == "teleport") {
unit_map::iterator u = units->find(event_info.loc1);
//search for a valid unit filter, and if we have one, look for the matching unit
const config* const filter = cfg.child("filter");
if(filter != NULL) {
unit_map::iterator u;
if(filter != NULL) {
for(u = units->begin(); u != units->end(); ++u){
if(u->second.matches_filter(*filter))
if(game_events::unit_matches_filter(u,*filter))
break;
}
}
//we have found a unit that matches the filter
if(u != units->end()) {
const gamemap::location dst(cfg);
if(game_map->on_board(dst)) {
const gamemap::location vacant_dst = find_vacant_tile(*game_map,*units,dst,(*game_map)[dst.x][dst.y]);
if(game_map->on_board(vacant_dst)) {
//note that inserting into a map does NOT invalidate iterators
//into the map, so this sequence is fine.
units->insert(std::pair<gamemap::location,unit>(vacant_dst,u->second));
units->erase(u);
}
//we have found a unit that matches the filter
if(u != units->end()) {
const gamemap::location dst(cfg);
if(game_map->on_board(dst)) {
const gamemap::location vacant_dst = find_vacant_tile(*game_map,*units,dst,(*game_map)[dst.x][dst.y]);
if(game_map->on_board(vacant_dst)) {
//note that inserting into a map does NOT invalidate iterators
//into the map, so this sequence is fine.
units->insert(std::pair<gamemap::location,unit>(vacant_dst,u->second));
units->erase(u);
}
}
}
@ -355,7 +357,7 @@ void event_handler::handle_event_command(const queued_event& event_info, const s
else if(cmd == "scroll_to_unit") {
unit_map::const_iterator u;
for(u = units->begin(); u != units->end(); ++u){
if(u->second.matches_filter(cfg))
if(game_events::unit_matches_filter(u,cfg))
break;
}
@ -451,7 +453,7 @@ void event_handler::handle_event_command(const queued_event& event_info, const s
std::map<gamemap::location,unit>::iterator itor;
for(itor = units->begin(); itor != units->end(); ++itor) {
if(itor->second.matches_filter(item)) {
if(game_events::unit_matches_filter(itor,item)) {
itor->second.assign_role(cfg["role"]);
break;
}
@ -612,9 +614,8 @@ void event_handler::handle_event_command(const queued_event& event_info, const s
} else if(cfg["speaker"] == "second_unit") {
speaker = units->find(event_info.loc2);
} else if(cfg["speaker"] != "narrator") {
for(speaker = units->begin(); speaker != units->end();
++speaker){
if(speaker->second.matches_filter(cfg))
for(speaker = units->begin(); speaker != units->end(); ++speaker){
if(game_events::unit_matches_filter(speaker,cfg))
break;
}
@ -713,7 +714,7 @@ void event_handler::handle_event_command(const queued_event& event_info, const s
for(std::map<gamemap::location,unit>::iterator un = units->begin();
un != units->end(); ++un) {
while(un != units->end() && un->second.matches_filter(cfg)) {
while(un != units->end() && game_events::unit_matches_filter(un,cfg)) {
units->erase(un);
un = units->begin();
}
@ -821,10 +822,10 @@ bool filter_loc_impl(const gamemap::location& loc, const std::string& xloc,
return true;
}
bool filter_loc(const gamemap::location& loc, config& cfg)
bool filter_loc(const gamemap::location& loc, const config& cfg)
{
const std::string& xloc = cfg.values["x"];
const std::string& yloc = cfg.values["y"];
const std::string& xloc = cfg["x"];
const std::string& yloc = cfg["y"];
return filter_loc_impl(loc,xloc,yloc);
}
@ -840,23 +841,16 @@ bool process_event(event_handler& handler, const queued_event& ev)
const config::child_list& first_filters = handler.first_arg_filters();
for(config::child_list::const_iterator ffi = first_filters.begin();
ffi != first_filters.end(); ++ffi) {
if(!filter_loc(ev.loc1,**ffi))
return false;
if(unit1 != units->end() && !unit1->second.matches_filter(**ffi)) {
if(!game_events::unit_matches_filter(unit1,**ffi))
return false;
}
}
const config::child_list& second_filters = handler.second_arg_filters();
for(config::child_list::const_iterator sfi = second_filters.begin();
sfi != second_filters.end(); ++sfi) {
if(!filter_loc(ev.loc2,**sfi))
if(!game_events::unit_matches_filter(unit2,**sfi))
return false;
if(unit2 != units->end() && !unit2->second.matches_filter(**sfi)) {
return false;
}
}
//the event hasn't been filtered out, so execute the handler
@ -872,6 +866,11 @@ bool process_event(event_handler& handler, const queued_event& ev)
namespace game_events {
bool unit_matches_filter(unit_map::const_iterator itor, const config& filter)
{
return filter_loc(itor->first,filter) && itor->second.matches_filter(filter);
}
const std::string& get_variable(const std::string& key)
{
static const std::string empty_string;

View file

@ -53,6 +53,8 @@ struct manager {
void write_events(config& cfg);
bool unit_matches_filter(unit_map::const_iterator itor, const config& filter);
//function to fire an event. Events may have up to two arguments, both of
//which must be locations.
bool fire(const std::string& event,

View file

@ -132,7 +132,7 @@ LEVEL_RESULT play_level(game_data& gameinfo, config& game_config,
}
}
const config* const theme_cfg = game_config.child("theme");
const config* const theme_cfg = game_config.find_child("theme","name",preferences::theme());
const config dummy_cfg;
display gui(units,video,map,status,teams,theme_cfg != NULL ? *theme_cfg : dummy_cfg);

View file

@ -531,23 +531,27 @@ void turn_info::left_click(const SDL_MouseButtonEvent& event)
assert(moves <= current_route_.steps.size());
const gamemap::location& dst = current_route_.steps[moves-1];
const unit_map::const_iterator u = units_.find(dst);
assert(u != units_.end());
const int range = u->second.longest_range();
//u may be equal to units_.end() in the case of e.g. a [teleport]
if(u != units_.end()) {
assert(u != units_.end());
current_route_.steps.clear();
const int range = u->second.longest_range();
show_attack_options(u);
current_route_.steps.clear();
if(current_paths_.routes.empty() == false) {
current_paths_.routes[dst] = paths::route();
selected_hex_ = dst;
gui_.select_hex(dst);
gui_.set_paths(&current_paths_);
}
show_attack_options(u);
if(clear_shroud(gui_,map_,gameinfo_,units_,teams_,team_num_-1)) {
undo_stack_.clear();
if(current_paths_.routes.empty() == false) {
current_paths_.routes[dst] = paths::route();
selected_hex_ = dst;
gui_.select_hex(dst);
gui_.set_paths(&current_paths_);
}
if(clear_shroud(gui_,map_,gameinfo_,units_,teams_,team_num_-1)) {
undo_stack_.clear();
}
}
} else {
gui_.set_paths(NULL);

View file

@ -347,6 +347,20 @@ std::string client_type()
return "human";
}
const std::string& theme()
{
std::string& res = prefs["theme"];
if(res.empty())
res = "Default";
return res;
}
void set_theme(const std::string& theme)
{
prefs["theme"] = theme;
}
void show_preferences_dialog(display& disp)
{
const events::resize_lock prevent_resizing;

View file

@ -81,6 +81,9 @@ namespace preferences {
std::string client_type();
void set_theme(const std::string& theme);
const std::string& theme();
void show_preferences_dialog(display& disp);
bool show_video_mode_dialog(display& disp);
void show_hotkeys_dialog (display & disp);

View file

@ -15,6 +15,7 @@
#include "SDL.h"
#include <string>
#include <vector>
class display;