(moved here from galaxy scripting, my fault sorry)
OK here is version 1.0 of this trigger combat control to keep units from shooting through walls... but I am happy enough with the triggers that I am posting them here to get help in squishing a bug i can't figure out. my problem is I need to be able to detect the difference between an attack move command by the player (attack targeting the ground) and the natural "unit is attacking but its target died, so its targeting a null unit" bit when something kills something else. this is causing the "attack move" code to run and making the unit run to where the enemy died at... albeit attack moving there... but still as a fire fight rolls on units get split off from the group making a lot more micro managing of them than necessary.
the code is split between several triggers.
when the region is first initialized (when the player sends units into this type of building for the first time) I setup an array of the regions designating valid fire zones. these regions are laid down in the terrain editor
The primary trigger controlling the combat has a pair of nested loops that looks at each unit you control within the sub region (the building) and for each unit it searches each room region to see if that unit is in that region. if it is it looks for the closest enemy within that room region. and the closest valid enemy from any of the room regions the unit is in (multiple room regions can overlap) is the one that the unit is told to attack.
Next I have a trigger to try and trap "attack moves" because i need to control the combat... so i change it into a regular move command, but enable the target scanning from the previous trigger, so if the unit comes across an enemy, it will attack. (unfortunately this code is also triggered when a unit kills an enemy, which i need to figure out how to prevent)
Next I have a trigger coded to remove the "attack move" status so the unit can switch back into a normal move whenever the player wants.
The second to last trigger traps when the unit "attacks" a target outside of a valid fire zone and issues a "stop" command. in practice this makes the unit stand there when you tell it to attack something that it can't immediately shoot... ideally I will have the unit move to a position where is could attack the unit you told it to... but I'm not there yet.
The final trigger is similar the the previous one but it traps when the unit "acquires" a target outside of a valid fire zone... this is more of a legacy bit from before I trapped the attack move command... but I have it in just in case.
I hope this helps other people out I have worked on this for over a week to get it to where it is. and I also appreciate any help from the more experienced code writers / map makers, the more i figure out in this editor the more I realize I need to figure out.
here is the map file also in case you guys want to fiddle with it. oh, if your forces that start in the mall get wiped out, there is a larger force waiting outside, you can run them over to the building (the pink box, until I make a model to import) and use the ability on the building to make nearby units enter the building. the grass patch on the south side of the building is the "exit" if you run units into it, they will leave back to the overview map. the stairs work as well (they are just labeled up and down with terrain texture painting), but the second floor is not setup for combat so other than running around, there is nothing to do up there right now.
(moved here from galaxy scripting, my fault sorry)
OK here is version 1.0 of this trigger combat control to keep units from shooting through walls... but I am happy enough with the triggers that I am posting them here to get help in squishing a bug i can't figure out. my problem is I need to be able to detect the difference between an attack move command by the player (attack targeting the ground) and the natural "unit is attacking but its target died, so its targeting a null unit" bit when something kills something else. this is causing the "attack move" code to run and making the unit run to where the enemy died at... albeit attack moving there... but still as a fire fight rolls on units get split off from the group making a lot more micro managing of them than necessary.
the code is split between several triggers.
when the region is first initialized (when the player sends units into this type of building for the first time) I setup an array of the regions designating valid fire zones. these regions are laid down in the terrain editor
The primary trigger controlling the combat has a pair of nested loops that looks at each unit you control within the sub region (the building) and for each unit it searches each room region to see if that unit is in that region. if it is it looks for the closest enemy within that room region. and the closest valid enemy from any of the room regions the unit is in (multiple room regions can overlap) is the one that the unit is told to attack.
Next I have a trigger to try and trap "attack moves" because i need to control the combat... so i change it into a regular move command, but enable the target scanning from the previous trigger, so if the unit comes across an enemy, it will attack. (unfortunately this code is also triggered when a unit kills an enemy, which i need to figure out how to prevent)
Next I have a trigger coded to remove the "attack move" status so the unit can switch back into a normal move whenever the player wants.
The second to last trigger traps when the unit "attacks" a target outside of a valid fire zone and issues a "stop" command. in practice this makes the unit stand there when you tell it to attack something that it can't immediately shoot... ideally I will have the unit move to a position where is could attack the unit you told it to... but I'm not there yet.
The final trigger is similar the the previous one but it traps when the unit "acquires" a target outside of a valid fire zone... this is more of a legacy bit from before I trapped the attack move command... but I have it in just in case.
I hope this helps other people out I have worked on this for over a week to get it to where it is. and I also appreciate any help from the more experienced code writers / map makers, the more i figure out in this editor the more I realize I need to figure out.
here is the map file also in case you guys want to fiddle with it. oh, if your forces that start in the mall get wiped out, there is a larger force waiting outside, you can run them over to the building (the pink box, until I make a model to import) and use the ability on the building to make nearby units enter the building. the grass patch on the south side of the building is the "exit" if you run units into it, they will leave back to the overview map. the stairs work as well (they are just labeled up and down with terrain texture painting), but the second floor is not setup for combat so other than running around, there is nothing to do up there right now.