Morale

Level 3
Joined
Nov 12, 2006
Messages
35
Im designing a war based game and I want to have mana as morale for most units (Mages use it as mana). Here are some ground rules on the system;

1. Morale is stagnant for most troops when idle.
2. Morale is increased when an enemy unit within a very small radius of a unit dies.
3. Morale decreases when a friendly unit within a small radius of a unit dies.
4. Leaders give off auras to increase morale over time.
5. If morale = 0, the unit will run from the nearest enemy unit until 1000 units away. If no enemies are within 1000 units, they get 1 mana and rally.

I need help implementing this system. If you are willing to help me out, tell me.
 
Level 13
Joined
Mar 16, 2008
Messages
943
Erm ok, I think that is VERY easy :wink:
Make some Triggers:

  • E: A unit dies
  • C: Triggering Unit is not a mage (Unit Type)
  • A: set temppoint = Position of triggering unit
    • set tempgroup = Units in range of 200 of temppoint matching is an ally of triggering unit
    • Pick all units in tempgroup and do
      • set mana of picked unit to mana of picked unit - 3
    • call RemoveLocation(udg_temppoint)
    • call DestroyGroup(tempgroup)
This one will decrease the moral for sure, change the condition in the group to enemys of triggering unit and the mana amount to +3 (or to your value).

Stagnant is no problem, Manareg of 0, and no possibilitys to increase it.

The only way to increase it should be a leader, so give them a brilliance aura.

The next triggers are two, since I don't think it's possible in one:

  • Morale Add Unit
  • E:A unit enters playable map
  • A: Add to <Morale Zero> the event (Mana of triggering unit becomes equal to 0)
  • Morale Zero
  • E:None! You add it in Morale Add Unit
  • A: set temppointmana = position of triggering unit
    • set tempgroup = units in range of triggering unit matching is enemy
    • pick all units in tempgroup and do
      • if distance between triggering unit and picked unit < tempdistance
        • set tempdistance = distance between triggering unit and picked unit
        • set temppointenemy = position of picked unit
        • set tempangle = Angle between temppointmana and temppointenemy
        • call RemoveLocation(temppointenemy)
      • else
    • if tempdistance > 0 then
      • set temppointtarget = temppointenemy offset by 1000 towards tempangle
      • Unit - Order triggering unit to move to temppointtarget
    • else
      • set mana of picked unit to 1
    • call RemoveLocation(udg_temppointmana)
    • call RemoveLocation(udg_temppointtarget)
    • call DestroyGroup(udg_tempgroup)
For sure the whole stuff is freehand, but I think you can understand how to do it :)

Greets Justify

EDIT: Omg Jass section, I'm blind, do you asked for a Jass code?
Crappy GUI^^
 
Last edited:
Level 3
Joined
Nov 12, 2006
Messages
35
I was expecting JASS, but Ill try this out and see if it works anyways. I mean no need to bring out JASS where it isnt needed right? Thanks so much for the help.
 
Level 3
Joined
Nov 12, 2006
Messages
35
Im having trouble with the first trigger you provided. The 4th line "set tempgroup = Units in range of 200 of temppoint matching is an ally of triggering unit"

I can get "Set tempgroup = (Units within 200.00 of temppoint matching (((Triggering unit) belongs to an ally of (Owner of (Triggering unit))) Equal to True))" but im pretty sure that will yield different results than what you posted.
 
Level 3
Joined
Nov 12, 2006
Messages
35
Im having trouble with this area:
"if distance between triggering unit and picked unit < tempdistance"

It requires tempdistance but tempdistance isnt defined until after it activates? Wouldnt that cause problems? Also what should I set the variable tempdistance to? I set it to an integer but the Real Comparison required to determine distances wont accept integer variables for its final part.
 
Level 3
Joined
Nov 12, 2006
Messages
35
WC Editor wont let me enable the first two triggers because of my final line;

Enemy Dies
Events
Unit - A unit Dies
Conditions
Actions
Set temppoint = (Position of (Triggering unit))
Set tempgroup = (Units within 200.00 of temppoint matching (((Picked unit) belongs to an enemy of (Owner of (Triggering unit))) Equal to True))
Unit Group - Pick every unit in tempgroup and do (Unit - Set mana of (Triggering unit) to (0.00 + 1.00))
Custom script: call RemoveLocation(udg_temppoint)
Custom script: call DestroyGround(tempgroup)
 
Level 13
Joined
Mar 16, 2008
Messages
943
Write udg_tempgroup like you did for udg_temppoint :)
And it's DestroyGroup not DestroyGround :)
Btw this will set the mana off all enemys around a dying unit to 1!!!
Or no, it will not, there are some other bugs in:

Picked Unit is the unit in a pick loop, for a matching condition you need matching unit.
Try it like this:

  • Enemy Dies
  • Events
  • Unit - A unit Dies
  • Conditions
  • Actions
  • Set temppoint = (Position of (Triggering unit))
  • Set tempgroup = (Units within 200.00 of temppoint matching (((Machting unit) belongs to an enemy of (Owner of (Triggering unit))) Equal to True))
  • Unit Group - Pick every unit in tempgroup and do (Unit - Set mana of (Picked unit) to ((Mana of (Picked unit)) + 1.00))
  • Custom script: call RemoveLocation(udg_temppoint)
  • Custom script: call DestroyGroup(udg_tempgroup)
 
Level 3
Joined
Nov 12, 2006
Messages
35
So, I tried out the system and it seems to work, but it has a flaw. The enemies that run away from having morale = 0 turn around quickly to attack again. I need to add to the trigger that the units with morale = 0 can not attack until they get mana again. How would I add that?
 
Level 3
Joined
Nov 12, 2006
Messages
35
wouldnt your suggestion only stop them from attacking, not targeting? Thus they would still turn around to attack before running 1000 units away, they couldnt actually attack, but they wouldnt complete their run.
 
Level 13
Joined
Mar 16, 2008
Messages
943
I havn't tested the whole system but:
A unit dies and an ally near him is attacking a unit.
His morale gets 0, now the trigger morale zero should trigger, but there is a problems I forgot and a bug, sry, and I also think now you mustn't use a stop attack trigger (if Morale Zero works now)

1)You need a trigger that adds all units on map init (or at 0.01 think thats better) to the trigger, just a pickloop with the same thing then 'Morale Add Unit' (Picked unit ;))

2)I made a mistake that breaks the whole system

  • if distance between triggering unit and picked unit < tempdistance
Should be
  • if distance between triggering unit and picked unit [B]>[/B] tempdistance
The distance has to be bigger then the last one :ugly:
 
Level 13
Joined
Mar 16, 2008
Messages
943
I havn't tested the whole system but:
A unit dies and an ally near him is attacking a unit.
His morale gets 0, now the trigger morale zero should trigger, but there is a problems I forgot and a bug, sry.

1)You need a trigger that adds all units on map init (or at 0.01 think thats better) to the trigger, just a pickloop with the same thing then 'Morale Add Unit' (Picked unit ;))

2)I made a mistake that breaks the whole system

  • if distance between triggering unit and picked unit < tempdistance
Should be
  • if distance between triggering unit and picked unit > tempdistancetempdistance
The distance has to be bigger then the last one :ugly:
 
Level 3
Joined
Nov 12, 2006
Messages
35
"1)You need a trigger that adds all units on map init (or at 0.01 think thats better) to the trigger, just a pickloop with the same thing then 'Morale Add Unit' (Picked unit ;))"

Could you explain how I would do that in a little detail?

Thanks again for all the help. Ill be sure to mention you in the map credits.
 
Level 13
Joined
Mar 16, 2008
Messages
943
  • E: Elapsed game time 0.1
  • A: set tempgroup = Units in playable map
    • Pick all units in tempgroup and do
      • Add to <Morale Zero> the event (Mana of picked unit becomes equal to 0)
    • call DestroyGroup(tempgroup)
You need something like this if there are units placed on the map (on startup, so you placed them in the editor and they'll never 'enter playable map').

Greets, Justify
 
Level 3
Joined
Nov 12, 2006
Messages
35
ok, something is still wrong. Guys with mp greater than 0 are running back just a short distance and then targeting again just like guys with 0 mp. Note that we still havent resolved the problem that when mana reaches 0, they guys run full distance instead of simply immediently retargeting.
 
Level 3
Joined
Nov 12, 2006
Messages
35
Ok, so I was thinking about the trigger and certain things just didnt make sense so I re-did it. Tell me what you think. This is the OLD.

Morale Zero
Events
Conditions
Actions
Set tempdistance = 0.00
Set temppointmana = (Position of (Triggering unit))
Set tempgroup = (Units within 500.00 of (Position of (Triggering unit)) matching (((Triggering unit) belongs to an enemy of (Owner of (Triggering unit))) Equal to True))

Unit Group - Pick every unit in tempgroup and do (Actions)

Loop - Actions

If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Distance between (Position of (Triggering unit)) and (Position of (Picked unit))) Greater than tempdistance
Then - Actions
Set tempdistance = (Distance between (Position of (Triggering unit)) and (Position of (Picked unit)))
Set temppointenemy = (Position of (Picked unit))
Set tempangle = (Angle from temppointmana to temppointenemy)
Custom script: call RemoveLocation(udg_temppointenemy)
Else - Actions
Do nothing

Seperate

If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
tempdistance Greater than 0.00
Then - Actions
Set temppointtarget = (temppointenemy offset by 1000.00 towards tempangle degrees)
Unit - Order (Triggering unit) to Move To temppointtarget
Else - Actions
Unit - Set mana of (Picked unit) to 1.00

Custom script: call RemoveLocation(udg_temppointmana)
Custom script: call RemoveLocation(udg_temppointtarget)
Custom script: call DestroyGroup(udg_tempgroup)

This is My Alteration:

Morale Zero Test
Events
Conditions
Actions
Set tempgroup = (Units within 500.00 of (Position of (Triggering unit)) matching (((Triggering unit) belongs to an enemy of (Owner of (Triggering unit))) Equal to True))

Unit Group - Pick every unit in tempgroup and do (Actions)

Loop - Actions
Set tempdistance = (Distance between (Position of (Triggering unit)) and (Position of (Picked unit)))
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
tempdistance Less than 1000.00
Then - Actions
Set temppointenemy = (Position of (Picked unit))
Set temppointmana = (Position of (Triggering unit))
Set tempangle = (Angle from temppointmana to temppointenemy)
Set temppointtarget = (temppointenemy offset by 1000.00 towards tempangle degrees)
Unit - Order (Triggering unit) to Move To temppointtarget
Custom script: call RemoveLocation(udg_temppointenemy)
Custom script: call RemoveLocation(udg_temppointmana)
Custom script: call RemoveLocation(udg_temppointtarget)
Else - Actions
Unit - Set mana of (Picked unit) to 1.00

Custom script: call DestroyGroup(udg_tempgroup)
 
Level 13
Joined
Mar 16, 2008
Messages
943
This wouldn't make any sence.
You pick all units in 500 and ask if the distance is lower then 1000.
Afterwards you order the unit to move 1000 offset in the direction of your target.

My method searches for the farthest unit and let her run away, should be the nearest how I see.

Change the IF to smaller then (how it was in my first trigger) but set tempdistance to the range on startup (500 in this case)
 
Level 3
Joined
Nov 12, 2006
Messages
35
for the sake of my learning, please explain;

"You pick all units in 500 and ask if the distance is lower then 1000."
tempgroup is set before the loop.
then in the loop the triggering unit is getting further and further away from the units in temp group, until the distance exceeds 1000, which will then trigger his mana to increase to 1. So, yes it will always do the "then" part of the if/then/else, when the trigger first activates, but as he moves away it will eventually do the "else" part.

"Afterwards you order the unit to move 1000 offset in the direction of your target."
This part I just copied from how you did it in the original. I dont see how it is any difference.

I acknowledge you know more about GUI, and I respect your opinion, thats why I want to know how my logic is flawwed. Thanks again for all the help.
 
Level 13
Joined
Mar 16, 2008
Messages
943
You have to think about it:
Your idea is correct (but not working this way), and I see that mine is a bit bugged in some situations.
The pickloop is finished after 0.1 seconds (or faster).
So you'll take a unit that is for example 100 away. Now your unit with 0 morale will walk to the unit. (angle+180 is the fix for this (or switching the order for temppointangle)).
In the next milisecond your loop will cause the unit to move to the next unit in it's range.
I see that there is some stuff I hadn't though off, I think I'll write a Jass version of this (if you want to) so the move away will always work (for example surrounded units).

greets, Justify
 
Level 3
Joined
Nov 12, 2006
Messages
35
You've done so much to help already, would you like to help me create the map? The terrain is done (I think pretty well). Im working on the units, which will need balancing. With you doing the triggers the game could become exponentially better. Are you interested?

Game Outline;
2-10 players, each player chooses a faction (there will be four in original; The Empire, The Godless, The Ascended, and another I forget the name) There will be 2-3 neutral or neutral hostile factions as well (treefolk, merlocks, and another). So, players begin with a settler, build a base and fight each other. Instead of gold mines there will be a requisition system similar to Dawn of War (You capture and hold points on the map and gain resources periodically because of that). I might use a hybrid of mining gold and the requisition system. With a good jass programmer we could have some cool abilities for the heroes (2 types of heroes per team).
 
Level 13
Joined
Mar 16, 2008
Messages
943
Ouh, sry but I already work on a map with a friend, and I help another friend with his one, don't want to work on a 3. one, sry.
Btw, I'm not that good, ok, but there are MANY who are better then me ;)
I'll work on a system (or just at the morale zero trigger) that will make your units run away in the best direction (the one with more allys then enemys)
 
Level 12
Joined
Aug 10, 2004
Messages
1,141
I would make it based off the numbers of units
And then heroes would create more Moral in an area as an aura

Just because I feel like thats the way the true Moral Works
 
Top