Looting equipped items

Users who are viewing this thread

sirinan

Regular
This is probably a really simple one, but bear with me - I'm only just starting to look at the module source.

It's always bugged me that some troop types give way more loot than others. Extreme examples being sea raiders, who give you abundant loot, compared to, say, Nord huntsmen, where the only loot you will ever get is a shirt.

Looking at the script that defines what loot is given, I think I understand why that is - it doesn't consider equipped items when it tallies up the available loot - only the items which appear in their inventory. And for troops which are given a lot of alternate items, such as sea raiders, they will be given a lot of items which they will not be equipping.

I want to change that. Rather than cycling through the inventory items, I want to cycle through the equipped items.

So, the question is, is there an equivalent array attached to the troop for equipped items that I can replace the inventory array with? Or is it a bit messier than that?

Any help, or pointers to information I can use, would be appreciated.
 
you can check what an agent is wielding his his hands, but that's as far as I can help you with my current knowledge.  I have done some code that let's you take from an agent (or his troop ID), and found that the change_screen_trade operation lets you take from what he is currently using, where change_screen_loot gives what is in their inventory.

I would think that the best thing to do would be to go through the dead agents and build an array of the items they have.  Put these items into the inventory (search for equip) of a dummy troop, then loot that troop.  This is just off the top of my head.
 
yeah, this has always annoyed me, I've had to give all my troop duplicate items so there is a chance they will drop.  This would be very neat to fix, and while I'm not sure how to fix it, I'll try to give some examples of similar stuff I've done....

equipped items are actually in inventory slot 0-9.  fisheye had a description somewhere of what number is what, but I have this code to loop through and clear all equipped items.  You could just do a troop_get_inventory slot for 0-9 instead.

Code:
        (try_for_range,":knight",reserved_knight_begin,reserved_knight_end),	#SW modified
			#clear any inventory
			(troop_clear_inventory, ":knight"),
			#remove all equipment
			(try_for_range, ":slot_no", 0, 9),
				#(troop_get_inventory_slot,":cur_item",":knight",":slot_no"),
				(troop_set_inventory_slot, ":knight",":slot_no",-1),
			(try_end),
		(try_end),

I also have the following code that is very similar and loops through the inventory checking if they have certain items (bacta_injector or bacta_capsules).  So I think you'd just want to loop from slot 0 to :inv_cap and get all the items.  I'm not sure if there will be any different behavior for regular troops vs tf_hero type of troops tho?

Code:
			#(troop_get_inventory_capacity, ":inv_cap", "trp_player"),
			(troop_get_inventory_capacity, ":inv_cap", "$g_player_troop"),	#since custom commander is integrated
			(assign, ":healing_item_injector_slot", -1),
			(assign, ":healing_item_capsule_slot", -1),
			(assign, reg1, 0),
			(try_for_range, ":slot_no", 0, ":inv_cap"),
				#(troop_get_inventory_slot,":item_id","trp_player",":slot_no"),
				(troop_get_inventory_slot,":item_id","$g_player_troop",":slot_no"),	#since custom commander is integrated
				(try_begin),
					(eq, ":item_id", "itm_bacta_injector"),
						(assign, ":healing_item_injector_slot", ":slot_no"),
				(else_try),
					(eq, ":item_id", "itm_bacta_capsule"),
						(assign, ":healing_item_capsule_slot", ":slot_no"),
						(val_add, reg1, 1),
				(try_end),
			(try_end),
 
Thanks guys

@HokieBT, I found the info on the 0-9 slots in header_items.py just before you posted. :smile: For completeness, it seems that 0-3 are the general (weapon) slots, 4 is head/helm, 5 is body, 6 is leg/foot, 7 is hand/gloves, 8 is horse, and 9 is food(? is it used?)

jiks idea of putting the stuff into a dummy troop and looting that makes sense, so I'll give that a shot.
 
food is no longer used (its disabled in the module.ini), but its possible some mods may re-enable it so you might want to check it anyway.  Let us know if you get this working, it would be nice to fix.  :smile:
 
Well, it seems to work, or at least I'm seeing items that I've never seen before when looting, and the amounts seem to be fairly consistent as to numbers of items per troop. I was expecting far more trouble.

The only changes I've made are to party_calculate_loot in module_scripts.py:

      (try_for_range, ":i_stack", 0, ":num_stacks"),
        (party_stack_get_troop_id,    ":stack_troop",":enemy_party",":i_stack"),
        (neg|troop_is_hero, ":stack_troop"),
        (party_stack_get_size, ":stack_size",":enemy_party",":i_stack"),
        (try_for_range, ":unused", 0, ":stack_size"),
    (troop_clear_inventory, "trp_temp_array_a"),
    (try_for_range, ":i_slot", 0, 9),
      (troop_get_inventory_slot, ":item_id", ":stack_troop", ":i_slot"),
      (gt,":item_id",0),
      (troop_get_inventory_slot_modifier,":modifier",":stack_troop",":i_slot"),
      (troop_add_item, "trp_temp_array_a", ":item_id", ":modifier"),
    (try_end),

          (troop_loot_troop,"trp_temp_troop","trp_temp_array_a",":loot_probability"),
        (try_end),
      (try_end),
      (troop_get_inventory_capacity, ":inv_cap", "trp_temp_troop"),
      (try_for_range, ":i_slot", 0, ":inv_cap"),
        (troop_get_inventory_slot, ":item_id", "trp_temp_troop", ":i_slot"),
        (ge, ":item_id", 0),
        (val_add, ":num_looted_items",1),
      (try_end),

The green lines are the ones I've added, and the red is where I changed the value from :stack_troop to trp_temp_array_a

The only issue I can think of is that now, looting caravans won't give you goods. Wouldn't be too hard to do a test on the rest of the items as to whether they're goods or not, and add them in, I guess.

If it looks like I've done anything wrong, go easy on me - it's my first attempt at editing the module system. :grin:

Edit: Added a couple of lines as recommended by Slawomir of Aaarrghh below
 
sirinan said:
Well, it seems to work, or at least I'm seeing items that I've never seen before when looting, and the amounts seem to be fairly consistent as to numbers of items per troop. I was expecting far more trouble.

The only changes I've made are to party_calculate_loot in module_scripts.py:

      (try_for_range, ":i_stack", 0, ":num_stacks"),
        (party_stack_get_troop_id,    ":stack_troop",":enemy_party",":i_stack"),
        (neg|troop_is_hero, ":stack_troop"),
        (party_stack_get_size, ":stack_size",":enemy_party",":i_stack"),
        (try_for_range, ":unused", 0, ":stack_size"),
    (try_for_range, ":i_slot", 0, 9),
      (troop_get_inventory_slot, ":item_id", ":stack_troop", ":i_slot"),
  (troop_add_item, "trp_temp_array_a", ":item_id", ),
    (try_end),

          (troop_loot_troop,"trp_temp_troop","trp_temp_array_a",":loot_probability"),
        (try_end),
      (try_end),
      (troop_get_inventory_capacity, ":inv_cap", "trp_temp_troop"),
      (try_for_range, ":i_slot", 0, ":inv_cap"),
        (troop_get_inventory_slot, ":item_id", "trp_temp_troop", ":i_slot"),
        (ge, ":item_id", 0),
        (val_add, ":num_looted_items",1),
      (try_end),

The green lines are the ones I've added, and the red is where I changed the value from :stack_troop to trp_temp_array_a

The only issue I can think of is that now, looting caravans won't give you goods. Wouldn't be too hard to do a test on the rest of the items as to whether they're goods or not, and add them in, I guess.

If it looks like I've done anything wrong, go easy on me - it's my first attempt at editing the module system. :grin:
I think that is because you clear the invertory, so the goods caravans carry are deleted. I think simply leaving the clear_invertory line out would do the job...
 
Sorry, I probably wasn't very clear - I expect it to break caravans, because of the way it works. And I meant it to work the way it does. :smile:

Incidentally, all it would need is to replace the '9' in the try_for_range I added to be the inventory size of stack_troop, and it would add all inventory items back into the mix. I probably won't do this for myself though.
 
It shouldn't break caravan loot, since you don't clear trp_temp_troop inventory. Caravan loot is defined a little earlier and its assigned to trp_temp_troop, not trp_temp_array_a.

(troop_add_merchandise, "trp_temp_troop", itp_type_goods, ":plunder_amount"),

So it should work fine.
 
You're right - I hadn't seen that, and was just assuming that caravan goods were in the caravan master's inventory.
 
Very cool, nice work.  I haven't tried it yet, but had a few questions:

1) Will equipped items with itp_unique (ie. non-lootable) now appear?
2) Will random item modifiers still work?
3) Will flags like itp_always_loot now not work?
 
From what I understand it should be:

1) Yes
2) Yes (if item modifiers are set when looting) or No (if they are set on stack troop)
3) Yes

Though I'm not sure about that. You still loot a troop (with inventory that was set by the script), so most of the things should work.

Code posted by sirinan has one big mistake, because it will add non egsisting items to inventory of the troop, that we will loot. There should be additional check for empty stack troop inventory slots. Something like this:

(troop_clear_inventory,"trp_temp_array_a"),
(try_for_range,":slot",0,9),
(troop_get_inventory_slot,":item",":stack_troop",":slot"),
(gt,":item",0),
(troop_get_inventory_slot_modifier,":modifier",":stack_troop",":slot"),
(troop_add_item,"trp_temp_array_a",":item",":modifier"),
(try_end),
          (troop_loot_troop,"trp_temp_troop","trp_temp_array_a",":loot_probability"),

In the code above I added also coping of the item modifier, this should probably fix the all-plain (no modifier) modifiers of items (if such a problem occurs).
 
Thanks for that - you clearly understand what I've done better than I do! (I'm definitely in the category of only knowing enough to be dangerous.)
 
Still good job on your part.  The only thing I would worry about is too much loot from a large battle, or stuff not being added from pausing between battles (you beat a few waves and the game asks if you want to keep fighting and what not).

You may want to do a bit of random (this weapon/armor is not useless/destroyed/whatnot) dropping of equipment from the loot.  Maybe 20% chance that its useless.

With loot from various waves, you may want to run code at the end of each mission_template battle that adds the junk to your temp array. 

By the way, your the first recruit that I have seen handle that aspect of the code well.
 
jik said:
The only thing I would worry about is too much loot from a large battle, or stuff not being added from pausing between battles (you beat a few waves and the game asks if you want to keep fighting and what not).
Yeah, the balance needs to be checked. On a somewhat related note, does anyone know what the probability of a troop being given any (non guaranteed) item in their item list is?

With loot from various waves, you may want to run code at the end of each mission_template battle that adds the junk to your temp array.
Logically, I'm not sure that's necessary... I really haven't done anything to trp_temp_troop or the way it works, which is where the loot is being stored. I haven't tested a battle with multiple waves yet though.

By the way, your the first recruit that I have seen handle that aspect of the code well.
Thanks! (Oh, the pressure to live up to! :grin:)
 
Well I have noticed that in large battles (often more than 2 pauses in the action), if the last battle is small (say they only have about 20 left from 500 soldiers) that there is barely any loot.  This would lead me to beleive (since I have not looked at the loot code before now) that this process is done at the end of the battle only, for the last mission_template run.  This kind of sucks if you were the underdog and had to fight wave after wave of enemies, then in the end, getting less than a handful of loot.

What can be done, is to make an alternate temp array and store the gear of the fallen (including your own soldiers that die) there.  Make about a 20% loss.  Also, make a cap of say 50 items.  If you want to get fancy you can drop less expensive items for better ones...
 
I'll take a look, and do what I can...

Any thoughts on why it would be happening, if it doesn't happen in native? As I said, I haven't changed the fundamental mechanics of the looting process, only the items which are available for looting. I don't understand how it could produce a different result... :sad:
 
I don't understand how it could produce a different result...

It couldn't, since it works like Native script. The only difference is that your modification loots equiped items. As far as I recall that issue with too small loot after big battles was already in Native.

I'll have to take a look at it, because it's worth fixing.
 
jik said:
Well I have noticed that in large battles (often more than 2 pauses in the action), if the last battle is small (say they only have about 20 left from 500 soldiers) that there is barely any loot.  This would lead me to beleive (since I have not looked at the loot code before now) that this process is done at the end of the battle only, for the last mission_template run.  This kind of sucks if you were the underdog and had to fight wave after wave of enemies, then in the end, getting less than a handful of loot.

What can be done, is to make an alternate temp array and store the gear of the fallen (including your own soldiers that die) there.  Make about a 20% loss.  Also, make a cap of say 50 items.  If you want to get fancy you can drop less expensive items for better ones...

I'd love to see the code for this, the autoloot by fisheye as adjusted by rubik can handle somewhere around 84-94 items, but it is easy to cut the loot to that amount.
The native code also seems to mess up in large battles, producing large amounts of identical equipement, most of it not worthwhile. A price based sort before and cutting off the cheap items would be preferable.

mfberg
 
Thanks S of A, good to know I'm not going insane (at least not for that reason. :smile: )

mfberg said:
The native code also seems to mess up in large battles, producing large amounts of identical equipement
From my reading of the code, that's because for each stack of troops, you're effectively looting the same guy over and over. I don't know whether this can be changed - troops seem to be generically identified by stack, not individually.

It's disappointing that 'real' looting doesn't seem to be possible - meaning looting of the actual troops who took part in the battle, with their individual assignments of gear. Or is it... I wonder if it's possible to create an array of gear during the actual battle, and pass that on to the looting code... Hmm...

 
Back
Top Bottom