Page 1 of 2

Making Code Graceful...

Posted: Tue Oct 04, 2011 10:12 am
by fildred13
I am making essentially a singleplayer version of territories. If at any time either team controls all of the flags, the game ends and they are victorious. If, at the end of 15 minutes, neither team controls all of the flags, then the team that controls the most wins. If there is a tie, the game enters into overtime and the first team to have more flags than his opponent at anytime wins. There are 5 flags.

Easy enough to figure out a way to script that. The challenge, for me, is getting the script to be as small as possible. I want the least number of map actions conceivable to still convey this gametype, because everything else going on in the map requires TONS of map actions.

My plan: Have Tuni's testing for each subject list around the flag during regulation time. The first tests to see if light units are at flag 1, if so test to see if dark units are there, if not test flag1 again. If dark units are there, test flag 1 for light units again, if not move on to flag 2. Test flag 2 for light units, if present test for dark, if not go back and test flag1 again. etcetcetc... That cycle continues for all the flags, and as soon as the light team is uncontested, they win. Duplicate that code and flip it so it tests dark first, and you have a seperate cycle to see if dark wins at any point.

At end of game: Test each flag for light units, and if they are there than reveal a special "point scoring" unit off map. Same for dark. Two GEOM's count the number of points for each team, send the results to a MATH action that compares, and if one team has more than the other, that team wins.

If Tie: Hide the point units with a mass unit control, and repeat end of game test again and again until one team has the advantage.


Is this truly the most cost-effective way, map action wise, to do this? I'm including below the script through regulation time to show just how inefficient this method is. End of game and Overtime don't look much better.


I'd appreciate any action-saving ideas.



Light Forces Have NW Flag? [Test Unit]
initially_active
deactivates_on_execution
0.00, 0.00
{
Team Index
0
Unit Count Greater Than
0
Activates on Success
Dark Forces Have NW Flag?
Closed Polygon Flag
true
Polygon
149.454, 65.499
142.344, 68.583
144.321, 74.624
149.272, 76.004
153.168, 71.147
Activates on Failure
Dark Forces Have NW Flag?
}

Dark Forces Have NW Flag? [Test Unit]
deactivates_on_execution
0.00, 0.00
{
Team Index
1
Unit Count Greater Than
0
Closed Polygon Flag
true
Polygon
149.454, 65.499
142.344, 68.583
144.321, 74.624
149.272, 76.004
153.168, 71.147
Activates on Success
Light Forces Have NW Flag?
Activates on Failure
Light Forces Have NE Flag?
}

Light Forces Have NE Flag? [Test Unit]
deactivates_on_execution
0.00, 0.00
{
Team Index
0
Unit Count Greater Than
0
Activates on Success
Dark Forces Have NE Flag?
Closed Polygon Flag
true
Polygon
48.079, 73.143
41.979, 72.272
39.997, 76.633
42.834, 81.192
48.372, 77.879
Activates on Failure
Light Forces Have NW Flag?
}

Dark Forces Have NE Flag? [Test Unit]
deactivates_on_execution
0.00, 0.00
{
Team Index
1
Unit Count Greater Than
0
Activates on Success
Light Forces Have NW Flag?
Closed Polygon Flag
true
Polygon
48.079, 73.143
41.979, 72.272
39.997, 76.633
42.834, 81.192
48.372, 77.879
Activates on Failure
Light Forces Have SE Flag?
}

Light Forces Have SE Flag? [Test Unit]
deactivates_on_execution
0.00, 0.00
{
Team Index
0
Unit Count Greater Than
0
Activates on Success
Dark Forces Have SE Flag?
Closed Polygon Flag
true
Polygon
56.342, 143.594
52.452, 137.741
46.963, 143.219
52.688, 146.838
Activates on Failure
Light Forces Have NW Flag?
}

Dark Forces Have SE Flag? [Test Unit]
deactivates_on_execution
0.00, 0.00
{
Team Index
1
Unit Count Greater Than
0
Activates on Success
Light Forces Have NW Flag?
Closed Polygon Flag
true
Polygon
56.342, 143.594
52.452, 137.741
46.963, 143.219
52.688, 146.838
Activates on Failure
Light Forces Have SW Flag?
}

