Prisoner ransom based upon prisoner level

Users who are viewing this thread

TalonAquila

Sergeant Knight
I've been trying for 3 days to get this to work... it won't use the formula no matter what i do...
  Here's the code as it now stands... the result is 1 (one), which is the level of the looters i'm trying to ransom.
Note: check for broker or keeper moved trying to force the calculations...
  ("game_get_prisoner_price",
    [
      (store_script_param_1, ":troop_id"),
  (try_begin),
        (store_character_level, ":troop_level", ":troop_id"), # set local variable ":troop_level" equal to param1 ":troop_id"        (assign, ":ransom_amount", ":troop_level"), # now we have a number we can work with  
#        (is_between, "$g_talk_troop", ransom_brokers_begin, ransom_brokers_end),
#  add tavernkeepers since ransom brokers are never around when you need one
#        (is_between, "$g_talk_troop", tavernkeepers_begin, tavernkeepers_end),
#  calculate ransom
        (val_add, ":ransom_amount", 10),
        (val_mul, ":ransom_amount", ":ransom_amount"),
        (val_div, ":ransom_amount", 6),
#  double the ransom for mounted troops        (troop_is_mounted, ":troop_id"),
        (val_mul, ":ransom_amount", 2),
        (is_between, "$g_talk_troop", ransom_brokers_begin, ransom_brokers_end),
#  add tavernkeepers since ransom brokers are never around when you need one        (is_between, "$g_talk_troop", tavernkeepers_begin, tavernkeepers_end),
        (assign, reg0, ":ransom_amount"),
#    (else_try),
#      (assign, reg0, 50),# Ramun's fixed ransom

(try_end),
      (set_trigger_result, reg0),
  ]),



 
I'm going to have to do some guesswork because the code you posted is in a semi-ambiguous state.
Here's what I think you meant:
("game_get_prisoner_price",
[
(store_script_param_1, ":troop_id"),
(try_begin),
(store_character_level, ":troop_level", ":troop_id"),
# set local variable ":troop_level" equal to param1 ":troop_id"       
(assign, ":ransom_amount", ":troop_level"), # now we have a number we can work with   
#        (is_between, "$g_talk_troop", ransom_brokers_begin, ransom_brokers_end),
#  add tavernkeepers since ransom brokers are never around when you need one
#        (is_between, "$g_talk_troop", tavernkeepers_begin, tavernkeepers_end),
#  calculate ransom       
(val_add, ":ransom_amount", 10),
(val_mul, ":ransom_amount", ":ransom_amount"),
(val_div, ":ransom_amount", 6),
#  double the ransom for mounted troops       
(troop_is_mounted, ":troop_id"),
(val_mul, ":ransom_amount", 2),
(is_between, "$g_talk_troop", ransom_brokers_begin, ransom_brokers_end),
#  add tavernkeepers since ransom brokers are never around when you need one       
(is_between, "$g_talk_troop", tavernkeepers_begin, tavernkeepers_end),     
(assign, reg0, ":ransom_amount"),
#    (else_try),
#          (assign, reg0, 50),# Ramun's fixed ransom
(try_end),
(set_trigger_result, reg0),
]),

If that's the case, take a look at the bit in red.  If your troop is not mounted, it will bail out of the (try_begin)/(try_end) block right there leaving the value of reg0 as whatever it happens to be when you enter that function.  I've taken the liberty to hack up my hacked up version of the original function with the intent you've stated:
("game_get_prisoner_price",
[
(store_script_param_1, ":troop_id"),
(assign, reg0, 50),
(try_begin),
(this_or_next|is_between, "$g_talk_troop", ransom_brokers_begin, ransom_brokers_end),
(is_between, "$g_talk_troop", tavernkeepers_begin, tavernkeepers_end),
(store_character_level, ":troop_level", ":troop_id"),
(assign, ":ransom_amount", ":troop_level"),
(val_add, ":ransom_amount", 10),
(val_mul, ":ransom_amount", ":ransom_amount"),
(val_div, ":ransom_amount", 6),
(try_begin),
(troop_is_mounted, ":troop_id"),
(val_mul, ":ransom_amount", 2),
(try_end),
(assign, reg0, ":ransom_amount"),
(try_end),
(set_trigger_result, reg0),
]),

This should allow you to sell to tavenkeeps as well as doubling the sell price of mounted troops while keeping Ramun's functionality.  I haven't tested this particular function, YMMV, yadda.  Hope that helps.

edit>  fixed a typo
 
Thanks for the quick reply.  I'll do the edit and re-compile, test it and let you know.

edit: It's using the (assign,reg0,50) and skipping to the final trigger.  I'm testing with looters, so the result should come out as 32.
  I'll keep pluggin' away at it... got me feelin' like an old dog with a bone, now...

2nd edit: commenting out the addign reg0, gave interesting results...
ransombroker: 21, from there to t-keeper: -574591248, back to broker: 192, back to t-keeper: 192, and 3 more trips to each: 192.

damned if I can figure out what it's doing.
 
I just copied & pasted the code into mine, compiled, grabbed some prisoners, and it worked fine.  I've even got a typo in the above code (I'll fix it shortly).

Not sure what's wrong with your version.  It should be working.  Make sure that you've made the appropriate modifications and go from there. 
 
I'm stumped on this one.  The function you're calling should be fine which means that the error most likely lies somewhere else.

Random debugging questions:
- Have you changed your tavernkeeper or ransom troops?
- Are your begin/end constants for tavernkeepers still correct?
- Have you made other troop modifications?
- Are you testing with an old save game?
- Is there any weirdness in the calling dialogs?
- Can you put some display_message calls in your function to see where it's bailing out of the topmost try_begin block?

Registers like reg0 are generic globals that don't get saved with save games.  If you don't set them in the function, they keep whatever value they came in with.  The register reg0 is one that's typically used to pass values around so it's not surprising that it comes into that function with weird values.  The line (set_trigger_result, reg0), just sends whatever's in reg0 to the game as the return of the function.
 
all tests have been done with new character creation.  i even made a clean install of M&B and the module system to new folders,on another drive, in something other than default directory (obviously).  Same screwy results.  i even made my wife try it with female character.

i haven't seen anything like this since my COBOL days... now i'm really dating myself, eh?

anyway, if i set reg0 first, the value is always whatever value i put there to initilize it, i.e. 0,50, 150 and finally 2500....

i even went so far as to wipe the whole section out and re-key it all in from scratch... i thought at first it was just my medications getting in the way of my intellect, but i'm certain after all this that isn't the case... roflmao ( if i don't, i'll ccry a river)
 
The plot thicks!  If you'll indulge my curiosity for a bit, try taking out the this_or_next from the first is_between and comment out the tavernkeeps thing and see if it works OK for ransom brokers.  It should look something like this:
("game_get_prisoner_price",
[
  (store_script_param_1, ":troop_id"),
  (assign, reg0, 50),
  (try_begin),
      (is_between, "$g_talk_troop", ransom_brokers_begin, ransom_brokers_end),
      #(is_between, "$g_talk_troop", tavernkeepers_begin, tavernkeepers_end),
      (store_character_level, ":troop_level", ":troop_id"),
      (assign, ":ransom_amount", ":troop_level"),
      (val_add, ":ransom_amount", 10),
      (val_mul, ":ransom_amount", ":ransom_amount"),
      (val_div, ":ransom_amount", 6),
      (try_begin),
        (troop_is_mounted, ":troop_id"),
        (val_mul, ":ransom_amount", 2),
      (try_end),
      (assign, reg0, ":ransom_amount"),
  (try_end),
  (set_trigger_result, reg0),
]),

I had the same annoyance as you did; that ransom brokers were never around when I wanted them, so I added a bunch more.  Adding 5 more (just copy the last guy and increment the troop number) will give you a roughly 3/4 chance of seeing a ransom guy in a tavern rather than the roughly 1/2 chance in Native.  The end constant should take care of itself.

Let me know if that works or otherwise.  This should be more straightforward than it's proving to be  :mrgreen:

Also:  COBOL?  ow! 
 
as my creole aunt used to say... aaayeeeee!  ransom broker:32  T-keeper:50
new character so i didn't try for a mounted prisoner, but i suspect it'll work the same way.
dip me in dog**** and call me rose... i never figured a check for tavernkeepers would through the whole thing off that way... well done, and thank you.
  i'll probably take your route and just add a few more brokers.

