Skip to content

Commit

Permalink
Implement prisoner auto-ransom to ransom broker in nearest town.
Browse files Browse the repository at this point in the history
Money is stored in the camp until the player visits it.
  • Loading branch information
angavrilov committed Jun 22, 2015
1 parent 3df759d commit b21eb61
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 6 deletions.
12 changes: 7 additions & 5 deletions pcamp_constants.py
Expand Up @@ -41,8 +41,10 @@
slot_pcamp_camp_chest = slot_town_merchant
slot_pcamp_camp_initialized = slot_center_player_relation

slot_pcamp_chest_commander = slot_troop_guardian
slot_pcamp_chest_party = slot_troop_home
slot_pcamp_chest_center = slot_troop_cur_center
slot_pcamp_chest_items = slot_troop_renown
slot_pcamp_chest_value = slot_troop_wealth
slot_pcamp_chest_commander = 33 #slot_troop_guardian
slot_pcamp_chest_party = 60 #slot_troop_home
slot_pcamp_chest_center = 12 #slot_troop_cur_center
slot_pcamp_chest_city = 9 #slot_troop_present_at_event
slot_pcamp_chest_items = 7 #slot_troop_renown
slot_pcamp_chest_value = 11 #slot_troop_wealth
slot_pcamp_chest_sell_prisoners = 16 #slot_troop_player_order_state
30 changes: 30 additions & 0 deletions pcamp_dialogs.py
Expand Up @@ -55,6 +55,36 @@
(change_screen_loot, ":chest")
] ],

[anyone|plyr, "player_camp_choice",
[
(party_get_slot, ":chest", "$g_talk_troop_party", slot_pcamp_camp_chest),
(neg|troop_slot_eq, ":chest", slot_pcamp_chest_sell_prisoners, 1),
(troop_get_slot, ":city", ":chest", slot_pcamp_chest_city),
(str_store_party_name, s0, ":city"),
],
"I want you to ransom all prisoners in {s0} whenever possible.", "player_camp_ransom_on",
[
(party_get_slot, ":chest", "$g_talk_troop_party", slot_pcamp_camp_chest),
(troop_set_slot, ":chest", slot_pcamp_chest_sell_prisoners, 1),
] ],

[anyone, "player_camp_ransom_on", [],
"Very well, I will do that whenever there is a broker in the city.", "player_camp_start", [] ],

[anyone|plyr, "player_camp_choice",
[
(party_get_slot, ":chest", "$g_talk_troop_party", slot_pcamp_camp_chest),
(troop_slot_eq, ":chest", slot_pcamp_chest_sell_prisoners, 1),
],
"I want you to stop ransoming all prisoners on your own.", "player_camp_ransom_off",
[
(party_get_slot, ":chest", "$g_talk_troop_party", slot_pcamp_camp_chest),
(troop_set_slot, ":chest", slot_pcamp_chest_sell_prisoners, 0),
] ],

[anyone, "player_camp_ransom_off", [],
"Very well, I will keep them safe here in the camp.", "player_camp_start", [] ],

[anyone|plyr, "player_camp_choice",
[
(assign, ":num_free", 0),
Expand Down
11 changes: 10 additions & 1 deletion pcamp_game_menus.py
Expand Up @@ -186,10 +186,13 @@

# Register links to chest
(assign, ":camp_chest", "$g_talk_troop_party"),
(call_script, "script_cleanup_player_camp_slot", ":camp_chest"),
(troop_set_slot, ":camp_chest", slot_pcamp_chest_party, ":camp_party"),
(troop_set_slot, ":camp_chest", slot_pcamp_chest_center, "$g_talk_troop_faction"),
(party_set_slot, ":camp_party", slot_pcamp_camp_chest, ":camp_chest"),
(troop_clear_inventory, ":camp_chest"),

(call_script, "script_find_closest_town", ":camp_party"),
(troop_set_slot, ":camp_chest", slot_pcamp_chest_city, reg0),

# Set the commander; the party should always remain fac_player_faction
(call_script, "script_set_player_camp_commander", ":camp_party", "$g_talk_troop"),
Expand All @@ -215,6 +218,12 @@
(change_screen_return),
(else_try),
(party_get_slot, "$g_talk_troop", "$g_encountered_party", slot_pcamp_camp_commander),
(party_get_slot, ":camp_chest", "$g_encountered_party", slot_pcamp_camp_chest),
# withdraw cash
(store_troop_gold, ":gold", ":camp_chest"),
(troop_remove_gold, ":camp_chest", ":gold"),
(troop_add_gold, "trp_player", ":gold"),
# update stuff
(call_script, "script_calc_player_camp_bandit_attraction", "$g_encountered_party"),
(call_script, "script_set_pcamp_banner_from_troop", "$g_encountered_party", "trp_player"),
(str_store_troop_name, s3, "$g_talk_troop"),
Expand Down
4 changes: 4 additions & 0 deletions pcamp_readme.txt
Expand Up @@ -15,6 +15,10 @@ Features:
- Camp will join in the battle if player is attacked right on top of it.
- Player will stop resting and join battle if current camp is attacked.

* Miscellaneous features.

- Camp can auto-ransom prisoners when there is a broker in the nearest town.

Configuration:

There are some options at the start of pcamp_constants.py. The absolute maximum
Expand Down
70 changes: 70 additions & 0 deletions pcamp_scripts.py
Expand Up @@ -281,7 +281,10 @@

(troop_set_slot, ":chest", slot_pcamp_chest_party, 0),
(troop_set_slot, ":chest", slot_pcamp_chest_commander, 0),
(troop_set_slot, ":chest", slot_pcamp_chest_sell_prisoners, 0),
(troop_clear_inventory, ":chest"),
(store_troop_gold, ":gold", ":chest"),
(troop_remove_gold, ":chest", ":gold"),
]),