Light Forces Have SW Flag? [Test Unit]
deactivates_on_execution
0.00, 0.00
{
Team Index
0
Unit Count Greater Than
0
Activates on Success
Dark Forces Have SW Flag?
Closed Polygon Flag
true
Polygon
153.450, 134.278
147.211, 133.913
146.493, 141.061
151.106, 140.764
153.663, 137.510
Activates on Failure
Light Forces Have NW Flag?
}

Dark Forces Have SW Flag? [Test Unit]
deactivates_on_execution
0.00, 0.00
{
Team Index
1
Unit Count Greater Than
0
Activates on Success
Light Forces Have NW Flag?
Closed Polygon Flag
true
Polygon
153.450, 134.278
147.211, 133.913
146.493, 141.061
151.106, 140.764
153.663, 137.510
Activates on Failure
Light Forces Have Center Flag?
}

Light Forces Have Center Flag? [Test Unit]
deactivates_on_execution
0.00, 0.00
{
Team Index
0
Unit Count Greater Than
0
Activates on Success
Dark Forces Have Center Flag?
Closed Polygon Flag
true
Polygon
99.766, 107.114
95.278, 105.616
91.290, 107.610
91.432, 112.004
94.659, 115.524
98.284, 114.219
100.401, 110.553
Activates on Failure
Light Forces Have NW Flag?
}

Dark Forces Have Center Flag? [Test Unit]
deactivates_on_execution
0.00, 0.00
{
Team Index
1
Unit Count Greater Than
0
Activates on Success
Light Forces Have NW Flag?
Closed Polygon Flag
true
Polygon
99.766, 107.114
95.278, 105.616
91.290, 107.610
91.432, 112.004
94.659, 115.524
98.284, 114.219
100.401, 110.553
Activates on Failure
Light Victory
}

{}-----------------------------------------------------------------

Light Forces Dead? [Test Unit]
deactivates_on_successful_execution
0.00, 0.00
{
Link
LIGHT FORCES SUBJ
PLAYER FORCES SUBJ
Unit Count Equal To
0
Activates on Success
Dark Victory
}

Dark Victory [Endgame Condition]
deactivates_on_trigger
0.00, 0.00
{
Dark Victory Flag
}

Dark Forces Have NW Flag? [Test Unit]
deactivates_on_execution
0.00, 0.00
{
Team Index
1
Unit Count Greater Than
0
Activates on Success
Light Forces Have NW Flag?
Closed Polygon Flag
true
Polygon
149.454, 65.499
142.344, 68.583
144.321, 74.624
149.272, 76.004
153.168, 71.147
Activates on Failure
Light Forces Have NW Flag?
}

Light Forces Have NW Flag? [Test Unit]
deactivates_on_execution
0.00, 0.00
{
Team Index
0
Unit Count Greater Than
0
Closed Polygon Flag
true
Polygon
149.454, 65.499
142.344, 68.583
144.321, 74.624
149.272, 76.004
153.168, 71.147
Activates on Success
Dark Forces Have NW Flag?
Activates on Failure
Dark Forces Have NE Flag?
}

Dark Forces Have NE Flag? [Test Unit]
deactivates_on_execution
0.00, 0.00
{
Team Index
1
Unit Count Greater Than
0
Activates on Success
Light Forces Have NE Flag?
Closed Polygon Flag
true
Polygon
48.079, 73.143
41.979, 72.272
39.997, 76.633
42.834, 81.192
48.372, 77.879
Activates on Failure
Dark Forces Have NW Flag?
}

Light Forces Have NE Flag? [Test Unit]
deactivates_on_execution
0.00, 0.00
{
Team Index
0
Unit Count Greater Than
0
Activates on Success
Dark Forces Have NW Flag?
Closed Polygon Flag
true
Polygon
48.079, 73.143
41.979, 72.272
39.997, 76.633
42.834, 81.192
48.372, 77.879
Activates on Failure
Dark Forces Have SE Flag?
}

Dark Forces Have SE Flag? [Test Unit]
deactivates_on_execution
0.00, 0.00
{
Team Index
1
Unit Count Greater Than
0
Activates on Success
Light Forces Have SE Flag?
Closed Polygon Flag
true
Polygon
56.342, 143.594
52.452, 137.741
46.963, 143.219
52.688, 146.838
Activates on Failure
Dark Forces Have NW Flag?
}

