summaryrefslogtreecommitdiff
path: root/_main.cfg
diff options
context:
space:
mode:
Diffstat (limited to '_main.cfg')
-rw-r--r--_main.cfg281
1 files changed, 281 insertions, 0 deletions
diff --git a/_main.cfg b/_main.cfg
new file mode 100644
index 0000000..c12f82a
--- /dev/null
+++ b/_main.cfg
@@ -0,0 +1,281 @@
+[modification]
+ id=Unit_Displacement
+ name=_"Unit Displacement"
+ description=_"Allows you to displace your own units, so congested areas are more managable, and optionally also allies' units (with some restrictions)"
+ require_modification=yes
+
+ [lua]
+ code=<<
+ Unit_Displacement = {map={}, sides={}}
+ function Unit_Displacement.lose_units(count, side)
+ if count == 1 then
+ wesnoth.interface.add_chat_message("RIP "..tostring(count).." unit from side "..tostring(side)..", who was improperly displaced.")
+ else
+ wesnoth.interface.add_chat_message("RIP "..tostring(count).." units from side "..tostring(side)..", who were improperly displaced.")
+ end
+ end
+ >>
+ [/lua]
+
+ [options]
+ [checkbox]
+ id=Unit_Displacement_allow_displacing_allies
+ default=true
+ name=_"Allow displacing allies"
+ description=_"Allows the player to displace allied units, if the ally moves after them, and no enemies are between"
+ [/checkbox]
+ [/options]
+
+ [event]
+ name=prestart
+
+ [set_menu_item]
+ id=Unit_Displacement_select
+ description=_"Displace this unit"
+
+ [show_if]
+ [lua]
+ code=<<
+ if not wesnoth.current.user_can_invoke_commands then return false end
+
+ local args=...
+
+ local tmp = Unit_Displacement.map[args.x]
+ if tmp and tmp[args.y] then return false end
+
+ local unit = wesnoth.units.get(args.x, args.y)
+ if not unit then return false end
+
+ local side_number = wesnoth.current.side
+ local side = wesnoth.sides[side_number]
+
+ if unit.canrecruit then return false end
+ if unit.side == side_number and unit.moves == 0 then return false end
+
+ if unit.side == side_number then return true end
+
+ if not args.allow_allied then return false end
+ if side_number >= unit.side then return false end
+
+ for i=side_number,unit.side do
+ if side:is_enemy(wesnoth.sides[i]) then return false end
+ end
+
+ return true
+ >>
+ [args]
+ allow_allied=$Unit_Displacement_allow_displacing_allies
+ x=$x1
+ y=$y1
+ [/args]
+ [/lua]
+ [/show_if]
+
+ [command]
+ [lua]
+ code=<<
+ args=...
+ local x = tonumber(args.x)
+ local y = tonumber(args.y)
+
+ local unit = wesnoth.units.get(x, y)
+ unit:extract()
+
+ Unit_Displacement.map[x] = Unit_Displacement.map[x] or {}
+ Unit_Displacement.map[x][y] = unit
+
+ Unit_Displacement.sides[unit.side] = Unit_Displacement.sides[unit.side] or {}
+ Unit_Displacement.sides[unit.side][unit] = true
+ >>
+ [args]
+ x=$x1
+ y=$y1
+ [/args]
+ [/lua]
+ [/command]
+ [/set_menu_item]
+ [/event]
+
+ [event]
+ name=moveto
+ first_time_only=no
+
+ [filter_condition]
+ [lua]
+ code=<<
+ local args=...
+ local x = tonumber(args.x)
+ local y = tonumber(args.y)
+ if not Unit_Displacement.map[x] or not Unit_Displacement.map[x][y] then return false end
+
+ local old_unit = Unit_Displacement.map[x][y]
+ local new_unit = wesnoth.units.get(x, y)
+ if old_unit.side ~= new_unit.side then return false end
+ if new_unit.canrecruit then return false end
+
+ return true
+ >>
+ [args]
+ x=$x1
+ y=$y1
+ [/args]
+ [/lua]
+
+ [or]
+ [lua]
+ code=<<
+ local args=...
+ local x = tonumber(args.x)
+ local y = tonumber(args.y)
+ if not Unit_Displacement.map[x] or not Unit_Displacement.map[x][y] then return false end
+
+ return true
+ >>
+ [args]
+ x=$x2
+ y=$y2
+ [/args]
+ [/lua]
+ [/or]
+ [/filter_condition]
+
+ [lua]
+ code=<<
+ -- same side, moving onto the tile
+
+ local args=...
+ local x = tonumber(args.x)
+ local y = tonumber(args.y)
+ if not Unit_Displacement.map[x] or not Unit_Displacement.map[x][y] then return end
+ local old_unit = Unit_Displacement.map[x][y]
+ local new_unit = wesnoth.units.get(x, y)
+ if old_unit.side ~= new_unit.side then return end
+ if new_unit.canrecruit then return end
+
+ Unit_Displacement.sides[old_unit.side][old_unit] = nil
+
+ new_unit:extract()
+ old_unit:to_map()
+
+ Unit_Displacement.map[x][y] = new_unit
+ Unit_Displacement.sides[new_unit.side][new_unit] = true
+ >>
+ [args]
+ x=$x1
+ y=$y1
+ [/args]
+ [/lua]
+
+ [lua]
+ code=<<
+ -- any side, moving out of the displaced tile
+
+ local args=...
+ local x = tonumber(args.x)
+ local y = tonumber(args.y)
+ if not Unit_Displacement.map[x] or not Unit_Displacement.map[x][y] then return end
+ local unit = Unit_Displacement.map[x][y]
+ Unit_Displacement.sides[unit.side][unit] = nil
+ Unit_Displacement.map[x][y] = nil
+
+ unit:to_map()
+ >>
+ [args]
+ x=$x2
+ y=$y2
+ [/args]
+ [/lua]
+ [/event]
+
+ [event]
+ name=side turn end
+ first_time_only=no
+
+ [lua]
+ code=<<
+ -- attempt to place units on turn end, if unsuccessful... well, nowhere to put them...
+
+ local args=...
+
+ if not Unit_Displacement.sides[args.side] then return end
+
+ local lost = 0
+ for unit, _ in pairs(Unit_Displacement.sides[args.side]) do
+ if wesnoth.units.get(unit.x, unit.y) then
+ lost = lost + 1
+ else
+ unit:to_map()
+ end
+
+ Unit_Displacement.map[unit.x][unit.y] = nil
+ end
+ if lost > 0 then
+ Unit_Displacement.lose_units(lost, args.side)
+ end
+
+ Unit_Displacement.sides[args.side] = {}
+
+ for i=1,args.side do
+ if Unit_Displacement.sides[i] then
+ local lost = 0
+ for unit, _ in pairs(Unit_Displacement.sides[i]) do
+ lost = lost + 1
+ Unit_Displacement.map[unit.x][unit.y] = nil
+ end
+ Unit_Displacement.sides[i] = {}
+ if lost > 0 then
+ Unit_Displacement.lose_units(lost, i)
+ end
+ end
+ end
+ >>
+ [args]
+ side=$side_number
+ [/args]
+ [/lua]
+ [/event]
+
+ [event]
+ name=side turn
+ first_time_only=no
+
+ [lua]
+ code=<<
+ -- swap out units on turn start
+
+ local args=...
+
+ if not Unit_Displacement.sides[args.side] then return end
+
+ local lost = 0
+ for unit, _ in pairs(Unit_Displacement.sides[args.side]) do
+ local new_unit = wesnoth.units.get(unit.x, unit.y)
+ if new_unit then
+ if new_unit.canrecruit then
+ lost = lost + 1
+ Unit_Displacement.map[unit.x][unit.y] = nil
+ else
+ new_unit:extract()
+
+ Unit_Displacement.sides[new_unit.side] = Unit_Displacement.sides[new_unit.side] or {}
+ Unit_Displacement.sides[new_unit.side][new_unit] = true
+ Unit_Displacement.map[new_unit.x][new_unit.y] = new_unit
+
+ unit:to_map()
+ end
+ else
+ unit:to_map()
+ end
+ end
+ if lost > 0 then
+ Unit_Displacement.lose_units(lost, args.side)
+ end
+
+ Unit_Displacement.sides[args.side] = {}
+ >>
+ [args]
+ side=$side_number
+ [/args]
+ [/lua]
+ [/event]
+[/modification]