- Joined
- Apr 27, 2008
- Messages
- 2,455
Nothing for me, but tell that about it with some others (such as Nestharus).
//To disable implicit usage of members and methods, (not requiring this. ) add:
// a line containing: [noimplicitthis]
struct ...
integer data
method m takes integer data ...
set this.data = data
I have not updated the thread yet because we are still discussion possibilities for globals.
"Event - Map Initialization" GUI Initializers
.
- MyTrigger
- Events
- Map Initialization
- Conditions
- Actions
type agent extends handle
type event extends agent
//[…]
type unit extends widget
key
s, there is no guidline for interfaces and function interfaces. How come that two of the most highlevel constructs in vJass are not mentioned? I think interface
s should follow the struct
convention whatever that is. And function interface
s should follow the function
convention.<P>Interface, key and function interface were not listed because I never use them so I didn't think to add them. Simple as that.</P><P> </P><P>Keys were a good idea but the execution was bad. One of the ideas in LuckyParser, which was derived from cJass, was to use definitions instead of keys because they are more dynamic.</P><P> </P><P>Function interfaces and interfaces in general were also good ideas but their compiled structure is aweful: mainly in that it duplicates the method with 2-3 copies, so longer methods just become giant.</P><P> </P><P>I see your point in that native types are lowercased, however native types do not have OOP syntax like structs do.</P>
Well WaterKnight I haven't added those to the tutorial, doesn't mean I won't write up the guidelines for them. I have just not made the update yet for one reason or another. Seeing as how this is still pending, I can make updating the thread and its arguments a lesser priority because there are so many other things I am trying to work on.
So much controversy over how to simply write code. Gosh this just make GUI look better and better.
Bribe said:variableNames and methodNames should begin with a
lowercase letter and each new word seperated by a new capitalized
letter. This is called camelCasing. variableNames, this was designed
by Blizzard. methodNames are typically formatted like this in most
mainstream languages like C and are also formatted in such a way
with most of vJass resources, it makes sense that this should also
be the standard.
It prioritizes the globals? That doesn't even make sense why they would do that. Epic fail right?
struct Code
static hashtable TABLE
trigger action
static method GetFromSelf takes code c returns thistype
local integer id = GetHandleId(Condition(c))
local thistype this = LoadInteger(thistype.TABLE, id, 0)
if (this == 0) then
set this = thistype.allocate()
set this.action = CreateTrigger()
call SaveInteger(thistype.TABLE, id, 0, this)
call TriggerAddCondition(this.action, Condition(c))
endif
return this
endmethod
static method Run takes nothing returns nothing
call TriggerEvaluate(this.action)
endmethod
static method onInit takes nothing returns nothing
set thistype.TABLE = InitHashtable()
endmethod
endstruct
Well common.AI has a native "StartThread" (which sadly is not one of the natives that actually works), though I suppose "ExecuteFunc" could still be used though it doesn't work so well with needing string concatenation and all that.
Code compression meaning that the JASS verbosity really takes up a LOT of map file size. The compression could be better.
Well StartThread takes a "code" argument and you know what that means.
Code size in a real map is quite important, a map with a couple dozen GUI spells
converted to optimized JASS can cut out 50-100KB of data.
I dunno how to even use an AI script. Although if those natives work inside of one I think I would use AI scripts to code everything from now on.
//===========================================================================
// ElfesH
//===========================================================================
globals
integer attackWave = 1
integer nextDelay = 0
integer awGold = 0
integer awWood = 0
string name = "computerElf"
unit u_heros = null
endglobals
//===========================================================================
function ReturnPlayerString takes integer i returns string
if i == 1 then
return "1"
elseif i == 2 then
return "2"
elseif i == 3 then
return "3"
elseif i == 4 then
return "4"
elseif i == 5 then
return "5"
elseif i == 6 then
return "6"
elseif i == 7 then
return "7"
elseif i == 8 then
return "8"
elseif i == 9 then
return "9"
elseif i == 10 then
return "10"
elseif i == 11 then
return "11"
elseif i == 12 then
return "12"
endif
endfunction
//===========================================================================
function InitOptions takes nothing returns nothing
call SetCampaignAI( )
call SetDefendPlayer( false )
call SetRandomPaths( false )
call SetTargetHeroes( true )
call SetPeonsRepair( false )
call SetHeroesFlee( true )
call SetHeroesBuyItems( true )
call SetUnitsFlee( true )
call SetGroupsFlee( false )
call SetWatchMegaTargets( false )
call SetIgnoreInjured( false )
call SetHeroesTakeItems( true )
call SetSlowChopping( false )
call SetCaptainChanges( false )
call SetSmartArtillery( true )
endfunction
//***************************************************************************
//*
//* Heroes
//*
//***************************************************************************
//===========================================================================
// Stores hero ID and skills
//===========================================================================
function SetHero takes integer order, integer heroid returns nothing
if (order == 1) then
set hero_id = heroid
if (heroid == 'Edem') then
set skills1[ 1] = 'AEmb'
set skills1[ 2] = 'AEim'
set skills1[ 3] = 'AEev'
set skills1[ 4] = 'AEmb'
set skills1[ 5] = 'AEim'
set skills1[ 6] = 'AEme'
set skills1[ 7] = 'AEev'
set skills1[ 8] = 'AEmb'
set skills1[ 9] = 'AEim'
set skills1[10] = 'AEev'
endif
endif
endfunction
//===========================================================================
// Selects hero IDs for three possible heroes
//===========================================================================
function SelectHeroes takes nothing returns nothing
local integer roll = GetRandomInt(1,100)
call SetHero( 1, 'Edem' )
endfunction
//===========================================================================
// Returns the hero skill for the given hero and level
//===========================================================================
function ChooseHeroSkill takes nothing returns integer
local integer curHero = GetHeroId()
local integer level = GetHeroLevelAI()
if (level > max_hero_level) then
set max_hero_level = level
endif
if (curHero == hero_id) then
return skills1[level]
elseif (curHero == hero_id2) then
return skills2[level]
elseif (curHero == hero_id3) then
return skills3[level]
endif
return 0
endfunction
//***************************************************************************
//*
//* Building and Harvesting
//*
//***************************************************************************
//===========================================================================
// Specifies building priorities for workers
//===========================================================================
function BuildPriorities takes nothing returns nothing
call SetBuildAll( BUILD_UNIT, 1, hero_id, -1 )
endfunction
//===========================================================================
// Specifies harvesting priorities for workers
//===========================================================================
function HarvestPriorities takes nothing returns nothing
local integer mine = TownWithMine()
local integer allGold = GetUnitCountDone('opeo')
local integer allWood = GetUnitCountDone('opeo')
local integer numWorkers
set numWorkers = 5
call HarvestGold( 0, numWorkers )
set numWorkers = 5
call HarvestWood( 0, numWorkers )
set numWorkers = 5
call HarvestGold( 1, numWorkers )
set numWorkers = 4
call HarvestWood( 0, numWorkers )
endfunction
//===========================================================================
// Determines all building and harvesting assignments for workers
//===========================================================================
function WorkerAssignment takes nothing returns nothing
loop
// Harvesting
call ClearHarvestAI( )
call HarvestPriorities( )
// Building
call InitBuildArray( )
call BuildPriorities( )
call Sleep( 2 )
endloop
endfunction
//===================================
function ReturnNeutralUnitById takes integer unitID returns unit
local group g = CreateGroup()
local unit u = null
call GroupEnumUnitsOfPlayer(g,Player(PLAYER_NEUTRAL_PASSIVE),null)
loop
set u = FirstOfGroup(g)
exitwhen u == null
if GetUnitTypeId(u) == unitID then
return u
endif
call GroupRemoveUnit(g, u)
endloop
return null
endfunction
//===================================
//==============UNITS================
//===================================
function ReturnUnitById takes integer unitID returns unit
local group g = CreateGroup()
local unit u = null
call GroupEnumUnitsOfPlayer(g,ai_player,null)
loop
set u = FirstOfGroup(g)
exitwhen u == null
if GetUnitTypeId(u) == unitID then
return u
endif
call GroupRemoveUnit(g, u)
endloop
return null
endfunction
//====================================
function CreateAttackGroup takes integer unitID returns group
local integer all
local integer i
local unit u
local group attack
set i = 0
set all = GetUnitCountDone(unitID)
loop
set u = ReturnUnitById(unitID)
if (not IsUnitInGroup(u,attack)) then
call GroupAddUnit(attack,u)
set i = i + 1
endif
exitwhen (i == all)
endloop
return attack
endfunction
//===================================
//==============HEROS================
//===================================
function CreateHeros takes nothing returns unit
local group g = CreateGroup()
local unit u = null
call GroupEnumUnitsOfPlayer(g,ai_player,null)
loop
set u = FirstOfGroup(g)
exitwhen u == null
if GetUnitTypeId(u) == hero_id then
return u
endif
call GroupRemoveUnit(g, u)
endloop
return null
endfunction
//===================================
function WaitHeros takes nothing returns nothing
loop
set u_heros = CreateHeros()
call Sleep(2)
exitwhen (u_heros != null)
endloop
endfunction
//====================================
function LGetHerosPercentLife takes nothing returns real
local real value = GetUnitState(u_heros,ConvertUnitState(0))
local real maxValue = GetUnitState(u_heros,ConvertUnitState(1))
return value / maxValue*100
endfunction
//====================================
function LifeNeeded takes nothing returns boolean
if (LGetHerosPercentLife() < 25) then
return true
elseif (LGetHerosPercentLife() > 95) then
return false
endif
endfunction
//===================================================================
function A takes nothing returns nothing
local group attackgroup = CreateGroup()
local unit heros
local unit fontaine = ReturnNeutralUnitById('nfoh')
local integer random
local real X
local real Y = 877.0
call WaitHeros()
loop
if (LGetHerosPercentLife() < 25 and not IsUnitInRange(u_heros,fontaine,250)) then
call IssuePointOrder(u_heros,"move",GetUnitX(fontaine),GetUnitY(fontaine))
loop
exitwhen IsUnitInRange(u_heros,fontaine,250)==true
call Sleep(0.5)
endloop
loop
exitwhen LGetHerosPercentLife() == 100.0
if IsUnitInRange(u_heros,fontaine,250) == true then
call IssueImmediateOrder(u_heros,"holdposition")
else
call IssuePointOrder(u_heros,"move",GetUnitX(fontaine),GetUnitY(fontaine))
endif
call Sleep(0.5)
endloop
set random = GetRandomInt(1,3)
if random == 1 then
set X = -672.0
elseif random == 2 then
set X = 439.0
elseif random == 3 then
set X = -567.0
endif
call IssuePointOrder(u_heros,"attack",X,Y)
endif
if (LGetHerosPercentLife() > 25) then
if (GetUnitCurrentOrder(u_heros) != OrderId("attack")) then
call IssuePointOrder(u_heros,"attack",-672.0,Y)
endif
endif
call Sleep(0.5)
endloop
endfunction
//===========================================================================
// main
//===========================================================================
function main takes nothing returns nothing
call InitAI( )
call SetPlayerName( ai_player,(name + "[" + ReturnPlayerString(GetAiPlayer()) + "]") )
call InitOptions( )
call SelectHeroes( )
call SetHeroLevels( function ChooseHeroSkill )
call Sleep( 0.1 )
call StartThread(function WorkerAssignment)
call StartThread(function A)
call PlayGame( )
endfunction
function ReturnPlayerString takes integer i returns string
if i == 1 then
return "1"
elseif i == 2 then
return "2"
elseif i == 3 then
return "3"
elseif i == 4 then
return "4"
elseif i == 5 then
return "5"
elseif i == 6 then
return "6"
elseif i == 7 then
return "7"
elseif i == 8 then
return "8"
elseif i == 9 then
return "9"
elseif i == 10 then
return "10"
elseif i == 11 then
return "11"
elseif i == 12 then
return "12"
endif
endfunction
function LifeNeeded takes nothing returns boolean
if (LGetHerosPercentLife() < 25) then
return true
elseif (LGetHerosPercentLife() > 95) then
return false
endif
endfunction