Light Forces Have SE Flag? [Test Unit]
deactivates_on_execution
0.00, 0.00
{
Team Index
0
Unit Count Greater Than
0
Activates on Success
Dark Forces Have NW Flag?
Closed Polygon Flag
true
Polygon
56.342, 143.594
52.452, 137.741
46.963, 143.219
52.688, 146.838
Activates on Failure
Dark Forces Have SW Flag?
}

Dark Forces Have SW Flag? [Test Unit]
deactivates_on_execution
0.00, 0.00
{
Team Index
1
Unit Count Greater Than
0
Activates on Success
Light Forces Have SW Flag?
Closed Polygon Flag
true
Polygon
153.450, 134.278
147.211, 133.913
146.493, 141.061
151.106, 140.764
153.663, 137.510
Activates on Failure
Dark Forces Have NW Flag?
}

Light Forces Have SW Flag? [Test Unit]
deactivates_on_execution
0.00, 0.00
{
Team Index
0
Unit Count Greater Than
0
Activates on Success
Dark Forces Have NW Flag?
Closed Polygon Flag
true
Polygon
153.450, 134.278
147.211, 133.913
146.493, 141.061
151.106, 140.764
153.663, 137.510
Activates on Failure
Dark Forces Have Center Flag?
}

Dark Forces Have Center Flag? [Test Unit]
deactivates_on_execution
0.00, 0.00
{
Team Index
1
Unit Count Greater Than
0
Activates on Success
Light Forces Have Center Flag?
Closed Polygon Flag
true
Polygon
99.766, 107.114
95.278, 105.616
91.290, 107.610
91.432, 112.004
94.659, 115.524
98.284, 114.219
100.401, 110.553
Activates on Failure
Dark Forces Have NW Flag?
}

Light Forces Have Center Flag? [Test Unit]
deactivates_on_execution
0.00, 0.00
{
Team Index
0
Unit Count Greater Than
0
Activates on Success
Dark Forces Have NW Flag?
Closed Polygon Flag
true
Polygon
99.766, 107.114
95.278, 105.616
91.290, 107.610
91.432, 112.004
94.659, 115.524
98.284, 114.219
100.401, 110.553
Activates on Failure
Dark Victory
}

{}-----------------------------------------------------------------

That's 20 actions just for regulation time, for those keeping score at home.

Re: Making Code Graceful...

Posted: Tue Oct 04, 2011 4:21 pm
by A-Red
That's not bad. You're trying to do something fairly complex, and 20 map actions isn't a lot. You can have close to 700 on a single map before the game starts to mess up. Most of the single-player maps I've scripted have between 200 and 400.

I've been working through several alternative options, and I can't come up with anything equally reliable that uses fewer actions. With Friends Like These is a single-player Terries map, and it's the most complicated script in the Myth II campaign. If you want, you could take a look to see how they did it, but it's a hard script to read. In fact, I think you've got it down to fewer map actions than Bungie themselves used--they didn't have MATH when they made the game, so they probably had to figure out something even less direct.

Re: Making Code Graceful...

Posted: Tue Oct 04, 2011 4:39 pm
by Pyro
The actual limit to map actions is 1024. There was some issue that got fixed in 1.7.2 where you would run into issues before hitting the MA limit. "Fixed map action code that could result in multiple map actions having the same identifier, leading to all sorts of problems." So you should be able to use all 1024 actions now.

Re: Making Code Graceful...

Posted: Tue Oct 04, 2011 6:10 pm
by fildred13
Hrm, well I trust you guys, I guess I'll keep it the way I planned. Thanks for taking a look at it.

Good to know I can use all 1024, I'll be coming close with this mesh I think.

Re: Making Code Graceful...

Posted: Tue Oct 04, 2011 10:47 pm
by Graydon
I mentioned this in the other thread.

The limit is not tied solely to number of map actions, and in fact the Map Actions limit is not the one you should be keeping an eye on, you'll be _very_ hard pressed to ever reach it before running into problems. The real limit that will halt your map is the Map Action Params Size. I'm not entirely certain what makes up all the 'size' of any one param, but I did discover at one point that any text you add to the action (true/false flags, number values, the Action Name) adds +1 per character to your param size. Naturally this means that more complex actions with multiple required fields like a GEOM or PLAT are going to take up far more params than something simple like a GENE or ATTA. With this in mind, it's probably possible to get 1024 ATTA actions and still keep your param count under its limit, but generally speaking, a mix of simplistic actions and complex actions as many maps have usually results in your param count maxing out around 700-800 actions.

By being extremely conservative in your naming schemes, and not adding textual flagging to things that default to that flag already (for example a true/false test that always defaults as true, no need to type true, that's just wasted 4 params) you can have many actions and still be under your limit. On one map that's been in the works a few years now I think I'm at around 930 MAs and still have about 8k params clearance. Before I purged and cleaned it I was maxing my params at 800 actions.

Re: Making Code Graceful...

Posted: Tue Oct 04, 2011 10:54 pm
by Graydon
I'm just wondering if there's any way to remove the second string of tests for Dark Victory..... you've already done the tests. Can't you just have a dark victory flag activated initially (or say a minute in or as soon as light caps their first flag, im not sure if light starts on a flag or not?) with 5 inhibitions linked to the Light Units at flag X?

Thus meaning dark victory will succeed if all 5 'light units at flag X?' tests have failed. That way you don't need to test for a success for dark... just use the failure of the light tests?

Re: Making Code Graceful...

Posted: Tue Oct 04, 2011 11:07 pm
by fildred13
@Graydon: Param size is something I had never even heard of before. Something tells me I am NOT conscious of protecting my map from that limit. I'll keep an eye on it, thanks for the heads.

As for the inhibitions... I like the idea, but I'm not sure I understand...The tests only make it to the end if light is at all 5 flags AND dark is NOT at those flags. I could use the inhibitions, but just because light ISN'T there doesn't mean dark IS there. Both teams could, say, be ignoring the SW flag, meaning no one has it meaning no one can win yet?

Maybe I don't understand clearly?

Re: Making Code Graceful...

Posted: Wed Oct 05, 2011 1:09 am
by Graydon
Ack no, you're absolutely correct. This is my downfall of trying to read script in text format on a forum while at work with no way to verify the BS I speculate over then type :D Which means, as A-Red stated, you've probably already found the most efficient method.

Re: Making Code Graceful...

Posted: Wed Oct 05, 2011 3:31 pm
by A-Red
Yeah. I was about to suggest the same thing yesterday before I realized it wouldn't work. If you want to require the player to have units near at least one flag at all times, then you can do away with the set of tests for Dark. If you want to give the player more freedom than that, you have to use a script like fildred is using.

Re: Making Code Graceful...

Posted: Tue Feb 07, 2012 6:29 pm
by fildred13
Alrighty so after much experimentation and testing I have the victory conditions on the verge of perfect. I come for help because the MATH and GEOM functions are giving me fits.

The Background (for those who don't remember every detail about this thread, and who may have a better solution):
I am making a 5-flag player vs AI Territories-like map. The issue comes from Victory Conditions. There are two sets: Normal Time, and Sudden Death. Normal Time is working fine: if at any time 1 team controls ALL the flags UNCONTESTEDLY, they win. It works like a charm, it's great. Now when sudden death rolls along I want the new victory condition to be that if one team holds MORE flags than the other, they win. It is in the code for this part here that shit gets sticky.

The Sticky Shit:
I go through each flag and for each flag that has a guy near it, I reveal a hidden "point" (monster) at the edge of the screen. If dark is there, just dark, if light AND dark are there, then both points go up, etc. THEN, after I have done that for every flag, I use a GEOM to count the points for the LIGHT team and put it as the lint and rint of two upcoming MATH functions. Then I use another GEOM to count the points for DARK and put the result in the rint and lint of the upcoming MATH functions. Then the first MATH function sees if light's points (lint) is greater than darks points (rint). If so, they win, otherwise another MATH checks to see if dark has more than light, and if so they win, otherwise hide all the points and do the whole process again.

The Error:
I debugged. Basically, the geom detects the right number of points that have been revealed, but it doesn't put them into the math function properly. The lint and rint is ALWAYS 0.

The Error Log:
2012-02-07 18:12:42 ### MA [geom] LF Points?: found 1 monsters
2012-02-07 18:12:42 ### MA [geom] LF Points?: testing monsters against entire map
2012-02-07 18:12:42 ### MA [geom] LF Points?: 1 monsters inside geometry (added to lint)
2012-02-07 18:12:42 ### MA [geom] LF Points?: 1 monsters outside geometry ignored
2012-02-07 18:12:42 ### MA [geom] LF Points?: 0 monsters points inside geometry ignored
2012-02-07 18:12:42 ### MA [geom] LF Points?: 1 monsters points outside geometry ignored
2012-02-07 18:12:42 ### MA [geom] LF Points?: 1 monsters inside geometry (added to rint)
2012-02-07 18:12:42 ### MA [geom] LF Points?: 1 monsters outside geometry ignored
2012-02-07 18:12:42 ### MA [geom] LF Points?: 0 monsters points inside geometry ignored
2012-02-07 18:12:42 ### MA [geom] LF Points?: 1 monsters points outside geometry ignored
2012-02-07 18:12:42 ### MA [geom] LF Points?: succeeded
2012-02-07 18:12:42 ### MA [geom] LF Points?: deactivated
2012-02-07 18:12:42 ### MA [geom] DF Points?: found 3 monsters
2012-02-07 18:12:42 ### MA [geom] DF Points?: testing monsters against entire map
2012-02-07 18:12:42 ### MA [geom] DF Points?: 3 monsters inside geometry (added to rint)
2012-02-07 18:12:42 ### MA [geom] DF Points?: 3 monsters outside geometry ignored
2012-02-07 18:12:42 ### MA [geom] DF Points?: 0 monsters points inside geometry ignored
2012-02-07 18:12:42 ### MA [geom] DF Points?: 3 monsters points outside geometry ignored
2012-02-07 18:12:42 ### MA [geom] DF Points?: 3 monsters inside geometry (added to lint)
2012-02-07 18:12:42 ### MA [geom] DF Points?: 3 monsters outside geometry ignored
2012-02-07 18:12:42 ### MA [geom] DF Points?: 0 monsters points inside geometry ignored
2012-02-07 18:12:42 ### MA [geom] DF Points?: 3 monsters points outside geometry ignored
2012-02-07 18:12:42 ### MA [geom] DF Points?: succeeded
2012-02-07 18:12:42 ### MA [geom] DF Points?: deactivated
2012-02-07 18:12:42 ### MA [math] Light Wins?: 0.000000 > 0.000000 = 0.000000
2012-02-07 18:12:42 ### MA [math] Light Wins?: failed
2012-02-07 18:12:42 ### MA [math] Light Wins?: deactivated
2012-02-07 18:12:42 ### MA [math] Dark Wins?: 0.000000 > 0.000000 = 0.000000
2012-02-07 18:12:42 ### MA [math] Dark Wins?: failed
2012-02-07 18:12:42 ### MA [math] Dark Wins?: deactivated
2012-02-07 18:12:42 ### MA [acli] Hide All Points: Activating all actions


The Relevant Code:
LF Points? [Geometry Filter]
deactivates_on_execution
0.00, 0.00
{
Monsters (subj)
10725 (thrall)
10724 (thrall)
10723 (thrall)
10722 (thrall)
10721 (thrall)
Entire Map
true
Tested items Inside Field Name
lint
rint
Results Action Identifier
Light Wins?
Dark Wins?
Activates on Execution
DF Points?
}

DF Points? [Geometry Filter]
deactivates_on_execution
0.00, 0.00
{
Monsters (subj)
10726 (thrall)
10727 (thrall)
10728 (thrall)
10729 (thrall)
10730 (thrall)
Entire Map
true
Tested items Inside Field Name
rint
lint
Results Action Identifier
Light Wins?
Dark Wins?
Activates on Execution
Light Wins?
}

Light Wins? [Mathematics]
deactivates_on_execution
0.00, 0.00
{
Left Integer
Right Integer
Activates on Success
Light Victory
Activates on Failure
Dark Wins?
Greater Than
}

Dark Wins? [Mathematics]
deactivates_on_execution
0.00, 0.00
{
Left Integer
Right Integer
Activates on Success
Dark Victory
Activates on Failure
Hide All Points
Greater Than
}

Hide All Points [Action List]



So what the hell am I doing wrong? Can a GEOM not put integers into a MATH? How do I use it then? I know this is doable, I jsut cannot for the life of me figure out where my (probably stupid) error is.

Thanks,
~fildred13

Re: Making Code Graceful...

Posted: Tue Feb 07, 2012 7:30 pm
by Graydon
Tried replacing the Tested Items Inside Field Name with Tested Items Inside Location Field Name yet?

Re: Making Code Graceful...

Posted: Tue Feb 07, 2012 8:31 pm
by fildred13
Just did, no effect. Makes sense though, right? I'm not trying to grab a location, I'm trying to grab the count result of a GEOM and use that as an INTEGER.

I see some other function in MATH like compare field name, decimal number, integer, action identifier. I don't really know what they do, though. Are any of them applicable?

Re: Making Code Graceful...

Posted: Tue Feb 07, 2012 9:59 pm
by Pyro
GEOMs don't output numbers. The GEOMs you made were outputting monster_identifier type parameters into the MATH actions. Doing what Graydon said would only output a waypoint which isn't what you want either. Use MATH instead of GEOMs for the points.

Instead of revealing a hidden monster, add a number to a Math action. Try something like the following. The Light Count and Dark Count actions are none/empty actions to place your numbers for the light and dark teams. I underlined the map actions to tell the parameters and their elements apart a lot easier.

MATH.Reset Light
Left Integer
0
Destination Action Identifier
<Light Count>
Destination Field Name
lint
Activates on Execution
MATH.Reset Dark

MATH.Reset Dark
Left Integer
0
Destination Action Identifier
<Dark Count>
Destination Field Name
lint
Activates on Execution
GEOM.Flag 1?

MATH.Add to Light
Left Action Identifier
<Light Count>
Left Field Name
lint
Right Integer
1
Add
Destination Action Identifier
<Light Count>
Destination Field Name
lint

MATH.Add to Dark
Left Action Identifier
<Dark Count>
Left Field Name
lint
Right Integer
1
Add
Destination Action Identifier
<Dark Count>
Destination Field Name
lint

<Light Count>

<Dark Count>

MATH.Add Counts
Left Action Identifier
<Light Count>
Left Field Name
lint
Right Action Identifier
<Dark Count>
Right Field Name
lint
Add
Destination Action Identifier
MATH.All Flags Taken?
Destination Field Name
lint
Activates on Execution
MATH.All Flags Taken?

MATH.All Flags Taken?
Right Integer
5
Equal
Activates on Success
MATH.Who Wins?
Activates on Failure
MATH.Reset Light

MATH.Who Wins?
Left Action Identifier
<Light Count>
Left Field Name
lint
Right Action Identifier
<Dark Count>
Right Field Name
lint
Greater Than
Activates on Success
ENDG.Light Victory
Activates on Failure
ENDG.Dark Victory


Depending on what method you go about checking each flag's status you might need to modify what I showed you above. One way would be to have "MATH.Reset Light" initially active. It resets the light count then triggers the resetting of the dark count. After that it activates the first of 5 GEOMs to test which teams are on each flag. Make them trigger in a series so that after GEOM 1, it triggers 2, then 3... etc. After the 5th one, trigger the "MATH.Add Counts" action. The rest is up there. Let me know how it goes. (I said GEOMs for the flag tests, but it doesn't mean it has to be 5 GEOMs. Could be whatever you had to test who was on the flags.)

Re: Making Code Graceful...

Posted: Tue Feb 07, 2012 10:54 pm
by fildred13
I had the exact right idea, just wasn't sure how to implement. That looks great, thanks a ton Pyro. I'm sure I'll get it working tomorrow now that I understand how the MATH function works a little better. I hope I don't eat those words :lol: !

Thanks again,
~fildred13

Re: Making Code Graceful...

Posted: Tue Feb 07, 2012 11:30 pm
by Pyro
This other thread explains a bit about the Math MA, maybe it can help. Though with my above post, that might be enough to get you started. If you enable the map action debugger (ctrl f12/f5) or add debug flags to Math, it tells you which values it used and their results. This can be useful if you run into problems.