Skip to content

Instantly share code, notes, and snippets.

@danthegoodman
Created June 30, 2015 17:10
Show Gist options
  • Save danthegoodman/e35666e312da930e8537 to your computer and use it in GitHub Desktop.
Save danthegoodman/e35666e312da930e8537 to your computer and use it in GitHub Desktop.
CreepSweeper
$IS_MINE:0
$TRIGGER_LEVEL:1
once
TRUE SetPopupTextAlwaysVisible
0 SetPopupTextY
Self "main" "NONE" SetImage
Self CONST_CELLHEIGHT 1 SetUnitAttribute
Self CONST_CELLWIDTH 1 SetUnitAttribute
Self CONST_CONNECTABLE 0 SetUnitAttribute
Self CONST_COUNTSFORVICTORY 0 SetUnitAttribute
Self CONST_CREATEPZ 0 SetUnitAttribute
Self CONST_DESTROYONDAMAGE 0 SetUnitAttribute
Self CONST_NULLIFIERDAMAGES 0 SetUnitAttribute
Self CONST_TAKEMAPSPACE 0 SetUnitAttribute
endonce
if(CurrentCoords GetTerrain lte(<-TRIGGER_LEVEL))
if(<-IS_MINE)
CurrentCoords 1000 SetCreeperNoLower
else
if(-?count not)
@getCellCount ->count
endif
<-count SetPopupText
endif
endif
#------------------
:getCellCount
0 ->_gcc_count
CurrentCoords 7 GetEnemyUnitsInRange
0 do
->_gcc_id
if(Self neq(<-_gcc_id))
if(<-_gcc_id "CreepMine.crpl" "IS_MINE" GetScriptVar)
<-_gcc_count add(1) ->_gcc_count
endif
endif
loop
<-_gcc_count
# First hit will not hit a mine.
# Does not handle MINES >= ROWS*COLUMNS
# ------------------------------------------
$ROWS:9
$COLUMNS:9
$TRIGGER_LEVEL:1
$MINES:10
$PREVENT_SAVELOAD:0
once
ElapsedTime asint ->randSeed
FALSE ->activated
CreateList ->spots
<-ROWS 0 do
<-COLUMNS 0 do
CreateList ->l
<-l add(2 mul(J 4)) AppendToList
<-l add(2 mul(I 4)) AppendToList
<-spots <-l AppendToList
loop loop
endonce
if (InvocationCount eq (1) and(<-PREVENT_SAVELOAD))
if(-?started)
@selfDestruct
else
TRUE ->started
endif
endif
if (<-activated)
@checkIfComplete
else
@watchMapForFirstAction
endif
#------------------
:checkIfComplete
GetListCount(<-spots) 0 do
GetListElement(<-spots I) ->_cic_unit
GetTerrain(GetUnitAttribute(<-_cic_unit CONST_COORDX) GetUnitAttribute(<-_cic_unit CONST_COORDY)) gt(<-TRIGGER_LEVEL) ->_cic_remains
<-_cic_unit "CreepMine.crpl" "IS_MINE" GetScriptVar ->_cic_isMine
if(<-_cic_remains neq(<-_cic_isMine ))
return #Mine triggerd or game not over
endif
loop
Destroy(Self 0) # Triggers mission pass
#------------------
:watchMapForFirstAction
GetListCount(<-spots) 0 do
GetListElement(<-spots I) ->_wm_l
if(GetTerrain(GetListElement(<-_wm_l 0) GetListElement(<-_wm_l 1)) lt(2))
@populateMap
break
endif
loop
#------------------
:populateMap
CreateList ->_pm_newSpots
# I refers to index from watchMapForFirstAction
GetListElement(<-spots I) FALSE @createMine
RemoveListElement(<-spots I)
<-MINES 0 do
@popRandomElement(<-spots) TRUE @createMine
loop
GetListCount(<-spots) 0 do
GetListElement(<-spots I) FALSE @createMine
loop
<-_pm_newSpots ->spots
TRUE ->activated
#------------------
:createMine
->_cmine_isMine ->_cmine_pos
CreateUnit("CRPLCORE" GetListElement(<-_cmine_pos 0) GetListElement(<-_cmine_pos 1)) ->_cmine_id
<-_cmine_id "CreepMine.crpl" AddScriptToUnit
<-_cmine_id "CreepMine.crpl" "IS_MINE" <-_cmine_isMine SetScriptVar
<-_cmine_id "CreepMine.crpl" "TRIGGER_LEVEL" <-TRIGGER_LEVEL SetScriptVar
<-_pm_newSpots <-_cmine_id AppendToList
#------------------
:selfDestruct
CurrentCoords 999 GetUnitsInRange
0 do
->_sd_id
if(GetUnitType(<-_sd_id) neq("COMMANDNODE"))
<-_sd_id 2 Destroy
endif
loop
MakeRain(100 1000)
#------------------
:popRandomElement
# L1 -- n1
# Arguments : A list
# Results : The n1 value removed from list
# Description: Removes a true-random item from the L1 list.
->_pre_l
GetListCount(<-_pre_l) mul (@TrueRandFloat) ->_pre_ndx
GetListElement(<-_pre_l <-_pre_ndx) # returned value
RemoveListElement(<-_pre_l <-_pre_ndx)
#------------------
:TrueRandFloat
# -- f1
# Arguments : None
# Results : A random value between 0.0 and 1.0.
# Description: Actually random.
<-randSeed mul (16807) mod (2147483647) ->randSeed
<-randSeed abs 2147483647.0 div
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment