Skip to content

Commit

Permalink
Merge pull request #216 from Rift-Walker/scenario_era_mod_defines_mer…
Browse files Browse the repository at this point in the history
…gable

Add define functionality to scenarios, eras, and mods
  • Loading branch information
AI0867 committed Jun 25, 2014
2 parents 198b89b + 6270674 commit 5ca7121
Show file tree
Hide file tree
Showing 14 changed files with 157 additions and 12 deletions.
1 change: 1 addition & 0 deletions changelog
Expand Up @@ -87,6 +87,7 @@ Version 1.13.0-dev:
* Added support for [elseif] tags inside [if]
* Schema validator messages now conform better to the new WML
parser/preprocessor diagnostics format introduced in version 1.11.10.
* Added define= functionality to scenarios, eras, and modifications.
* Miscellaneous and bug fixes:
* replace 'fight_on_without_leader'=yes/no with defeat_condition=no_leader/
no_units/always/never which allows the wml developer to decide when a side
Expand Down
4 changes: 4 additions & 0 deletions data/core/about.cfg
Expand Up @@ -1174,6 +1174,10 @@
email = "greywhind_AT_users.sourceforge.net"
wikiuser = "Greywhind"
[/entry]
[entry]
name = "Nathan Walker (RiftWalker)"
email = "nathan.b.walker@vanderbilt.edu"
[/entry]
[entry]
name = "Oleg Tsarev"
email = "zabivator@gmail.com"
Expand Down
7 changes: 7 additions & 0 deletions data/multiplayer/scenarios/2p_Dark_Forecast.cfg
Expand Up @@ -10,7 +10,9 @@ Note: You need to use the default map settings for the scenario to work right."
experience_modifier="100"
map_data="{multiplayer/maps/Dark_Forecast.map}"
victory_when_enemies_defeated=no
define=MULTIPLAYER_2P_DARK_FORECAST_LOAD

#ifdef MULTIPLAYER_2P_DARK_FORECAST_LOAD
#define RANDOMIZE NUMBER
{VARIABLE_OP random rand 1..{NUMBER}}
#enddef
Expand Down Expand Up @@ -1006,6 +1008,7 @@ Note: You need to use the default map settings for the scenario to work right."
{FIRST_WATCH}
{SECOND_WATCH}

#endif
[side]
side=1
team_name="revolt"
Expand All @@ -1015,6 +1018,7 @@ Note: You need to use the default map settings for the scenario to work right."
no_leader=yes
controller="ai"
village_gold=1
#ifdef MULTIPLAYER_2P_DARK_FORECAST_LOAD
[unit]
type=Ancient Lich
canrecruit=yes
Expand All @@ -1033,6 +1037,7 @@ Note: You need to use the default map settings for the scenario to work right."
[/object]
[/modifications]
[/unit]
#endif
[/side]

[side]
Expand Down Expand Up @@ -1088,6 +1093,7 @@ Note: You need to use the default map settings for the scenario to work right."
share_view="yes"
[/side]

#ifdef MULTIPLAYER_2P_DARK_FORECAST_LOAD
[event]
name=prestart
{SET_TIMID_AI_AND_BOLD_AI 2 1}
Expand Down Expand Up @@ -1406,4 +1412,5 @@ The weather will also change randomly, affecting the layout of the map.
#undef WEATHER_ALERT
#undef ADJUST_WEATHER
#undef INIT_WEATHER
#endif
[/multiplayer]
7 changes: 7 additions & 0 deletions data/multiplayer/scenarios/2p_Hornshark_Island.cfg
@@ -1,5 +1,6 @@
#textdomain wesnoth-multiplayer

#ifdef MULTIPLAYER_HORNSHARK_ISLAND_LOAD
#define MODIFY_BOWMAN X Y
[object]
silent=yes
Expand All @@ -18,6 +19,7 @@
[/effect]
[/object]
#enddef
#endif

[multiplayer]
id=multiplayer_Hornshark_Island
Expand All @@ -26,10 +28,13 @@
description= _ "Players must forge strange alliances with the local inhabitants, in order to survive on this most unusual of islands. Designed by Doc Paterson."
map_data="{multiplayer/maps/2p_Hornshark_Island.map}"
random_start_time="no"
define=MULTIPLAYER_HORNSHARK_ISLAND_LOAD

