Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Macrodecisions inspector. #135

Merged
merged 4 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 152 additions & 0 deletions sote/game/raws/decisions/character-decisions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,158 @@ local function load()
WORLD:emit_immediate_event('sell-goods', root, nil)
end
}


---@type DecisionCharacterProvince
Decision.CharacterProvince:new {
name = 'personal-raid',
ui_name = "Raid",
tooltip = function (root, primary_target)
if root.busy then
return "You are too busy to consider it."
end
local warband = root.leading_warband
if warband == nil then
return "You are not a leader of a warband."
end
if warband and warband.status ~= 'idle' then
return "Your warband is busy."
end
if primary_target.realm == nil then
return "Invalid province"
end
return "Raid the province " .. primary_target.name
end,
sorting = 1,
primary_target = "province",
secondary_target = 'none',
base_probability = 0.9 , -- Almost every month
pretrigger = function(root)
return true
end,
clickable = function(root, primary_target)
return true
end,
available = function(root, primary_target)
if root.busy then
return false
end
local warband = root.leading_warband
if warband == nil then
return false
end
if warband and warband.status ~= 'idle' then
return false
end
if primary_target.realm == nil then
return false
end
return true
end,
ai_target = function(root)
---@type Province[]
local targets = {}
for _, province in pairs(root.realm.known_provinces) do
if province.realm and root.realm.tributaries[province.realm] == nil then
table.insert(targets, province)
end
end

local index, prov = tabb.random_select_from_set(targets)
if prov then
return prov, true
end

return nil, false
end,
ai_secondary_target = function(root, primary_target)
return nil, true
end,
ai_will_do = function(root, primary_target, secondary_target)
if root.realm.tributaries[primary_target] then
return 0
end

if root.traits[TRAIT.WARLIKE] then
return 0.2
end

return 0
end,
effect = function(root, primary_target, secondary_target)
MilitaryEffects.covert_raid_no_reward(root, primary_target)
end
}

---@type DecisionCharacterProvince
Decision.CharacterProvince:new {
name = 'patrol-target',
ui_name = "Patrol targeted province",
tooltip = function (root, primary_target)
if root.busy then
return "You are too busy to consider it."
end
local warband = root.leading_warband
if warband == nil then
return "You are not a leader of a warband."
end
if warband and warband.status ~= 'idle' then
return "Your warband is busy."
end
if primary_target.realm == nil then
return "Invalid province"
end
if primary_target.realm ~= root.realm then
return'You can\'t patrol provinces of other realms'
end
return "Patrol the province " .. primary_target.name
end,
sorting = 1,
primary_target = "province",
secondary_target = 'none',
base_probability = 0.9 , -- Almost every month
pretrigger = function(root)
return true
end,
clickable = function(root, primary_target)
return true
end,
available = function(root, primary_target)
if root.busy then
return false
end
local warband = root.leading_warband
if warband == nil then
return false
end
if warband and warband.status ~= 'idle' then
return false
end
if primary_target.realm == nil then
return false
end
if primary_target.realm ~= root.realm then
return false
end
return true
end,
ai_target = function(root)
return root.province, true
end,
ai_secondary_target = function(root, primary_target)
return nil, true
end,
ai_will_do = function(root, primary_target, secondary_target)
if root.leading_warband then
return 0.2
end

return 0
end,
effect = function(root, primary_target, secondary_target)
root.realm:add_patrol(primary_target, root.leading_warband)
end
}
end

return load
11 changes: 9 additions & 2 deletions sote/game/scenes/game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ local inspectors_table = {
["reward-flag-edit"] = require "game.scenes.game.inspector-reward-flag-edit",
["market"] = require "game.scenes.game.inspectors.market",
["macrobuilder"] = require "game.scenes.game.inspectors.macrobuilder",
["macrodecision"] = require "game.scenes.game.inspectors.macrodecision",
}

