- Joined
- Apr 1, 2010
- Messages
- 289
just joking. Nestharus cancelled it anyway .http://www.hiveworkshop.com/forums/requests-341/morale-system-willing-pay-200-a-204902/?highlight=Morale i have made something that kinda fits the requirements, the morale part works(other then sometimes not looping through the units)
So why didn't i just say, I need help with a morale system,
1st Lolz
2nd you're reading this aren't you?
How this Morale system is by using an RPS(region positioning system) which creates a lot of regions, and records the number of units in each one, using enters/leaves.
I have not added something for dying units(oh, it clears the references too them but they "remain" in the region(for the morale system anyway), but thats not a big deal i already have come up with a way to handle that and i would like to improve things in the code before i implement it)
here is the code
Problems that i have noted
Problem1 when the number of the units exceeds 300, it skips some of them(i think)
Problem 2, my unit group looping could probably be improved
Problem 3, my routing system stinketh.
I could use help fixing all bugs, etc.
please note saying use vJass, etc... is not help(ful)
So why didn't i just say, I need help with a morale system,
1st Lolz
2nd you're reading this aren't you?
How this Morale system is by using an RPS(region positioning system) which creates a lot of regions, and records the number of units in each one, using enters/leaves.
I have not added something for dying units(oh, it clears the references too them but they "remain" in the region(for the morale system anyway), but thats not a big deal i already have come up with a way to handle that and i would like to improve things in the code before i implement it)
here is the code
JASS:
function Trig_System_Perodic takes nothing returns boolean
local unit u
local integer UnitH
local integer i = 0
local real addition
local real r
//local integer t
local integer reduce = udg_InCombatCount
local integer sign = 1
local integer id
local real x
local real y
local real x1
local real y1
local real a
local real morale
local group g = CreateGroup()
call GroupAddGroup(udg_InCombat,g)
loop
loop
set u =FirstOfGroup(g)
call GroupRemoveUnit(g,u)// this is a first of group loop
exitwhen null != u
endloop
set UnitH =GetHandleId(u)
set i = i +1
if not IsUnitType(u, UNIT_TYPE_DEAD) then// checking to see if the unit is dead
set morale = LoadReal(udg_RPS,UnitH,1)
set udg_RegionH = LoadInteger(udg_RPS,UnitH,0)// this is determine which region to load the values from
set udg_Player = GetOwningPlayer(u)//the owning player
set udg_Friend = 0
set udg_Enemy = 0
set id =0
loop
if udg_Player == Player(id) or IsPlayerAlly(udg_Player,Player(id)) then
set udg_Friend = udg_Friend+LoadInteger(udg_RPS,udg_RegionH,id)
else
set udg_Enemy = udg_Enemy+LoadInteger(udg_RPS,udg_RegionH,id)
endif
set id = id+1
exitwhen id == 15
endloop
set r = I2R(udg_Friend-udg_Enemy )
if 0 > r then
set sign = -1
set r = -r
else
set sign = 1
endif
set addition = (r/(r+5))*10
set addition = (addition*sign)+morale
//call KillUnit(u)
if 100 < addition then
set addition = 100
elseif -200 > addition then
set addition = -200
endif
if IsUnitSelected(u,Player(0)) then
call CreateTextTagUnitBJ( I2S(R2I(addition)),u , 35, 10, 100, 100, 100, 0 )
call SetTextTagPermanentBJ( GetLastCreatedTextTag(), false )// note yes, i know you can use natives instead, this is just for the test!!
call SetTextTagLifespanBJ( GetLastCreatedTextTag(), 0.50 )
endif
if addition < -100 and not IsUnitInGroup(u,udg_Running) then//checking morale of unit
call SaveReal(udg_RPS,UnitH,3,GetUnitX(u))
call SaveReal(udg_RPS,UnitH,4,GetUnitY(u))
call GroupAddUnit(udg_Running,u)//adding unit to flee group
call UnitAddAbility(u,'A000')// preventing unit attacks
call UnitAddAbility(u,'A001')
elseif IsUnitInGroup(u,udg_Running) then
if addition > -50 then
call GroupRemoveUnit(udg_Running,u)
call UnitRemoveAbility(u,'A000')
call UnitRemoveAbility(u,'A001')
//call DisplayTextToPlayer(Player(0),0,0,"removing ability")
else
set x = LoadReal(udg_RPS,UnitH,3)
set y = LoadReal(udg_RPS,UnitH,4)
set x1 = GetUnitX(u)
set y1 = GetUnitY(u)
set a = Atan2(y1-y,x1-x)
set x = Cos(a)*500
set y = Sin(a)*500
call IssuePointOrder(u,"move",x1+x,y1+y)
endif
endif
//call SaveInteger(udg_RPS,UnitH,2,t)// saving the time its been in combat
call SaveReal(udg_RPS,UnitH,1,addition)// saving its "morale"
else
set reduce = reduce - 1 // removing the unit from the unit group
call FlushChildHashtable(udg_RPS,UnitH) // clearing the hashtable
call GroupRemoveUnit(udg_InCombat,u) // removing unit
endif
exitwhen i == udg_InCombatCount
endloop
set udg_InCombatCount = reduce
set u = null
call DestroyGroup(g)
set g = null
return false
endfunction
function Trig_System_Actions takes nothing returns nothing
local unit d = GetTriggerUnit()
local unit a = GetAttacker()
if not IsUnitInGroup(d,udg_InCombat) then
call GroupAddUnit(udg_InCombat,d)
set udg_InCombatCount =udg_InCombatCount+1
endif
if not IsUnitInGroup(a,udg_InCombat) then
call GroupAddUnit(udg_InCombat,d)
set udg_InCombatCount =udg_InCombatCount+1
endif
call SaveInteger(udg_RPS,GetHandleId(d),2,0)
call SaveInteger(udg_RPS,GetHandleId(a),2,0)
endfunction
//===========================================================================
function InitTrig_System takes nothing returns nothing
set gg_trg_System = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_System, EVENT_PLAYER_UNIT_ATTACKED )
call TriggerAddAction( gg_trg_System, function Trig_System_Actions )
set udg_RPS_Per = CreateTrigger( )
call TriggerRegisterTimerEvent(udg_RPS_Per,.5, true)
call TriggerAddCondition(udg_RPS_Per,Condition(function Trig_System_Perodic))
endfunction
JASS:
function RPS_LeaveLarge takes nothing returns boolean
local region r = GetTriggeringRegion()
local integer hand = GetHandleId(r)
local integer int = GetPlayerId(GetOwningPlayer(GetTriggerUnit()))
local integer i = LoadInteger(udg_RPS,hand,int)-1
if i < 0 then
set i =0
endif
call SaveInteger(udg_RPS,hand,int,i)
set r = null
return false
endfunction
function RPS_EnterLarge takes nothing returns boolean
local region r = GetTriggeringRegion()
local integer hand = GetHandleId(r)
local integer int = GetPlayerId(GetOwningPlayer(GetTriggerUnit()))
call SaveInteger(udg_RPS,hand,int,LoadInteger(udg_RPS,hand,int)+1)
set r = null
return false
endfunction
function RPS_EnterSmall takes nothing returns boolean
call SaveInteger(udg_RPS,GetHandleId(GetTriggerUnit()),0,LoadInteger(udg_RPS,GetHandleId(GetTriggeringRegion()),0))
return false
endfunction
function Trig_RPS_Actions takes nothing returns boolean
local unit u = GetTriggerUnit()
if not IsUnitInGroup(u,udg_InCombat) then
call GroupAddUnit(udg_InCombat,u)
set udg_InCombatCount = udg_InCombatCount+1
endif
return false
endfunction
//===========================================================================
function InitTrig_RPS takes nothing returns nothing
local rect tr = GetPlayableMapRect()
local rect lr = Rect(-udg_CellSize/2*3,-udg_CellSize/2*3,udg_CellSize/2*3,udg_CellSize/2*3)
local region sr
local region br
local trigger E = CreateTrigger()
local trigger L = CreateTrigger()
local trigger EnterSmall = CreateTrigger()
local real h = GetRectMinY(tr)-300
local real minx = GetRectMinX(tr)-300
local integer row = R2I((300+GetRectMaxY(tr) - h)/udg_CellSize)+1
local integer col = R2I((GetRectMaxX(tr)+300 - minx)/udg_CellSize)+1
local integer i1 = 0
local integer i2 = 0
local real step = udg_CellSize
local real w = minx
set udg_RPS = InitHashtable()
set udg_AntiAttack = 'A000'
call SetRect(tr, -udg_CellSize/2,-udg_CellSize/2,udg_CellSize/2,udg_CellSize/2)
loop
set i1 = i1 + 1
loop
set i2 = i2 +1
call MoveRectTo(lr,w,h)
set br = CreateRegion()
call RegionAddRect(br,lr)
call TriggerRegisterEnterRegion(E,br,null)
call TriggerRegisterLeaveRegion(L,br,null)
call MoveRectTo(tr,w,h)
set sr = CreateRegion()
call RegionAddRect(sr,tr)
call TriggerRegisterEnterRegion(EnterSmall,sr,null)
call SaveInteger(udg_RPS,GetHandleId(sr),0,GetHandleId(br))
//call CreateUnit(Player(0),'hfoo',w,h,0)
set w = w+step
exitwhen i2 == col
endloop
set h = h+step
set i2 = 0
set w = minx
exitwhen i1 == row
endloop
call TriggerAddCondition(E,Condition(function RPS_EnterLarge))
call TriggerAddCondition(L,Condition(function RPS_LeaveLarge))
call TriggerAddCondition(EnterSmall,Condition(function RPS_EnterSmall))
call RemoveRect(lr)
call RemoveRect(tr)
set br = null
set sr = null
set tr = null
set L = null
set lr = GetWorldBounds()
set sr = CreateRegion()
call RegionAddRect(sr,lr)
set gg_trg_RPS = CreateTrigger( )
call TriggerRegisterEnterRegion(gg_trg_RPS,sr,null)
call TriggerAddCondition( gg_trg_RPS, Condition(function Trig_RPS_Actions ))
call RemoveRect(lr)
set lr = null
set sr = null
endfunction
Problem1 when the number of the units exceeds 300, it skips some of them(i think)
Problem 2, my unit group looping could probably be improved
Problem 3, my routing system stinketh.
I could use help fixing all bugs, etc.
please note saying use vJass, etc... is not help(ful)