On some advice I received here, I am trying to streamline my movement system for a dogfighting map I'm making. I would like some advice on how to use a list.
Here is the situation:
I have ships, missiles and lasers stored in a unit array. Their position in the array is stored in their custom value. Arrays of other interesting variables relating to the units are also stored that way, so the ship whose custom value is 5, for example, is moving at: MoveSpeed[5], toward MovePoint[5], with LaserStrength[5].
Ship movement is caused by a "For every Integer A 1 to 100 loop" that counts through the whole list moving each ship, missile and laser in turn. This is inefficient, though, as at any time there is likely only 20 units in that array. I was told to make the loop from 1 to "the number of units in the array" so the computer doesn't have to loop 100 times every .02 seconds when it really only has to loop 20 times.
Here's my problem. The units die at different times, so the array will rarely look like this:
1- Xwing Fighter
2- Tie Fighter
3- Laser
4- Laser
5- Concussion Missile
6- no unit
7- no unit
etc.
Usually it will look like this:
1- Xwing
2- Tie Fighter
3- no unit
4- no unit
5- Concussion Missile
6- no unit
7- Ywing
This means that the total number of units I have is 4, but I can't just loop from 1 to 4 because the concussion missile in slot 5 and Ywing in slot 7 will never move.
Here are two solutions I thought of, please let me know if one is best or if there is one I haven't thought of. I know how to use Custom Scripts to remove leaks and such, and to move units, but I don't know JASS proper.
Solution 1: Keep track of the total number of units in the list. Then, when a unit dies, if it is not the highest number, copy the highest numbered unit into the new slot. In other words, when unit 3 dies, copy unit 5 into slot three. This involves storing about 12 variables (e.g., set LaserStrength[3] = LaserStrength[5]) every time a unit dies.
Solution 2: Keep all the units in a unit group. So FliersUnitGroup would equal: Xwing, Tie, laser, laser, and concussion missile. Then, instead of looping from 1-100, I would pick every unit in FliersUnitGroup and move it. This unitgroup would vary in size from about 10 to 80.
Thank you.
Darwin
Here is the situation:
I have ships, missiles and lasers stored in a unit array. Their position in the array is stored in their custom value. Arrays of other interesting variables relating to the units are also stored that way, so the ship whose custom value is 5, for example, is moving at: MoveSpeed[5], toward MovePoint[5], with LaserStrength[5].
Ship movement is caused by a "For every Integer A 1 to 100 loop" that counts through the whole list moving each ship, missile and laser in turn. This is inefficient, though, as at any time there is likely only 20 units in that array. I was told to make the loop from 1 to "the number of units in the array" so the computer doesn't have to loop 100 times every .02 seconds when it really only has to loop 20 times.
Here's my problem. The units die at different times, so the array will rarely look like this:
1- Xwing Fighter
2- Tie Fighter
3- Laser
4- Laser
5- Concussion Missile
6- no unit
7- no unit
etc.
Usually it will look like this:
1- Xwing
2- Tie Fighter
3- no unit
4- no unit
5- Concussion Missile
6- no unit
7- Ywing
This means that the total number of units I have is 4, but I can't just loop from 1 to 4 because the concussion missile in slot 5 and Ywing in slot 7 will never move.
Here are two solutions I thought of, please let me know if one is best or if there is one I haven't thought of. I know how to use Custom Scripts to remove leaks and such, and to move units, but I don't know JASS proper.
Solution 1: Keep track of the total number of units in the list. Then, when a unit dies, if it is not the highest number, copy the highest numbered unit into the new slot. In other words, when unit 3 dies, copy unit 5 into slot three. This involves storing about 12 variables (e.g., set LaserStrength[3] = LaserStrength[5]) every time a unit dies.
Solution 2: Keep all the units in a unit group. So FliersUnitGroup would equal: Xwing, Tie, laser, laser, and concussion missile. Then, instead of looping from 1-100, I would pick every unit in FliersUnitGroup and move it. This unitgroup would vary in size from about 10 to 80.
Thank you.
Darwin