| 03-26-2009, 04:56 AM | #1 |
Problems fixed so far. Waiting for more questions to arise. JASS:scope ThreatTable //This is to simulate a Threat System in the map and to allow random intelligent creep behavior. globals //private FI array AreaAI //Tells the timer what Area to cycle through. private group AIGroup //This group will be used for many AI and Threat purposes. private timer Cycler //Timer to cycle through engaged units. private integer array AreaID //Each Area is assigned an ID that has a creep list associated with it. private unit array PlayerHero //This stores each player's Hero private unit array PetHero //This stores each player's Pet if applicable. //This is all temporary data used in Unit Groups private unit TempUnit //Obvious private CreepData TempData //Obvious private integer Count //Counts units in group endglobals function Check takes nothing returns boolean return IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(TempUnit)) and GetWidgetLife(GetFilterUnit()) > 0 and TempData.IsEngaged == true endfunction function Counter takes nothing returns nothing set Count = Count + 1 endfunction struct CreepData integer CreepID real array PThreat[12] //0 - 5 = Players 6 - 11 = Pets real HighestThreat unit CurrentTarget boolean IsEngaged static method create takes integer CreepID returns CreepData local CreepData C = CreepData.allocate() local integer i = 0 set C.CreepID = CreepID loop exitwhen i > 11 set C.PThreat[i] = 0 set i = i + 1 endloop set C.HighestThreat = 0 set C.CurrentTarget = null set C.IsEngaged = false return C endmethod private method TargetAssign takes unit dealer returns nothing if .HighestThreat < .PThreat[GetPlayerId(GetOwningPlayer(dealer))] then set .HighestThreat = .PThreat[GetPlayerId(GetOwningPlayer(dealer))] set .CurrentTarget = dealer endif endmethod private method GetThreatPosition takes unit whichhero returns integer local real unitthreat = .PThreat[GetPlayerId(GetOwningPlayer(whichhero))] local integer counter = 0 local integer i = 0 loop exitwhen i > 11 if .PThreat[i] < unitthreat then set counter = counter + 1 endif set i = i + 1 endloop return counter endmethod private method RegisterThreat takes CreepData C, unit dealer, unit target, real Value, string Type returns nothing local integer p = GetPlayerId(GetOwningPlayer(dealer)) local unit u if GetTableString(GetAttachedString(target, "Table"), "[classification]") == "player" then if Type == "Damage" then set .PThreat[p] = .PThreat[p] + Value elseif Type == "Heal" then set TempUnit = dealer set TempData = C call GroupEnumUnitsInRange(AIGroup, GetUnitX(dealer), GetUnitY(dealer), 2000, Condition(function Check)) set Count = 0 call ForGroup(AIGroup, function Counter) loop set u = FirstOfGroup( AIGroup ) exitwhen u == null call GroupRemoveUnit( AIGroup, u ) set TempData = GetUnitUserData(u) set TempData.PThreat[p] = TempData.PThreat[p] + ((.5 * Value) / Count) endloop elseif Type == "Taunt" then set .PThreat[p] = .HighestThreat + 1 elseif Type == "Detaunt" then set .PThreat[p] = .PThreat[p] - Value endif elseif GetTableString(GetAttachedString(target, "Table"), "[classification]") == "pet" then if Type == "Damage" then set .PThreat[p+6] = .PThreat[p+6] + Value elseif Type == "Heal" then set TempUnit = dealer set TempData = C call GroupEnumUnitsInRange(AIGroup, GetUnitX(dealer), GetUnitY(dealer), 2000, Condition(function Check)) set Count = 0 call ForGroup(AIGroup, function Counter) loop set u = FirstOfGroup( AIGroup ) exitwhen u == null call GroupRemoveUnit( AIGroup, u ) set TempData = GetUnitUserData(u) set TempData.PThreat[p+6] = TempData.PThreat[p+6] + ((.5 * Value) / Count) endloop elseif Type == "Taunt" then set .PThreat[p+6] = .HighestThreat + 1 elseif Type == "Detaunt" then set .PThreat[p+6] = .PThreat[p+6] - Value endif endif if .IsEngaged == false then set .IsEngaged = true endif //if GetUnitAbilityLevel(target, somebuff) > 0 or blahblah then //donothing //else call .TargetAssign(dealer) //endif //This will be used for abilities that FORCE a unit to attack a different target. TargetCheck will automatically get called at the end of any buff that has this effect. set u = null endmethod endstruct function RegisterCreepData takes unit u, integer CreepID returns nothing local CreepData C = CreepData.create(CreepID) call SetUnitUserData(u, C) endfunction endscope |
| 03-27-2009, 06:51 AM | #2 |
This is a rough example, I didn't look that closely at your code so I haven't put in references to all your variables, or how you pass data. JASS:globals //don't need these globals, can pass using Tables or w/e integer Count integer HealedValue endglobals local group g = CreateGroup() set Count = 0 call GroupEnumUnits(g, 800, x, y, Condition(function Count)) //forgotten the exact syntax, but easy to check set HealedValue = //whatever it was, can't be bothered checking call ForGroup(g, function Enum) call DestroyGroup() function Count takes nothing returns boolean //this is called by GroupEnumUnits, once for each unit that is within the 800 set Count = Count + 1 return true //if it returns false, then the GetFilterUnit() is excluded from the group endfunction function Enum takes nothing returns nothing //and this is called by ForGroup(), for each unit that has passed whatever check you have in count, and is now in the group g. local unit u = GetEnumUnit() set u.struct.threat = u.struct.threat 0.5 * Healed Value / Count //not sure how you need endfunction |
| 03-27-2009, 08:22 AM | #3 |
Thanks for the help, got my question answered though. Keeping this thread open for future questions I am sure I will have though. (Edit ftw) |
