diff options
Diffstat (limited to '_main.cfg')
-rw-r--r-- | _main.cfg | 168 |
1 files changed, 168 insertions, 0 deletions
diff --git a/_main.cfg b/_main.cfg new file mode 100644 index 0000000..28b789d --- /dev/null +++ b/_main.cfg @@ -0,0 +1,168 @@ +[modification] + id=Select_Trait + name=_"Select Trait" + description=_"Optionally select a new recruit's trait(s), at an increased cost" + require_modification=yes + + [lua] + code=<< + Select_Trait = {} + function Select_Trait.select_for_unit(unit, cost_per) + local side = wesnoth.sides[unit.side] + local type = wesnoth.unit_types[unit.type] + local race = wesnoth.races[type.race] + + local available_traits = type.traits + if available_traits == nil then + if type.ignore_race_traits then return end + available_traits = race.traits + end + if available_traits == nil then return end + + local num_traits = type.num_traits + if num_traits == nil then + num_traits = race.num_traits + end + if num_traits == nil then return end + + local gender = unit.gender + + local sorted_traits = {} + for id, _ in pairs(available_traits) do + table.insert(sorted_traits, id) + end + table.sort(sorted_traits) + + local options = {} + local ids = {} + for _,id in pairs(sorted_traits) do + table.insert(options, {label=available_traits[id][gender.."_name"]}) + table.insert(ids, available_traits[id].id) + end + table.insert(options, {label="Random (no charge, ends loop)"}) + + if num_traits >= #ids then return end + + local choice + + local traits = {} + while num_traits > 0 and side.gold >= cost_per do + choice = wesnoth.sync.evaluate_single(function() + return {value = gui.show_narration( + { + title = "Trait Selection", + message = "Select a trait ("..tostring(cost_per).." gold)", + }, + options + )} + end).value + + if choice == #options then break end + + side.gold = side.gold - cost_per + + table.insert(traits, ids[choice]) + table.remove(options, choice) + table.remove(ids, choice) + num_traits = num_traits - 1 + end + + --while num_traits > 0 do + -- choice = mathx.random(#ids) + -- table.insert(traits, ids[choice]) + -- table.remove(ids, choice) + -- num_traits = num_traits - 1 + --end + + local original_moves = unit.moves + local original_attacks_left = unit.attacks_left + local x = unit.x + local y = unit.y + local original_canrecruit = unit.canrecruit + + while true do -- lol + unit:extract() + wesnoth.units.to_map({ + side=unit.side, + variation=unit.variation, + type=unit.type, + gender=unit.gender, + race=unit.race, + random_traits=true, + }, x, y) + unit = wesnoth.units.get(x, y) + local correct = true + for key, trait in pairs(traits) do + if unit.traits[key] ~= trait then + correct = false + break + end + end + if correct then break end + end + + unit.moves = original_moves + unit.attacks_left = original_attacks_left + unit.canrecruit = original_canrecruit + end + >> + [/lua] + + [options] + [checkbox] + id=Select_Trait_give_to_leaders + default=true + name=_"Select for leader" + description=_"Allow the player to select the initial traits for their leader unit, if it didn't come with any" + [/checkbox] + + [slider] + id=Select_Trait_cost_per_trait + default=1 + min=0 + max=10 + name=_"Cost" + description=_"How much gold to charge for each trait the player selects, during recruiting" + [/slider] + [/options] + + [event] + name=recruit + first_time_only=no + [lua] + code=<< + local args=... + event_context = wesnoth.current.event_context + + local unit = wesnoth.units.get(event_context.x1, event_context.y1) + if not unit then return end + + Select_Trait.select_for_unit(unit, args.cost) + >> + [args] + cost=$Select_Trait_cost_per_trait + [/args] + [/lua] + [/event] + + [event] + name=side $side_number turn 1 + first_time_only=no + [lua] + code=<< + args=... + if not args.actually_run then return end + + for _,unit in ipairs(wesnoth.units.find_on_map({side=args.side_number, canrecruit=true})) do + if #unit.traits == 0 then + Select_Trait.select_for_unit(unit, 0) + end + end + >> + [args] + side_number=$side_number + actually_run=$Select_Trait_give_to_leaders + [/args] + [/lua] + [/event] +[/modification] |