CRPL related questions

Started by eduran, October 13, 2013, 09:10:10 AM

Previous topic - Next topic

knucracker

Alright I see some issues with this I will fix and put in the next beta build.  Looks like I left out the strafer and bomber in a routine for some reason.

As a note on your CRPL, you can do this for improved efficiency:

GetEnemyUnitsInRange(0 0 99999) ->count ClearStack

Note that you have to be running with an empty stack prior to this line since it clears the stack.  But this will give you the count and then throw away all of the unit UIDs that were pushed to the stack without requiring that you pop each one off.

Clean0nion

#46
If I use GetUnitAt on a coord with multiple units on it, in which order are the UIDs returned?
Edit: answered by V and eduran. eduran says only returns one UID. V says returns all UIDs in order of age.

knucracker

It should only return one, that's for sure.   If you want all, then you could probably use a GetAllUnitsInRange call with a short range (like 1).

I just checked and when you ask for one, the one you get back (if units are stacked) is not defined.  Translation, it's hash order and won't make any sense and can change across loads or as units get created and destroyed.

kwinse

I was messing around with that the other day and noticed the problem with GetUnitAt and stacked units (in my case, a cannon and a flying strafer). A 0 range on your choice of unit in range function should work.

Lost in Nowhere

#49
Ok, I am trying to make a player-controlled spaceship, similar to the credits mission.
Currently, it immediately explodes and teleports while doing so, despite it having no reason to do so.
# PlayerShip.crpl
# Created on: 11/23/2013 8:06:21 PM
# ------------------------------------------

$Name:"Player"

$MaxHealth:100
$HealRate:0.1
$CreeperDamage:0.6

$SelectedWeapon:0

$LaserCooldown:10
$LaserCreeperDamage:100
$LaserStructureDamage:100

$MaxMissiles:0
$Missiles:0
$MissileCooldown:30
$MissileCreeperDamage:10000
$MissileStructureDamage:200

$MaxSuperLasers:0
$SuperLasers:0
$SuperLaserCooldown:30
$SuperLaserStructureDamage:500

$MaxSpeed:4.0
$Acceleration:0.05
$TurnSpeedDeg:4

once
# initialize more variables and set some unit attributes
SetUnitAttribute(Self CONST_MAXHEALTH <-MaxHealth)
SetUnitAttribute(Self CONST_HEALTH <-MaxHealth)
SetUnitAttribute(Self CONST_DESTROYONDAMAGE TRUE)
SetUnitAttribute(Self CONST_HEALRATE <-HealRate)

0.0 ->dir
0.0 ->speed
endonce

@UpdateHealth
@UpdatePosition
@UpdateImage

:awake
TRUE EnableAlternateControlMode
:UpdateHealth
if (@OverCreeper)
GetUnitAttribute(Self CONST_HEALTH) ->health
<-health sub(<-CreeperDamage) ->health
if (<-health lte(0))
0 ->health
endif
SetUnitAttribute(Self CONST_HEALTH <-health)
endif
#if (@OverWall)
# 0 ->health
#endif
#Stick stuff for other enemies here
if (<-health lte(0))
Self 2 Destroy
endif
:OverCreeper
do(2 -1)
do (2 -1)
if (GetCreeper(CurrentX add(I) CurrentY add(J)) gt(0))
return (TRUE)
endif
loop
loop
FALSE
:OverWall
do(2 -1)
do (2 -1)
if (GetTerrainOverride(CurrentX add(I) CurrentY add(J)) gt(500))
return (TRUE)
endif
loop
loop
FALSE
:UpdateImage
Self "main" <-dir SetImageRotation
:UpdatePosition
"LeftArrow" GetKey or("A" GetKey) if
<-TurnSpeedDeg @DegToRad <-dir add ->dir
endif
"RightArrow" GetKey or("D" GetKey) if
<-TurnSpeedDeg @DegToRad <-dir sub ->dir
endif
"UpArrow" GetKey or("W" GetKey) if
<-speed <-Acceleration add <-MaxSpeed min ->speed
endif
"DownArrow" GetKey or("S" GetKey) if
<-speed <-Acceleration sub 0.0 max ->speed
endif
CurrentPixelCoords ->px ->py
<-dir cos mul (<-speed 8 mul) add (<-px) ->px
<-dir sin mul (<-speed 8 mul) add (<-py) ->py
Self CONST_PIXELCOORDX <-px SetUnitAttribute
Self CONST_PIXELCOORDY <-py SetUnitAttribute
:FireProjectile
"Alpha1" GetKey if
1 ->SelectedWeapon
endif
"Alpha2" GetKey if
2 ->SelectedWeapon
endif
"Alpha3" GetKey if
3 ->SelectedWeapon
endif

<-SelectedWeapon 1 eq if
    #Stuff
endif
<-SelectedWeapon 2 eq and (<-Missiles 0 gt) if
    #Stuff
endif
<-SelectedWeapon 3 eq and (<-SuperLasers 0 gt) if
    #Stuff
endif
:DegToRad
asfloat PI mul 180.0 div
:destroyed
#FailMission

Its teleportation also seems to be across the line y=MapHeight-x, running diagonally across the map...
Edit - fixed the teleporting
Don't die! :)

Kingo

Quote from: Lost in Nowhere on November 24, 2013, 10:27:13 AM
Ok, I am trying to make a player-controlled spaceship, similar to the credits mission.
Currently, it immediately explodes and teleports while doing so, despite it having no reason to do so.
# PlayerShip.crpl
# Created on: 11/23/2013 8:06:21 PM
# ------------------------------------------

