-
-
Notifications
You must be signed in to change notification settings - Fork 988
/
enemy_themed.lua
98 lines (95 loc) · 2.19 KB
/
enemy_themed.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
local _ = wesnoth.textdomain 'wesnoth-wc'
local on_event = wesnoth.require("on_event")
local strings = {
enemy_pet = _ "$name|'s pet"
}
-- in the later scenarios there is a small chance that a scenario will be themed for an enemy
-- which means in paticular changing the castle of the enemy accorign to the unit type of that
-- enemy, and giving him an extra unit.
local function wct_map_enemy_themed(race, pet, castle, village, chance)
if wesnoth.random(100) > chance then
return
end
local boss = wesnoth.units.find_on_map {
side="4,5,6,7,8,9",
canrecruit=true,
race=race,
-- human means only outlaw
wml.tag["not"] {
race="human",
wml.tag["not"] {
wml.tag.filter_wml {
alignment="chaotic",
}
}
}
}
boss = boss[1]
if boss == nil then
return
end
--give themed castle
wesnoth.set_terrain(boss.loc, "K" .. castle, "base")
wesnoth.wml_actions.terrain {
terrain="C" .. castle,
wml.tag["and"] {
terrain = "C*,*^C*",
wml.tag["and"] {
wml.tag.filter {
x=boss.x,
y=boss.y,
},
radius=999,
wml.tag.filter_radius {
terrain="K*^*,C*^*,*^K*,*^C*"
},
},
},
}
local elvish_castle = wesnoth.get_locations {
terrain="Cv",
wml.tag.filter_adjacent_location {
terrain="Kv^*"
}
}
-- extra tweak with trees to elvish castle
for i, tile in ipairs(elvish_castle) do
if wesnoth.random(10) <= 4 then
wesnoth.set_terrain(tile, "Cv^Fet")
end
end
-- adjacent themed villages
wesnoth.wml_actions.terrain {
terrain=village,
wml.tag["and"] {
terrain="*^V*",
wml.tag.filter_adjacent_location {
terrain="C" .. castle .. ",K" .. castle .. "^*",
},
},
}
-- give pet
wesnoth.wml_actions.unit {
x = boss.x,
y = boss.y,
type=pet,
side = boss.side,
name= stringx.vformat(enemy_pet, { name = boss.name }),
role = "hero",
overlays = "misc/hero-icon.png",
wml.tag.modifications {
wc2_heroes.trait_heroic,
wc2_heroes.trait_expert,
wml.tag.object {
id = "wc2_hero_overlay",
wml.tag.effect {
apply_to="overlay",
add = "misc/hero-icon.png",
}
}
}
}
end
function wesnoth.wml_actions.wc2_enemy_themed(cfg)
wct_map_enemy_themed(cfg.race, cfg.pet, cfg.castle, cfg.village, cfg.chance)
end