("cleanup_player_camp_commander",
Expand Down Expand Up @@ -502,6 +505,73 @@
(assign, reg0, ":best_camp"),
(assign, reg1, ":min_distance"),
]),

("find_closest_town",
[
(store_script_param_1, ":party_no"),
(assign, reg0, -1),
(assign, reg1, 9999999),
(try_for_range, ":town_no", towns_begin, towns_end),
(store_distance_to_party_from_party, ":distance", ":party_no", ":town_no"),
(lt, ":distance", reg1),
(assign, reg0, ":town_no"),
(assign, reg1, ":distance"),
(try_end),
]),

("pcamp_ransom_prisoners",
[
(assign, ":old_tt", "$g_talk_troop"),

(try_for_range, ":chest", pcamp_chests_begin, pcamp_chests_end),
(troop_slot_eq, ":chest", slot_pcamp_chest_sell_prisoners, 1),

(troop_get_slot, ":party", ":chest", slot_pcamp_chest_party),
(gt, ":party", 0),
(party_is_active, ":party"),

# requires broker in city
(troop_get_slot, ":city", ":chest", slot_pcamp_chest_city),
(is_between, ":city", towns_begin, towns_end),
(party_get_slot, "$g_talk_troop", ":city", slot_center_ransom_broker),
(gt, "$g_talk_troop", 0),

# can't sell in enemy cities
(store_faction_of_party, ":city_faction", ":city"),
(store_relation, ":faction_rel", ":city_faction", "fac_player_faction"),
(ge, ":faction_rel", 0),

(assign, ":total", 0),

(party_get_num_prisoner_stacks, ":num_stacks", ":party"),
(try_for_range_backwards, ":stack_no", 0, ":num_stacks"),
(party_prisoner_stack_get_troop_id, ":stack_troop",":party",":stack_no"),
(neg|troop_is_hero, ":stack_troop"),
(party_prisoner_stack_get_size, ":stack_size",":party",":stack_no"),
(call_script, "script_game_get_prisoner_price", ":stack_troop"),
(store_mul, ":price", ":stack_size", reg0),
(val_add, ":total", ":price"),
(party_remove_prisoners, ":party", ":stack_troop", ":stack_size"),

(try_begin),
(eq, "$cheat_mode", 1),
(assign, reg0, ":price"),
(assign, reg1, ":stack_size"),
(str_store_troop_name, s0, ":chest"),
(str_store_troop_name, s1, ":stack_troop"),
(display_message, "@{!}DEBUG: {s0} sold {reg1} {s1} for {reg0}"),
(try_end),
(try_end),

(try_begin),
(gt, ":total", 0),
(troop_add_gold, ":chest", ":total"),
(call_script, "script_calc_player_camp_bandit_attraction", ":party"),
(try_end),
(try_end),

(assign, "$g_talk_troop", ":old_tt"),
]),
]

x = [
Expand Down
14 changes: 14 additions & 0 deletions pcamp_simple_triggers.py
Expand Up @@ -78,6 +78,20 @@
]
],
]),
# Auto-ransom prisoners every 6 hours
([
(assign, ":resting_at_manor_or_walled_center", 0),
(assign, "$g_half_payment_checkpoint", 0),
],[
[
SD_OP_BLOCK_INSERT, "",
D_SEARCH_FROM_TOP | D_SEARCH_LINENUMBER | D_INSERT_BEFORE,
0, 0,
[
(call_script, "script_pcamp_ransom_prisoners"),
]
],
]),
]

new_triggers = [
Expand Down

0 comments on commit b21eb61

Please sign in to comment.