$Name:"Player"

$MaxHealth:100
$HealRate:0.1
$CreeperDamage:0.6

$SelectedWeapon:0

$LaserCooldown:10
$LaserCreeperDamage:100
$LaserStructureDamage:100

$MaxMissiles:0
$Missiles:0
$MissileCooldown:30
$MissileCreeperDamage:10000
$MissileStructureDamage:200

$MaxSuperLasers:0
$SuperLasers:0
$SuperLaserCooldown:30
$SuperLaserStructureDamage:500

$MaxSpeed:4.0
$Acceleration:0.05
$TurnSpeedDeg:4

once
# initialize more variables and set some unit attributes
SetUnitAttribute(Self CONST_MAXHEALTH <-MaxHealth)
SetUnitAttribute(Self CONST_HEALTH <-MaxHealth)
SetUnitAttribute(Self CONST_DESTROYONDAMAGE TRUE)
SetUnitAttribute(Self CONST_HEALRATE <-HealRate)

0.0 ->dir
0.0 ->speed
endonce

@UpdateHealth
@UpdatePosition
@UpdateImage

:awake
TRUE EnableAlternateControlMode
:UpdateHealth
if (@OverCreeper)
GetUnitAttribute(Self CONST_HEALTH) ->health
<-health sub(<-CreeperDamage) ->health
if (<-health lte(0))
0 ->health
endif
SetUnitAttribute(Self CONST_HEALTH <-health)
endif
#if (@OverWall)
# 0 ->health
#endif
#Stick stuff for other enemies here
if (<-health lte(0))
Self 2 Destroy
endif
:OverCreeper
do(2 -1)
do (2 -1)
if (GetCreeper(CurrentX add(I) CurrentY add(J)) gt(0))
return (TRUE)
endif
loop
loop
FALSE
:OverWall
do(2 -1)
do (2 -1)
if (GetTerrainOverride(CurrentX add(I) CurrentY add(J)) gt(500))
return (TRUE)
endif
loop
loop
FALSE
:UpdateImage
Self "main" <-dir SetImageRotation
:UpdatePosition
"LeftArrow" GetKey or("A" GetKey) if
<-TurnSpeedDeg @DegToRad <-dir add ->dir
endif
"RightArrow" GetKey or("D" GetKey) if
<-TurnSpeedDeg @DegToRad <-dir sub ->dir
endif
"UpArrow" GetKey or("W" GetKey) if
<-speed <-Acceleration add <-MaxSpeed min ->speed
endif
"DownArrow" GetKey or("S" GetKey) if
<-speed <-Acceleration sub 0.0 max ->speed
endif
CurrentPixelCoords ->px ->py
<-dir cos mul (<-speed 8 mul) add (<-px) ->px
<-dir sin mul (<-speed 8 mul) add (<-py) ->py
Self CONST_PIXELCOORDX <-px SetUnitAttribute
Self CONST_PIXELCOORDY <-py SetUnitAttribute
:FireProjectile
"Alpha1" GetKey if
1 ->SelectedWeapon
endif
"Alpha2" GetKey if
2 ->SelectedWeapon
endif
"Alpha3" GetKey if
3 ->SelectedWeapon
endif

<-SelectedWeapon 1 eq if
    #Stuff
endif
<-SelectedWeapon 2 eq and (<-Missiles 0 gt) if
    #Stuff
endif
<-SelectedWeapon 3 eq and (<-SuperLasers 0 gt) if
    #Stuff
endif
:DegToRad
asfloat PI mul 180.0 div
:destroyed
#FailMission

Its teleportation also seems to be across the line y=MapHeight-x, running diagonally across the map...
Edit - fixed the teleporting

Have you checked to see if the health is resetting to zero somewhere in the code?

Lost in Nowhere

No, it's not. It also started working, so, it definitely isn't.
Don't die! :)

Clean0nion

Why does RandCoords run 25 times in succession always give the same set of 25 coords(?)

Grauniad

A goodnight to all and to all a good night - Goodnight Moon

knucracker

"health" only gets initialized if the ship is over Creeper.  But there is a check that if health is <= 0, then destroy.  Either this has to be done every frame:
GetUnitAttribute(Self CONST_HEALTH) ->health
or GetUnitAttribute(Self CONST_HEALTH) has to be called for determining whether to call Destroy.

Clean0nion

Command request!
WinMission: the opposite of FailMission

kwinse

Alternatively, you can blow up all enemy units to trigger normal victory, as in the connect totems to win code example.

Annonymus

He tried (he used destroyallenemyunits) but for some reason it doesn't win the map!
If a topic started by me is in the wrong place feel free to move it at anytime.

Clean0nion

Quote from: Annonymus on December 08, 2013, 12:21:49 PM
He tried (he used destroyallenemyunits) but for some reason it doesn't win the map!
...or destroy the units.

pawel345

Collectors is a list with some UID's of CPRL cores. Since the player can destroy them, every game loop I check if any have been destroyed and remove them form this list using such a code:

<-Collectors GetListCount 0 do
<-Collectors I GetListElement CONST_ISDESTROYED GetUnitAttribute if
<-Collectors I RemoveListElement
endif
loop

Can someone tell me why it doesn't work? I'm getting that RemoveListElement it taking item from an empty stack?