WC: Change it to a campaign so it can use the built-in difficulty selection
Fixes #5113
This commit is contained in:
parent
284f7149e3
commit
7488fbfef6
6 changed files with 118 additions and 144 deletions
|
@ -1,120 +0,0 @@
|
|||
-- The difficulty dialog. unlike other files this does not 'export' functions,
|
||||
-- just run this file to show the diffculty dialog.
|
||||
|
||||
local _ = wesnoth.textdomain 'wesnoth-wc'
|
||||
local strings = {
|
||||
chose_difficulty = "<span size='large'>" .. _"Choose difficulty level:" .. "</span>",
|
||||
}
|
||||
|
||||
local _ = wesnoth.textdomain 'wesnoth-units'
|
||||
local strings_mainline = {
|
||||
Sergeant = _"Sergeant",
|
||||
Peasant = _"Peasant",
|
||||
Lieutenant = _"Lieutenant",
|
||||
General = _"General",
|
||||
Grand_Marshal = _"Grand Marshal"
|
||||
}
|
||||
|
||||
local function icon_human_difficult(unit_image, color)
|
||||
return "misc/blank-hex.png~SCALE(140,100)" ..
|
||||
"~BLIT(units/" .. unit_image .. ".png~RC(magenta>" .. color .. "),34,7)"
|
||||
end
|
||||
|
||||
local function str_dif_lvl(name)
|
||||
return "<span size='large'>" .. name .. "</span>"
|
||||
end
|
||||
|
||||
local icon_nightmare_difficulty = "units/monsters/fire-dragon.png~CROP(0,0,160,160)~RC(magenta>red)"
|
||||
|
||||
|
||||
local t_option = wml.tag.option
|
||||
|
||||
local function wct_difficulty(name, power, enemy_t, heroes, gold, train, exp)
|
||||
local nplayers = wml.variables.wc2_player_count
|
||||
if nplayers == 1 then
|
||||
heroes = heroes + 1
|
||||
end
|
||||
-- adjust bonus gold for number of players
|
||||
gold = gold * 2 ^ (3 - nplayers)
|
||||
return wml.tag.command {
|
||||
wml.tag.set_variables {
|
||||
name = "wc2_difficulty",
|
||||
wml.tag.literal {
|
||||
name = name,
|
||||
enemy_power = power,
|
||||
enemy_trained = enemy_t,
|
||||
heroes = heroes,
|
||||
extra_gold = gold,
|
||||
extra_trainig = train,
|
||||
experience_penalty = exp,
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
function wct_scenario_chose_difficulty()
|
||||
-- fixme: should the first part argument of wct_difficulty be translatable
|
||||
wesnoth.wml_actions.message {
|
||||
speaker = "narrator",
|
||||
caption = strings.chose_difficulty,
|
||||
t_option {
|
||||
image = icon_human_difficult("human-peasants/peasant", "purple"),
|
||||
label = str_dif_lvl(strings_mainline.Peasant),
|
||||
description="(" .. _"Easy" .. ")",
|
||||
wct_difficulty("Peasant", 6, 2, 2, 10, true, 0),
|
||||
},
|
||||
t_option {
|
||||
image=icon_human_difficult("human-loyalists/sergeant", "black"),
|
||||
label=str_dif_lvl(strings_mainline.Sergeant),
|
||||
wct_difficulty("Sergeant", 7, 3, 2, 7, true, 5),
|
||||
},
|
||||
t_option {
|
||||
image=icon_human_difficult("human-loyalists/lieutenant", "brown"),
|
||||
label=str_dif_lvl(strings_mainline.Lieutenant),
|
||||
wct_difficulty("Lieutenant", 8, 4, 2, 5, true, 10),
|
||||
},
|
||||
t_option {
|
||||
image=icon_human_difficult("human-loyalists/general", "orange"),
|
||||
label=str_dif_lvl(strings_mainline.General),
|
||||
wct_difficulty("General", 8, 5, 2, 2, false, 13),
|
||||
},
|
||||
t_option {
|
||||
image=icon_human_difficult("human-loyalists/marshal", "white"),
|
||||
label=str_dif_lvl(strings_mainline.Grand_Marshal),
|
||||
wct_difficulty("Grand_marshal", 9, 6, 2, 1, false, 17),
|
||||
},
|
||||
t_option {
|
||||
image=icon_nightmare_difficulty,
|
||||
label=str_dif_lvl("Nightmare"),
|
||||
description="(" .. _"Expert" .. ")",
|
||||
wct_difficulty("Nightmare", 9, 7, 1, 0, false, 20),
|
||||
},
|
||||
}
|
||||
end
|
||||
|
||||
function wct_scenario_start_bonus()
|
||||
for side_num = 1, wml.variables.wc2_player_count do
|
||||
wesnoth.wml_actions.wc2_start_units {
|
||||
side = side_num
|
||||
}
|
||||
end
|
||||
|
||||
if wml.variables.wc2_difficulty.extra_trainig then
|
||||
for side_num = 1, wml.variables.wc2_player_count do
|
||||
wesnoth.wml_actions.wc2_give_random_training {
|
||||
among="2,3,4,5,6",
|
||||
side = side_num,
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function wesnoth.wml_actions.wc2_choose_difficulty(cfg)
|
||||
if wml.variables["wc2_difficulty"] then
|
||||
return
|
||||
end
|
||||
wct_scenario_chose_difficulty()
|
||||
wct_scenario_start_bonus()
|
||||
wesnoth.fire_event("wc2_start")
|
||||
end
|
|
@ -62,9 +62,24 @@ on_event("prestart", function(cx)
|
|||
wesnoth.fire_event("wc2_start")
|
||||
end)
|
||||
|
||||
-- we need to do this also after difficulöty selection.
|
||||
-- we need to do this also after difficulty selection.
|
||||
-- NOTE: this is a bit fragile, in particualr it breaks if difficulty_selection happens before the prestart event above.
|
||||
on_event("wc2_start", function(cx)
|
||||
for side_num = 1, wml.variables.wc2_player_count do
|
||||
wesnoth.wml_actions.wc2_start_units {
|
||||
side = side_num
|
||||
}
|
||||
end
|
||||
|
||||
if wml.variables.wc2_difficulty.extra_training then
|
||||
for side_num = 1, wml.variables.wc2_player_count do
|
||||
wesnoth.wml_actions.wc2_give_random_training {
|
||||
among="2,3,4,5,6",
|
||||
side = side_num,
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
local gold = (wml.variables.wc2_carryover or 0) + (wml.variables["wc2_difficulty.extra_gold"] or 0)
|
||||
for i = 1, wml.variables.wc2_player_count do
|
||||
wesnoth.sides[i].gold = wesnoth.sides[i].gold + gold
|
||||
|
|
|
@ -15,8 +15,6 @@ wesnoth.dofile("./campaign/autorecall.lua")
|
|||
wesnoth.dofile("./campaign/objectives.lua")
|
||||
wesnoth.dofile("./campaign/enemy_themed.lua")
|
||||
|
||||
wc2_difficulty = wesnoth.require("./campaign/difficulty.lua")
|
||||
|
||||
on_event("prestart", function(cx)
|
||||
wesnoth.wml_actions.wc2_fix_colors {
|
||||
wml.tag.player_sides {
|
||||
|
|
|
@ -78,20 +78,12 @@ function wc_ii_generate_scenario(nplayers, gen_args)
|
|||
wc2_host_version = "0.8.2"
|
||||
},
|
||||
side = {},
|
||||
id = "WC_II_" .. nplayers .. "p",
|
||||
next_scenario = "WC_II_" .. nplayers .. "p",
|
||||
id = gen_args.id,
|
||||
next_scenario = gen_args.id,
|
||||
description = "WC_II_" .. nplayers .. "p_desc",
|
||||
modify_placing = false,
|
||||
-- does this work
|
||||
turns = scenario_data.turns,
|
||||
experience_modifier = 100,
|
||||
victory_when_enemies_defeated = true,
|
||||
carryover_percentage = 0,
|
||||
carryover_report = false,
|
||||
carryover_add = false,
|
||||
force_lock_settings = true,
|
||||
}
|
||||
table.insert(prestart_event, wml.tag.wc2_choose_difficulty {} )
|
||||
|
||||
-- add [side]s to the [scenario]
|
||||
local enemy_data = scenario_data.get_enemy_data(enemy_stength)
|
||||
|
|
|
@ -179,6 +179,9 @@ _ "melee" #enddef
|
|||
#define STR_NIGHTMARE
|
||||
_ "Nightmare" #enddef
|
||||
|
||||
#define STR_MEDIUM
|
||||
_ "Medium" #enddef
|
||||
|
||||
#define STR_PIERCE
|
||||
_ "pierce" #enddef
|
||||
|
||||
|
@ -210,3 +213,10 @@ _ "General" #enddef
|
|||
|
||||
#define STR_GRAND_MARSHAL
|
||||
_ "Grand Marshal" #enddef
|
||||
|
||||
#################################
|
||||
#textdomain wesnoth-tutorial
|
||||
#################################
|
||||
|
||||
#define STR_BEGINNER
|
||||
_ "Beginner" #enddef
|
||||
|
|
|
@ -22,22 +22,89 @@ _ "World Conquest 3p" #enddef
|
|||
_ "A randomly generated cooperative campaign for 3 players. It has 6 levels of difficulty.
|
||||
(Expert level, 5 scenarios.)" #enddef
|
||||
|
||||
#define WC2_HUMAN_DIFFICULTY IMAGE COLOR
|
||||
"units/{IMAGE}.png~RC(magenta>{COLOR})"#enddef
|
||||
|
||||
#define WC2_NIGHTMARE_DIFFICULTY
|
||||
"units/monsters/fire-dragon.png~CROP(0,0,160,160)~SCALE_INTO(72,72)~RC(magenta>red)"#enddef
|
||||
|
||||
#define WC2_CAMPAIGN_DIFFICULTY DIFFICULTY IMAGE LABEL DESCRIPTION POWER TRAINED HEROES GOLD TRAIN XP
|
||||
{CAMPAIGN_DIFFICULTY {DIFFICULTY} {IMAGE} {LABEL} {DESCRIPTION}}
|
||||
[event]
|
||||
name=preload
|
||||
# These events run for every difficulty, so this Lua block ensures only the active difficulty's
|
||||
# event actually fills the settings variable.
|
||||
[lua]
|
||||
code=<<
|
||||
if wesnoth.scenario.difficulty ~= (...).difficulty then
|
||||
wesnoth.wml_actions["return"]{}
|
||||
end
|
||||
>>
|
||||
[args]
|
||||
difficulty={DIFFICULTY}
|
||||
[/args]
|
||||
[/lua]
|
||||
[set_variables]
|
||||
name=wc2_difficulty
|
||||
[value]
|
||||
name={LABEL}
|
||||
enemy_power={POWER}
|
||||
enemy_trained={TRAINED}
|
||||
heroes={HEROES}
|
||||
# adjust bonus gold for number of players
|
||||
extra_gold=$(gold * 2 ^ (3 - nplayers) where nplayers = $wc2_player_count, gold = {GOLD})
|
||||
extra_training={TRAIN}
|
||||
experience_penalty={XP}
|
||||
[/value]
|
||||
[/set_variables]
|
||||
[/event]
|
||||
#enddef
|
||||
|
||||
#define WC2_CAMPAIGN_NEW PLAYERS
|
||||
## Everything that usually goes into [scenario] like [event], [load_ressource], map_data
|
||||
## etc is generated by lua. This is also why there is only one [multiplayer] tag: the next
|
||||
## scenario is again "WC_II_{PLAYERS}p" and the lua code detects that is was called a second
|
||||
## time and generated the second scenario. (same for third, fourth and fifth). All the lua
|
||||
## code inside ./lua/map does map/scenario generation.
|
||||
[multiplayer]
|
||||
[campaign]
|
||||
id = "WC_II_{PLAYERS}p"
|
||||
define = CAMPAIGN_WC_{PLAYERS}P
|
||||
name= {WC_II_CAMPAIGN_NAME_{PLAYERS}P}
|
||||
description = {WC_II_CAMPAIGN_DESC_{PLAYERS}P}
|
||||
allow_new_game=yes
|
||||
require_scenario=no
|
||||
first_scenario = "WC_II_{PLAYERS}p"
|
||||
min_players={PLAYERS}
|
||||
max_players={PLAYERS}
|
||||
type = mp
|
||||
abbrev = _ "WC"
|
||||
{WC2_CAMPAIGN_DIFFICULTY VERY_EASY {WC2_HUMAN_DIFFICULTY human-peasants/peasant purple} {STR_PEASANT} {STR_BEGINNER} 6 2 2 10 yes 0}
|
||||
{WC2_CAMPAIGN_DIFFICULTY EASY {WC2_HUMAN_DIFFICULTY human-loyalists/sergeant black} {STR_SERGEANT} {STR_EASY} 7 3 2 7 yes 5}
|
||||
{WC2_CAMPAIGN_DIFFICULTY NORMAL {WC2_HUMAN_DIFFICULTY human-loyalists/lieutenant brown} {STR_LIEUTENANT} {STR_MEDIUM} 8 4 2 5 yes 10} {DEFAULT_DIFFICULTY}
|
||||
{WC2_CAMPAIGN_DIFFICULTY HARD {WC2_HUMAN_DIFFICULTY human-loyalists/general orange} {STR_GENERAL} {STR_HARD} 8 5 2 2 no 13}
|
||||
# Challenging is a string that exists in mainline but only in campaigns so it probably counts as adding a string?
|
||||
#textdomain wesnoth-httt
|
||||
{WC2_CAMPAIGN_DIFFICULTY VERY_HARD {WC2_HUMAN_DIFFICULTY human-loyalists/marshal white} {STR_GRAND_MARSHAL} _"Challenging" 9 6 2 1 no 17}
|
||||
# Expert is a string that was supposed to be in wesnoth-wc but accidentally got added to wesnoth-units instead
|
||||
#textdomain wesnoth-units
|
||||
{WC2_CAMPAIGN_DIFFICULTY NIGHTMARE {WC2_NIGHTMARE_DIFFICULTY} {STR_NIGHTMARE} _"Expert" 9 7 1 0 no 20}
|
||||
[/campaign]
|
||||
#enddef
|
||||
|
||||
#define WC2_SCENARIO_NEW TAG ID NAME PLAYERS
|
||||
## Everything that usually goes into [scenario] like [event], [load_ressource], map_data
|
||||
## etc is generated by lua. This is also why there is only one [scenario] tag: the next
|
||||
## scenario is again "WC_II" and the lua code detects that is was called a second
|
||||
## time and generates the second scenario. (Same for third, fourth and fifth). All the lua
|
||||
## code inside ./lua/map does map/scenario generation.
|
||||
[{TAG}]
|
||||
id = {ID}
|
||||
name={NAME}
|
||||
allow_new_game=no
|
||||
scenario_generation=lua
|
||||
experience_modifier=100
|
||||
victory_when_enemies_defeated=yes
|
||||
carryover_percentage=0
|
||||
carryover_report=no
|
||||
carryover_add=no
|
||||
force_lock_settings=yes
|
||||
[generator]
|
||||
id="WC_II_{PLAYERS}p"
|
||||
config_name={WC_II_CAMPAIGN_NAME_{PLAYERS}P}
|
||||
id={ID}
|
||||
config_name={NAME}
|
||||
nplayers={PLAYERS}
|
||||
create_scenario = <<
|
||||
local a = ...
|
||||
local function doit()
|
||||
|
@ -76,9 +143,21 @@ _ "World Conquest 3p" #enddef
|
|||
{DEFAULT_MUSIC_PLAYLIST}
|
||||
[/scenario]
|
||||
[/generator]
|
||||
[/multiplayer]
|
||||
[/{TAG}]
|
||||
#enddef
|
||||
|
||||
{WC2_CAMPAIGN_NEW 1}
|
||||
{WC2_CAMPAIGN_NEW 2}
|
||||
{WC2_CAMPAIGN_NEW 3}
|
||||
|
||||
#ifdef CAMPAIGN_WC_1P
|
||||
{WC2_SCENARIO_NEW scenario "WC_II_1p" {WC_II_CAMPAIGN_NAME_1P} 1}
|
||||
#endif
|
||||
|
||||
#ifdef CAMPAIGN_WC_2P
|
||||
{WC2_SCENARIO_NEW scenario "WC_II_2p" {WC_II_CAMPAIGN_NAME_2P} 2}
|
||||
#endif
|
||||
|
||||
#ifdef CAMPAIGN_WC_3P
|
||||
{WC2_SCENARIO_NEW scenario "WC_II_3p" {WC_II_CAMPAIGN_NAME_3P} 3}
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue