too many troops!

Currently viewing this thread:

jik

Knight
Since the mod I am working on has troops that are for various "jobs", I have been manually spawning the troops to the scenes.  The first round works find, but it seems that if I have wounded, they are counted twice when adding the troops to the scene.  Here is the code I am using:
##script_search_party
##Called before jumping into the mission_template
##Input : The party searching, but will mostly be the player party; Max troops that can be at the scene, default/max is 40
##Output: Sets up the visitor slots for the search team, up to 20 fighting members per entry point.
("search_party",
[(store_script_param,":cur_party",1),
(store_script_param,":max_troops",2),
(try_for_range,":search_slot",scav_start,fighter_start),
(party_set_slot,"p_bus",":search_slot",0), ##reset the locator troop numbers in the scene
(try_end),
(try_begin),
(this_or_next|gt,":max_troops",40),
(lt,":max_troops",1),
(assign, ":max_troops",40),          ##Set the default
(try_end),
(party_get_num_companion_stacks,":stacks",":cur_party"),
(val_add,":stacks",1),                                  ##Make sure to get the last stack
(try_for_range, ":cur_stack",1,":stacks"),              ##Loop through the stacks
(gt, ":max_troops",0),                                ##loop as long as there is space left
(party_stack_get_troop_id,":this_troop",":cur_party",":cur_stack"),
(party_stack_get_size,":troop_count",":cur_party",":cur_stack"),        ##get the number of troops in the current stack
(party_stack_get_num_wounded,":wounded",":cur_party",":cur_stack"),    ##Need to skip wounded, or they are counted twice!
(val_sub, ":troop_count",":wounded"),                                  ##:wounded will be subtracted from the total that will be used
        (gt,":troop_count", 0),                                                ##there has to be at least 1 to continue
(try_begin),###Fighters
(is_between,":this_troop","trp_fighter","trp_tinker"),              ##trp_tinker is after last of the fighting troops
(val_min, ":troop_count",":max_troops"),                            ##Don't go over the max number
(val_sub, ":max_troops",":troop_count"),
#(party_remove_members,":cur_party",":this_troop",":troop_count"),  ##Don't remove them here
##Need to check who survives and remove casualties from the stack at the end
(store_random_in_range,":spot",1,5),                                ##Set entry points before starting mission
(set_visitors,":spot",":this_troop",":troop_count"),
(else_try),###Searchers
(eq,":this_troop","trp_scavenger"),
(party_set_slot,"p_bus",scav_start,":troop_count"),
(else_try),
(eq,":this_troop","trp_searcher"),
(party_set_slot,"p_bus",sear_start,":troop_count"),
(else_try),
(eq,":this_troop","trp_locator"),
(party_set_slot,"p_bus",loca_start,":troop_count"),
(try_end),
(try_end),
]
),

I have bolded the section that I added to manage this, but it doesn't seem to be working right.  I start with 5 fighters, and wound them all at the end of the first round.  At the start of the second round, I have 10 fighters!  If I exit out, I'm back down to 5 fighters.  Any ideas anyone?

 

kt0

Knight
There are a lot of unknowns here since you haven't posted values for things and we can't see your mission spawn/resolution code. 

The following things jump out at me:
- If scav_start and fighter_start are referring to troop values, they're probably way off in the distance and your reset code isn't working properly.
- You might be overwriting existing data in your fighters begin_try block because of the random spot (assumedly intentionally)
- I don't think you need to add 1 to your stack count; I did a quick spot check in Native and didn't find any indication that this was necessary.  If it isn't necessary, the results are technically undefined.
- There might be an issue post-fight where the party data is being handled incorrectly. 

Beyond that, I'd start throwing display_message calls in to verify what it's doing.
 

jik

Knight
kt0 said:
There are a lot of unknowns here since you haven't posted values for things and we can't see your mission spawn/resolution code. 

The following things jump out at me:
- If scav_start and fighter_start are referring to troop values, they're probably way off in the distance and your reset code isn't working properly.
- You might be overwriting existing data in your fighters begin_try block because of the random spot (assumedly intentionally)
- I don't think you need to add 1 to your stack count; I did a quick spot check in Native and didn't find any indication that this was necessary.  If it isn't necessary, the results are technically undefined.
- There might be an issue post-fight where the party data is being handled incorrectly. 

Beyond that, I'd start throwing display_message calls in to verify what it's doing.

Between scav_start and fighter_start are just the searching troop holders.  They are not factored into the problem.  The issue seems to be with troops that I spawn in the scene.  Only trp_fighter are spawned.

My issue is when I count the trp_fighter.  If there are 5, I get 5.  If there are 5 that are all wounded I get 10.  The search troops are fine, as I have a test to count how many were in "the background" at the end of the mission, and how many of them returned.  That seems to work fine, though I have not had to deal with any of them being wounded.  Do I need to remove the wounded before counting?  I could do that then add them back after.
 

kt0

Knight
My issue is when I count the trp_fighter.  If there are 5, I get 5.  If there are 5 that are all wounded I get 10.  The search troops are fine, as I have a test to count how many were in "the background" at the end of the mission, and how many of them returned.  That seems to work fine, though I have not had to deal with any of them being wounded.  Do I need to remove the wounded before counting?  I could do that then add them back after.
I can find no obvious errors in the bolded block of code.  Unless we're both missing something, I have to conclude that the problem lies elsewhere.  I'd start with throwing a display_message at the very bottom of the spawn try block to see how often it gets hit.  I'd also double check that the +1 to your stack range is necessary for the reasons I stated above.  You might check that set_visitors on the same spot with the same values doesn't double the count and that reset_visitors is being called correctly but having never done anything with those, I have no instinct for their correct usage.
 

jik

Knight
you may be right.  I have the check start at 1, but I think that's ok, since the player should be the start of the stack (0).  I can also (to make it more generic) test that and exclude placing the player troop type.

I have some screen shots on the this output text:
(gt, ":max_troops",0),                                ##loop as long as there is space left
(party_stack_get_troop_id,":this_troop",":cur_party",":cur_stack"),
(party_stack_get_size,":troop_count",":cur_party",":cur_stack"),        ##get the number of troops in the current stack
(party_stack_get_num_wounded,":wounded",":cur_party",":cur_stack"),    ##Need to skip wounded, or they are counted twice!
(val_sub, ":troop_count",":wounded"),                                  ##:wounded will be subtracted from the total that will be used
###TESTING CODES
(str_store_troop_name,s40,":this_troop"),
(assign,reg40,":troop_count"),
(assign,reg41,":wounded"),
(display_message,"@For this stack of {s40}, there are {reg40} able troops, and {reg41} wounded"),
###END OF TEST CODES
            (gt,":troop_count", 0),                                                ##there has to be at least 1 to continue

And it gave this on the first round (0 wounded):
1.jpg


And this on the second (2 wounded):
2.jpg


As you can see, it knows from the variables used that it should only spawn 3 troops (":troop_count" is 3), but it still spawns 5 + the 2 wounded (giving me 7).
Now something interesting I found.  This issue didn't repeat in the 3rd round, even though all 7 were wounded at the end of the 2nd round.  I'm guessing that I should clear the ":troop_count" at the end of each pass just to be sure...
 

jik

Knight
k0t, I don't know why I don't listen to you.  I dropped the stack increment and all is well, first round anyway...  Thanks again for your logic in site.

In case any one else will be trying to do this kind of thing, I will post my working code (need to run a few more tests) here later on.  I'm sure I'm not the only one interested in controlling what units spawn for your side.  unfortunately, I still can't get the code for add_visitors_to_current_scene, so this only works for the initial start up.  Would like to be able to use it mid scene to control your re-inforcements.  Would be cool when in battle if you wanted to, with a key command, send in your archers, this code would find them and deploy them... again, if I could get the add_visitors thing to work right....

 

TalonAquila

Sergeant Knight
M&BWBWF&S
if i understand the add_visitor operation, it will only work for scenes, not mission_types....?
i think you'll have to look at the reinforcement stages in mission_templates.
 

jik

Knight
TalonAquila said:
if i understand the add_visitor operation, it will only work for scenes, not mission_types....?
i think you'll have to look at the reinforcement stages in mission_templates.

It has to work in a mission_template as that is the only way to visit a scene.  The example where native uses it is in the melee battles.  They use it to add new opponents when there are less than 7 people on the field.  I know how to use the code, but I am missing something that gets it to work.  I thought it might be the modify_visitors_at_scene thing, but I have that.