#ifdef MULTIPLAYER_HORNSHARK_ISLAND_LOAD
{DEFAULT_SCHEDULE_MORNING}

{DEFAULT_MUSIC_PLAYLIST}
#endif

[side]
[ai]
Expand All @@ -56,6 +61,7 @@
fog=yes
[/side]

#ifdef MULTIPLAYER_HORNSHARK_ISLAND_LOAD
[event]
name=prestart

Expand Down Expand Up @@ -1011,4 +1017,5 @@
{MODIFY_BOWMAN 1 1}
{MODIFY_BOWMAN 28 24}
[/event]
#endif
[/multiplayer]
13 changes: 13 additions & 0 deletions data/multiplayer/scenarios/4p_A_New_Land.cfg
Expand Up @@ -6,7 +6,9 @@
description= _ "This 4p survival scenario allows you to construct buildings and terraform the land. Use map settings. The recommended starting gold is 100."
experience_modifier=70%
turns=unlimited
define=MULTIPLAYER_A_NEW_LAND_LOAD

#ifdef MULTIPLAYER_A_NEW_LAND_LOAD
{DEFAULT_SCHEDULE}
{DEFAULT_MUSIC_PLAYLIST}
# ------------------------------------------------------
Expand Down Expand Up @@ -36,6 +38,7 @@
[/objective]
[/objectives]
[/event]
#endif

# ------------------------------------------------------
# Side Definitions
Expand Down Expand Up @@ -120,6 +123,7 @@
income_lock=yes
type=Death Knight
allow_player=no
#ifdef MULTIPLAYER_A_NEW_LAND_LOAD
[modifications]
{MOVEMENT_RESTRICTION flat shallow_water}
[/modifications]
Expand All @@ -130,6 +134,7 @@
[village]
x,y=10,25
[/village]
#endif
[/side]

[side]
Expand All @@ -147,6 +152,7 @@
income_lock=yes
type=Orcish Sovereign
allow_player=no
#ifdef MULTIPLAYER_A_NEW_LAND_LOAD
[modifications]
{MOVEMENT_RESTRICTION flat shallow_water}
[/modifications]
Expand All @@ -157,6 +163,7 @@
[village]
x,y=50,25
[/village]
#endif
[/side]

[side]
Expand All @@ -174,6 +181,7 @@
income_lock=yes
type=Orcish Sovereign
allow_player=no
#ifdef MULTIPLAYER_A_NEW_LAND_LOAD
[modifications]
{MOVEMENT_RESTRICTION flat shallow_water}
[/modifications]
Expand All @@ -184,6 +192,7 @@
[village]
x,y=10,30
[/village]
#endif
[/side]

[side]
Expand All @@ -201,6 +210,7 @@
income_lock=yes
type=Death Knight
allow_player=no
#ifdef MULTIPLAYER_A_NEW_LAND_LOAD
[modifications]
{MOVEMENT_RESTRICTION flat shallow_water}
[/modifications]
Expand All @@ -211,6 +221,7 @@
[village]
x,y=50,30
[/village]
#endif
[/side]

# This side is for trapped units. It is allied to the AI so they don't attack it.
Expand All @@ -233,6 +244,7 @@
[/ai]
[/side]

#ifdef MULTIPLAYER_A_NEW_LAND_LOAD
# ------------------------------------------------------
# ANL Building Logic
# ------------------------------------------------------
Expand Down Expand Up @@ -840,4 +852,5 @@
type=Necrophage,Bone Shooter,Revenant
[/allow_recruit]
[/event]
#endif
[/multiplayer]
9 changes: 9 additions & 0 deletions data/multiplayer/scenarios/6p_Team_Survival.cfg
Expand Up @@ -49,6 +49,7 @@ _s , _s , _s , _s , _s , _s
_s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s
_s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s , _s
#enddef
#ifdef 6P_TEAM_SURVIVAL_LOAD
#define TS_WALL_MASK_NORTH
usage=mask