local tile_inspectors = {
Expand All @@ -49,6 +50,7 @@ local tile_inspectors = {
---@field macrobuilder_building_type BuildingType?
---@field war War?
---@field decision DecisionCharacter?
---@field macrodecision DecisionCharacter?
---@field tech Technology?
---@field cached_tech Technology?
---@field reward_flag RewardFlag?
Expand Down Expand Up @@ -384,6 +386,11 @@ end
function gam.click_tile(tile_id)
gam.clicked_tile_id = tile_id
gam.clicked_tile = WORLD.tiles[tile_id]

if gam.clicked_tile then
gam.selected.province = gam.clicked_tile.province
end

gam.reset_decision_selection()
---@type Tile
if require "engine.table".contains(ARGS, "--dev") then
Expand Down Expand Up @@ -693,7 +700,7 @@ function gam.draw()
end
end

if coll_point and ((gam.camera_position:len() < draw_distance) or (gam.inspector == 'macrobuilder')) then
if coll_point and ((gam.camera_position:len() < draw_distance) or (gam.inspector == 'macrobuilder') or (gam.inspector == 'macrodecision')) then
province_on_map_interaction = true
---comment
---@param province Province
Expand Down Expand Up @@ -746,7 +753,7 @@ function gam.draw()
end

-- drawing provinces
if gam.inspector == 'macrobuilder' then
if gam.inspector == 'macrobuilder' or gam.inspector == 'macrodecision' then
local character = WORLD.player_character
if character then
for _, province in pairs(character.realm.known_provinces) do
Expand Down
15 changes: 13 additions & 2 deletions sote/game/scenes/game/inspectors/left-side-bar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ function inspector.mask()
end
end


---comment
---@param gam GameScene
function inspector.draw(gam)
local rect = get_main_panel()
local base_unit = ut.BASE_HEIGHT * 2
Expand All @@ -30,23 +33,26 @@ function inspector.draw(gam)

local inspectors = {
"macrobuilder",
"macrodecision",
"market",
"army",
"character-decisions",
}

local inspector_icons = {
['macrobuilder'] = ASSETS.icons['hammer-drop.png'],
['macrodecision'] = ASSETS.icons['horizon-road.png'],
['market'] = ASSETS.icons['scales.png'],
['army'] = ASSETS.icons['guards.png'],
['character-decisions'] = ASSETS.icons['envelope.png'],
}

local inspector_tooltips = {
['macrobuilder'] = "Plan development of your estates",
['macrodecision'] = "Target province",
['market'] = "Visit local market",
['army'] = "Visit local warriors",
['character-decisions'] = "Do something",
['army'] = "View local warriors",
['character-decisions'] = "Actions",
}

for _, inspector in pairs(inspectors) do
Expand All @@ -59,6 +65,11 @@ function inspector.draw(gam)
gam.inspector = nil
else
gam.inspector = inspector

local character = WORLD.player_character
if character and gam.inspector == 'market' then
gam.selected.province = character.province
end
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions sote/game/scenes/game/inspectors/macrobuilder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ end
---@param gam GameScene
function inspector.draw(gam)
local rect = get_main_panel()
local base_unit = ut.BASE_HEIGHT + 5
local base_unit = UI_STYLE.scrollable_list_item_height

ui.panel(rect)

Expand All @@ -40,7 +40,7 @@ function inspector.draw(gam)

local top_rect = rect:subrect(0, 0, rect.width - base_unit, base_unit, "left", 'up')

local label_rect = top_rect:subrect(2, 0, top_rect.width / 2, base_unit, "left", 'up')
local label_rect = top_rect:subrect(0, 0, top_rect.width / 2, base_unit, "left", 'up')
ui.centered_text("Construction", label_rect)
local public_flag_rect = top_rect:subrect(0, 0, top_rect.width / 2, base_unit, "right", 'up')

Expand Down
101 changes: 101 additions & 0 deletions sote/game/scenes/game/inspectors/macrodecision.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
local inspector = {}

local ui = require "engine.ui";
local ut = require "game.ui-utils"

local scroll = 0

---@return Rect
local function get_main_panel()
local fs = ui.fullscreen()
local panel = fs:subrect(ut.BASE_HEIGHT * 2, ut.BASE_HEIGHT * 2, ut.BASE_HEIGHT * 15 , fs.height - ut.BASE_HEIGHT * 2, "left", 'up')
return panel
end

---Returns whether or not clicks on the planet can be registered.
---@return boolean
function inspector.mask()
if ui.trigger(get_main_panel()) then
return false
else
return true
end
end

---comment
---@param gam GameScene
function inspector.draw(gam)
local rect = get_main_panel()

ui.panel(rect)

local top_rect = rect:subrect(0, 0, rect.width - UI_STYLE.slider_width, UI_STYLE.scrollable_list_item_height, "left", 'up')

ui.centered_text("Provincial decisions", top_rect)

local decisions_rect = rect:subrect(
0,
UI_STYLE.scrollable_list_item_height,
rect.width,
rect.height - UI_STYLE.scrollable_list_item_height,
"left",
'up'
)

if WORLD.player_character == nil then
return
end

-- love.graphics.print("Decision selection", rect.x, rect.y)
local total = 0
local valid = 0

-- Maps decisions to whether or not they can be clicked.
---@type table<number, {[1]: DecisionCharacter, [2]: boolean}>
local decisions = {}
for _, decision in pairs(RAWS_MANAGER.decisions_characters_by_name) do
if decision.primary_target == 'province' then
if decision.pretrigger(WORLD.player_character) then
decisions[#decisions + 1] = { decision, true }
valid = valid + 1
end
total = total + 1
end
end
-- love.graphics.print("Total" .. tostring(total), rect.x, rect.y)
-- love.graphics.print("Valid" .. tostring(valid), rect.x, rect.y + 20)

-- Once the list of decisions is known, we can sort it by the decisions sorting order
table.sort(decisions, function(a, b)
return a[1].sorting < b[1].sorting
end)


scroll = ui.scrollview(
decisions_rect,
function(i, rect)
if i > 0 then
local dec = decisions[i]
---@type DecisionCharacter
local decis = dec[1]
local available = dec[2]
local active = decis == gam.selected.macrodecision
if ut.text_button(decis.ui_name, rect, nil, available, active) then
print("Player selected the macrodecision: " .. decis.name)
if active then
gam.selected.macrodecision = nil
else
gam.selected.macrodecision = decis
end
end
end
end,
UI_STYLE.scrollable_list_item_height,
#decisions,
UI_STYLE.slider_width,
scroll
)
end


return inspector
Loading