summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--COPYING.txt23
-rw-r--r--_main.cfg281
2 files changed, 304 insertions, 0 deletions
diff --git a/COPYING.txt b/COPYING.txt
new file mode 100644
index 0000000..1465453
--- /dev/null
+++ b/COPYING.txt
@@ -0,0 +1,23 @@
+This is free and unencumbered software released into the public
+domain.
+
+Anyone is free to copy, modify, publish, use, compile, sell, or
+distribute this software, either in source code form or as a compiled
+binary, for any purpose, commercial or non-commercial, and by any
+means.
+
+In jurisdictions that recognize copyright laws, the author or authors
+of this software dedicate any and all copyright interest in the
+software to the public domain. We make this dedication for the benefit
+of the public at large and to the detriment of our heirs and
+successors. We intend this dedication to be an overt act of
+relinquishment in perpetuity of all present and future rights to this
+software under copyright law.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
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]