Expand Down Expand Up @@ -311,6 +312,7 @@ usage=mask
{TS_SPAWN2 "Goblin Rouser"}{TS_SPAWN2 "Goblin Spearman"}{TS_SPAWN2 "Goblin Spearman"}{TS_SPAWN2 "Goblin Spearman"}{TS_SPAWN2 "Goblin Spearman"}{TS_SPAWN2 "Goblin Spearman"}{TS_SPAWN2 "Goblin Spearman"}
[/event]
#enddef
#endif

[multiplayer]
id=multiplayer_6p_Team_Survival
Expand All @@ -321,9 +323,12 @@ usage=mask
turns=32
victory_when_enemies_defeated=yes
random_start_time="no"
define=6P_TEAM_SURVIVAL_LOAD

#ifdef 6P_TEAM_SURVIVAL_LOAD
{DEFAULT_MUSIC_PLAYLIST}
{DEFAULT_SCHEDULE}
#endif

[side]
user_team_name=_ "Attacker"
Expand Down Expand Up @@ -420,6 +425,7 @@ usage=mask
[/ai]
[/side]

#ifdef 6P_TEAM_SURVIVAL_LOAD
[event]
name=prestart

Expand Down Expand Up @@ -600,9 +606,11 @@ usage=mask
image=portraits/undead/transparent/spectre.png
[/message]
[/event]
#endif
[/multiplayer]

#undef TS_MAP_DATA
#ifdef 6P_TEAM_SURVIVAL_LOAD
#undef TS_WALL_MASK_NORTH
#undef TS_WALL_MASK_NORTH_EAST
#undef TS_WALL_MASK_NORTH_WEST
Expand All @@ -622,3 +630,4 @@ usage=mask
#undef TS_LAKE_SPAWN
#undef TS_HOME_SPAWN
#undef TS_SPAWNS
#endif
12 changes: 12 additions & 0 deletions src/game_classification.cpp
Expand Up @@ -34,6 +34,9 @@ game_classification::game_classification():
campaign_type(),
campaign_define(),
campaign_xtra_defines(),
scenario_define(),
era_define(),
mod_defines(),
campaign(),
abbrev(),
completion(),
Expand All @@ -51,6 +54,9 @@ game_classification::game_classification(const config& cfg):
campaign_type(lexical_cast_default<game_classification::CAMPAIGN_TYPE> (cfg["campaign_type"].str(), game_classification::SCENARIO)),
campaign_define(cfg["campaign_define"]),
campaign_xtra_defines(utils::split(cfg["campaign_extra_defines"])),
scenario_define(cfg["scenario_define"]),
era_define(cfg["era_define"]),
mod_defines(utils::split(cfg["mod_defines"])),
campaign(cfg["campaign"]),
abbrev(cfg["abbrev"]),
completion(cfg["completion"]),
Expand All @@ -68,6 +74,9 @@ game_classification::game_classification(const game_classification& gc):
campaign_type(gc.campaign_type),
campaign_define(gc.campaign_define),
campaign_xtra_defines(gc.campaign_xtra_defines),
scenario_define(gc.scenario_define),
era_define(gc.era_define),
mod_defines(gc.mod_defines),
campaign(gc.campaign),
abbrev(gc.abbrev),
completion(gc.completion),
Expand All @@ -88,6 +97,9 @@ config game_classification::to_config() const
cfg["campaign_type"] = lexical_cast<std::string> (campaign_type);
cfg["campaign_define"] = campaign_define;
cfg["campaign_extra_defines"] = utils::join(campaign_xtra_defines);
cfg["scenario_define"] = scenario_define;
cfg["era_define"] = era_define;
cfg["mod_defines"] = utils::join(mod_defines);
cfg["campaign"] = campaign;
cfg["abbrev"] = abbrev;
cfg["completion"] = completion;
Expand Down
3 changes: 3 additions & 0 deletions src/game_classification.hpp
Expand Up @@ -43,6 +43,9 @@ class game_classification : public savegame::savegame_config
CAMPAIGN_TYPE campaign_type;
std::string campaign_define; /**< If there is a define the campaign uses to customize data */
std::vector<std::string> campaign_xtra_defines; /**< more customization of data */
std::string scenario_define; /**< If there is a define the scenario uses to customize data */
std::string era_define; /**< If there is a define the era uses to customize data */
std::vector<std::string> mod_defines; /**< If there are defines the modifications use to customize data */

std::string campaign; /**< the campaign being played */

Expand Down
11 changes: 11 additions & 0 deletions src/game_config_manager.cpp
Expand Up @@ -374,6 +374,10 @@ void game_config_manager::load_game_config_for_game(
!classification.difficulty.empty());
game_config::scoped_preproc_define campaign(classification.campaign_define,
!classification.campaign_define.empty());
game_config::scoped_preproc_define scenario(classification.scenario_define,
!classification.scenario_define.empty());
game_config::scoped_preproc_define era(classification.era_define,
!classification.era_define.empty());
game_config::scoped_preproc_define multiplayer("MULTIPLAYER",
classification.campaign_type == game_classification::MULTIPLAYER);

Expand All @@ -385,6 +389,13 @@ void game_config_manager::load_game_config_for_game(
(new game_config::scoped_preproc_define(extra_define));
extra_defines.push_back(new_define);
}
std::deque<define> modification_defines;
BOOST_FOREACH(const std::string& mod_define,
classification.mod_defines) {
define new_define
(new game_config::scoped_preproc_define(mod_define, !mod_define.empty()));
modification_defines.push_back(new_define);
}

try{
load_game_config(NO_FORCE_RELOAD, &classification);
Expand Down
41 changes: 29 additions & 12 deletions src/multiplayer.cpp
Expand Up @@ -41,6 +41,8 @@
#include "settings.hpp"
#include "sound.hpp"
#include "unit_id.hpp"
#include "resources.hpp"
#include "game_config_manager.hpp"

#include <boost/bind.hpp>
#include <boost/foreach.hpp>
Expand Down Expand Up @@ -785,13 +787,34 @@ void start_local_game_commandline(game_display& disp, const config& game_config,
// None of the other parameters need to be set, as their creation values above are good enough for CL mode.
// In particular, we do not want to use the preferences values.

// Override era, faction (side) and scenario if set on the commandline
if (cmdline_opts.multiplayer_era) parameters.mp_era = *cmdline_opts.multiplayer_era;
const config &era_cfg = game_config.find_child("era", "id", parameters.mp_era);
if (!era_cfg) {
std::cerr << "Could not find era '" << parameters.mp_era << "'\n";
return;
// scope for config objects that will become invalid after reload
{
// Override era, faction (side) and scenario if set on the commandline
if (cmdline_opts.multiplayer_era)
parameters.mp_era = *cmdline_opts.multiplayer_era;
const config& era_cfg_preload = game_config.find_child("era", "id", parameters.mp_era);
if (!era_cfg_preload) {
std::cerr << "Could not find era '" << parameters.mp_era << "'\n";
return;
}

if (cmdline_opts.multiplayer_scenario)
parameters.name = *cmdline_opts.multiplayer_scenario;
const config &level_preload = game_config.find_child("multiplayer", "id", parameters.name);
if (!level_preload) {
std::cerr << "Could not find scenario '" << parameters.name << "'\n";
return;
}

game_classification classification;
classification.campaign_type = game_classification::MULTIPLAYER;
classification.scenario_define = level_preload["define"].str();
classification.era_define = era_cfg_preload["define"].str();
resources::config_manager->load_game_config_for_game(classification);
}

const config& era_cfg = resources::config_manager->game_config().find_child("era", "id", parameters.mp_era);
const config& level = resources::config_manager->game_config().find_child("multiplayer", "id", parameters.name);

if (cmdline_opts.multiplayer_side) {
for(std::vector<boost::tuple<unsigned int, std::string> >::const_iterator
Expand All @@ -805,12 +828,6 @@ void start_local_game_commandline(game_display& disp, const config& game_config,
}
}

if (cmdline_opts.multiplayer_scenario) parameters.name = *cmdline_opts.multiplayer_scenario;
const config &level = game_config.find_child("multiplayer", "id", parameters.name);
if (!level) {
std::cerr << "Could not find scenario '" << parameters.name << "'\n";
return;
}

// Should the map be randomly generated?
if (level["map_generation"].empty()) {
Expand Down

0 comments on commit 5ca7121

Please sign in to comment.