Reinforcements are different, and handled by the engine (to my knowledge).  I was attempting to make my own call for reinforcements.  This would allow for rather large battles, since the game is not controlling the number of agents in the scene, I am.  The benefit of using the add_visitor_to operation over spawn agent, is that spawn agent doesn't spawn them with variations.  They all look identical.  If there was a way to vary (such as the face code range, or various items - I have them, but the spawned units are identical) the troops, I could still use the spawn stuff.  Sucks having clones....

If you want to see what I was doing, here's the add_visitor stuff:
##script_add_zombie  ###NOT WORKING USE script_zombie_spawner
##Similar to zombie_spawner, this uses add_visitors_to_current_scene to site, instead of spawn_agent
##Will increment the global variable $zombies_spawned to track numbers
##Input : How Many to spawn; low range entry point; high range entry point
##Output: Increments $zombies_spawned by each zombie added to the scene
####THIS SCRIPT IS NOT WORKING, CAN'T SEEM TO GET add_visitors_to_current_scene TO WORK
("add_zombie",
[
(store_script_param,":entry_start",1),
(store_script_param,":entry_end",2),
(try_begin),
(lt,":entry_end",1),            ##value not passed
(assign,":entry_start",0),      ##Use entry point 0 only.
(assign,":entry_end",0),        ##Use entry point 0 only.
(try_end),
(val_add,":entry_end",1),
(store_random_in_range,":zombie","trp_zombie","trp_survivor"),
(store_random_in_range,":spot",":entry_start",":entry_end"),
(modify_visitors_at_site,"scn_zombie_town"),
(add_visitors_to_current_scene,":spot",":zombie",1),
(val_add, "$zombies_spawned", 1),

]
),

Following the melee stuff, you don't seem to have to do much.  The info is all there, ":spot" is set to 35-45, which I have entry_points in the scene.  I use the same code pretty much for the spawn_agent, and that works.  I tried hard coding the troop ID, that didn't work.  And the number is how many.  I have added messages to show that the code executes, it does, but nothing is added/spawned/whatever. 
 

TalonAquila

Sergeant Knight
M&BWBWF&S
from what i understand, there are 2 conditions for the add_ visitors  to take place...
1: the entry_point must not be the player's entry point
2: and it must be at least 12 meters from the player

have you insured those 2 conditions are met?
 

jik

Knight
TalonAquila said:
from what i understand, there are 2 conditions for the add_ visitors  to take place...
1: the entry_point must not be the player's entry point
2: and it must be at least 12 meters from the player

have you insured those 2 conditions are met?

Where did you get the 12 meters thing?  But in this case, both are true.  I would say the closest entry point would be over 15 meters.  In game I have entry points 0 to 5 for the player and his team, and 35 to 46 for the enemy.  spawn_agent works fine for this.

Another note, I spoke too soon.  Still creates extras.  Really stumped with this.  Can't see how it would be sending in more that run through the try_ loop.  With the text output, it only sees 1 stack of fighters and 1 stack of scavengers, which don't appear in the scene. 
Cleaned up the other stuff, and so this is round 1
1-b.jpg


Round to reports:
2-b.jpg


looking at my code:
(assign,reg40,":troop_count"), is 1 in round 2.  With :troop_count being just 1, it should only add 1.  What I am thinking is that it is keeping the troops that are there, and adding one more, as in this case I had 6 troops (7 including me) in the next round.  Maybe I need to be using (reset_visitors),.  Will try that next.

 

TalonAquila

Sergeant Knight
M&BWBWF&S
that was my next suggestion, believe it or not... i've gotten some very wierd results playing with loops in module system, most of them my fault, but there are some quirky things that appear to be hard-coded.  i've also seen some very creative work-arounds that take approaches i'd never have considered.
 

foxyman

Sergeant Knight
M&BWB
So I've looked into mission_template and found this thing: add_reinforcements_to_entry.
But this doesn't specify which troop to add.
 

jik

Knight
foxyman said:
So I've looked into mission_template and found this thing: add_reinforcements_to_entry.
But this doesn't specify which troop to add.

That works with the game engine.  I would use that if I could, but alas, it has no manual control.

The key was using (reset_visitors),.  It now works, but still no go on the add_visitors...  Maybe I need to check more on the menu/dialog that calls the melee battles.
 
Top Bottom