edit: if i comment out the brokers and check for t-keepers, results reversed... it appears i'll have to use the extra brokers method you suggested.  i think we've discovered why this piece of code wasn't used in native... y' think?
 
here it is ...

("game_get_prisoner_price",
[
  (store_script_param_1, ":troop_id"),
  (assign, reg0, 0),# make certain it's empty
  (try_begin),
#      (is_between, "$g_talk_troop", ransom_brokers_begin, ransom_brokers_end),
      (is_between, "$g_talk_troop", tavernkeepers_begin, tavernkeepers_end),
      (store_character_level, ":troop_level", ":troop_id"),
      (assign, ":ransom_amount", ":troop_level"),
      (val_add, ":ransom_amount", 10),
      (val_mul, ":ransom_amount", ":ransom_amount"),
      (val_div, ":ransom_amount", 6),
      (try_begin),
        (troop_is_mounted, ":troop_id"),
        (val_mul, ":ransom_amount", 2),
      (try_end),
      (assign, reg0, ":ransom_amount"),
(else_try),
  (assign, reg0, 50), # Ramun's fixed ransom
  (try_end),
  (set_trigger_result, reg0),
]),
 
woke up this mornin' with solution on the brain... here's my code...

("game_get_prisoner_price",
[
  (store_script_param_1, ":troop_id"),
  (assign, reg0, 0),# make certain it's empty
  (try_begin),
#  do the calculations
      (store_character_level, ":troop_level", ":troop_id"),
      (assign, ":ransom_amount", ":troop_level"),
      (val_add, ":ransom_amount", 10),
      (val_mul, ":ransom_amount", ":ransom_amount"),
      (val_div, ":ransom_amount", 6),
      (try_begin), # double the ransom for mounted troops
        (troop_is_mounted, ":troop_id"),
        (val_mul, ":ransom_amount", 2),
      (try_end),
  (try_begin),
    (try_begin),
          (is_between, "$g_talk_troop", ransom_brokers_begin, ransom_brokers_end),
    (else_try),
          (is_between, "$g_talk_troop", tavernkeepers_begin, tavernkeepers_end),
(try_end), 
        (assign, reg0, ":ransom_amount"),
  (try_end),
  (else_try),
  (assign, reg0, 50), # Ramun's fixed ransom
  (try_end),
  (set_trigger_result, reg0),
]),



  # script_game_check_prisoner_can_be_sold
  # This script is called from the game engine for checking if a given troop can be sold.
  # Input:
  # param1: troop_id,
  # Output: reg0: 1= can be sold; 0= cannot be sold.
 
  ("game_check_prisoner_can_be_sold",
    [
      (store_script_param_1, ":troop_id"),
      (assign, reg0, 0),
      (try_begin),
        (neg|troop_is_hero, ":troop_id"),
        (assign, reg0, 1),
      (try_end),
      (set_trigger_result, reg0),
  ]),

tested with broker, t-keeper and Ramun... Ramun buys for 50, while broker and t-keeper buy according to prisoner rank.  :grin: i do feel fine, heh
 
As I suspected, you were missing this_or_next.  That will make it a logical OR between the two is_between calls rather than a logical AND.  Mods below in red:
("game_get_prisoner_price",
[
  (store_script_param_1, ":troop_id"),
  (assign, reg0, 0),# make certain it's empty
  (try_begin),
      (this_or_next|is_between, "$g_talk_troop", ransom_brokers_begin, ransom_brokers_end),
      (is_between, "$g_talk_troop", tavernkeepers_begin, tavernkeepers_end),
      (store_character_level, ":troop_level", ":troop_id"),
      (assign, ":ransom_amount", ":troop_level"),
      (val_add, ":ransom_amount", 10),
      (val_mul, ":ransom_amount", ":ransom_amount"),
      (val_div, ":ransom_amount", 6),
      (try_begin),
        (troop_is_mounted, ":troop_id"),
        (val_mul, ":ransom_amount", 2),
      (try_end),
      (assign, reg0, ":ransom_amount"),
(else_try),
  (assign, reg0, 50), # Ramun's fixed ransom
  (try_end),
  (set_trigger_result, reg0),
]),

I think that should work as well.  I haven't had my caffeine.  Sorry for any confusion.
 
Back
Top Bottom