User Tools

Site Tools


crpl:crpltutorial:easycrpl

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
crpl:crpltutorial:easycrpl [2015/04/13 18:58] Telanircrpl:crpltutorial:easycrpl [2019/05/05 13:13] (current) – Small change for code highlighting Karsten75
Line 2: Line 2:
  
 ===== EasyCRPL ===== ===== EasyCRPL =====
-== Version 1.==+== Version 1.==
  
  
- +<code 4rpl>#=============================================
- +
-<code>  +
-#=============================================+
 # ===== :EasyCRPL: Collection by Telanir ===== # ===== :EasyCRPL: Collection by Telanir =====
 +# --VERSION: 1.1
 +# CREDITS:
 +# Big thanks to Knuckle Cracker (knucracker) for an amazing game and lots of well commented source!
 +# Big thanks to Tyler21 for a contribution of Forcefield code using Field cells!
 # #
 # Usage: Simply paste this script at the bottom of your # Usage: Simply paste this script at the bottom of your
Line 40: Line 41:
 # This code can be used at any time if it is in your # This code can be used at any time if it is in your
 # script, and generally comes in blocks of functions. # script, and generally comes in blocks of functions.
 +# Forcefield Manager: A custom forcefield manager that helps safely create functional forcefields.
 +# @SetForcefieldProperties: 
 +#
 # List-Builder: Two simple functions that will safely create a list without touching the stack. # List-Builder: Two simple functions that will safely create a list without touching the stack.
 # @BeginList [* *...] @BuildList # @BeginList [* *...] @BuildList
Line 60: Line 64:
 # -- # --
 # #
 +# @GetCreeperInRadius: x y f1 - f2
 # @SetImageAlpha: s1 i1 - # @SetImageAlpha: s1 i1 -
 # @TerrainAccessible: x y i1 - b1 # @TerrainAccessible: x y i1 - b1
Line 83: Line 88:
 # Wiki CRPL Reference: http://knucklecracker.com/wiki/doku.php?id=crpl:crplreference # Wiki CRPL Reference: http://knucklecracker.com/wiki/doku.php?id=crpl:crplreference
 #============================================= #=============================================
 +
 +#======================================
 +#======== FORCEFIELD MANAGER ==========
 +#======================================
 +
 +# Sets the Forcefield properties.
 +# Order goes: RANGE CPUSH ACPUSH
 +# The higher the PUSH values the more the
 +# forcefield repels from the epicenter.
 +# Values are in millionths per unit of creeper moved.
 +# Notation: f1 i1 i2 -
 +# 12.5 100000 100000 @SetForcefieldProperties
 +:SetForcefieldProperties
 + -?FF_INITIALIZED not if
 + ->FF_ACPUSH
 + ->FF_CPUSH
 + ->FF_RANGE
 + true ->FF_INITIALIZED
 + -?FF_X or(-?FF_Y) not if
 + CurrentCoords ->FF_Y ->FF_X
 + endif
 + endif
 +
 +# Function :SetForcefieldCoords
 +# Sets the coordinates of future forcefields.
 +# If a previous forcefield was present it removes
 +# the old one and creates a new one.
 +# Notation: x y -
 +# e.g. CurrentCoords @SetForcefieldCoords
 +:SetForcefieldCoords
 + -?FORCEFIELD_AVAILABLE if
 + @WipeForcefield
 + ->FF_Y
 + ->FF_X
 + @CreateForcefield
 + else
 + ->FF_Y
 + ->FF_X
 + endif
 +
 +# Function :OverrideWipeForcefieldProperties
 +# By default initializing forcefield properties locks the
 +# method and helps prevent leftover forcefields.
 +:OverrideWipeForcefieldProperties
 + @WipeForcefield
 + 0 ->FF_ACPUSH
 + 0 ->FF_CPUSH
 + 0 ->FF_RANGE
 + --FF_INITIALIZED
 +
 +# Function :WipeForcefield
 +# Safe method to wipe forcefield, if there is none it will be ignored.
 +# Notation: -
 +# e.g. @WipeForcefield
 +:WipeForcefield
 + -?FF_INITIALIZED if
 + -?FORCEFIELD_AVAILABLE if
 + --FORCEFIELD_AVAILABLE
 + @ModifyForcefield(<-FF_X <-FF_Y <-FF_RANGE <-FF_CPUSH neg <-FF_ACPUSH neg)
 + endif
 + endif
 +
 +# Function :CreateForcefield
 +# Creates a Forcefield with the initialized parameters.
 +# Notation: -
 +# e.g. @CreateForcefield
 +:CreateForcefield
 + -?FF_INITIALIZED if
 + -?FORCEFIELD_AVAILABLE not if
 + true ->FORCEFIELD_AVAILABLE
 + @ModifyForcefield(<-FF_X <-FF_Y <-FF_RANGE <-FF_CPUSH <-FF_ACPUSH)
 + endif
 + endif
 +
 +# Major props to Tyler, thanks for helping make forcefields work as intended.
 +# Function :ModifyForcefield
 +# Adds input creeper and anti-creeper to surrounding field cells with
 +# strength decreasing with distance form the epicenter.
 +# Negative values will modify the forces in opposite directions and 0 will change nothing.
 +# Notation: x y f1 i1 i2 -
 +# e.g. CurrentCoords 10 100000 -100000 @ModifyForcefield
 +:ModifyForcefield
 +neg ->SF_ACPUSH
 +neg ->SF_CPUSH
 +asfloat ->SF_RANGE # float-value is required for the div operations
 +->SF_Y
 +->SF_X
 +
 +<-SF_RANGE 2 mul 1 add 0 
 +do
 + <-SF_RANGE 2 mul 1 add 0 
 + do
 + <-SF_X J add <-SF_RANGE sub ->xCell
 + <-SF_Y I add <-SF_RANGE sub ->yCell
 +
 + <-xCell neq(<-SF_X) or(<-yCell neq(<-SF_Y)) if
 + <-SF_X <-SF_Y <-xCell <-yCell Distance ->SF_DIST
 + <-SF_DIST lte(<-SF_RANGE) if
 + <-SF_DIST neg add(<-SF_RANGE) div(<-SF_RANGE) mul(0.7) add(0.3) ->SF_MOD
 + <-SF_ACPUSH mul(<-SF_MOD) asint ->SF_ACPUSHMOD
 + <-SF_CPUSH mul(<-SF_MOD) asint ->SF_CPUSHMOD
 + @GetVector(@GetAngle(<-xCell <-yCell <-SF_X <-SF_Y) <-SF_CPUSHMOD) ->cRLCell ->cUDCell
 + @GetVector(@GetAngle(<-xCell <-yCell <-SF_X <-SF_Y) <-SF_ACPUSHMOD) ->acUDCell ->acRLCell
 + GetFieldCell(<-xCell <-yCell) ->oacRLCell ->oacUDCell ->ocRLCell ->ocUDCell
 + SetFieldCell(<-xCell <-yCell <-cUDCell add(<-ocUDCell) <-cRLCell add(<-ocRLCell) <-acUDCell add(<-oacUDCell) <-acRLCell add(<-oacRLCell)) # n1, n2, n3 and n4 are for creeper U(+)/D(-), creeper R(+)/L(-), AC U/D and AC R/L
 + endif
 + endif
 + loop
 +loop
  
 #====================================== #======================================
Line 561: Line 675:
  <-uv_found  <-uv_found
  
 +# Function :GetCreeperInRadius
 +# Returns the SUM of all creeper in a certain square
 +# around an origin. If there is anti-creeper present this
 +# value may go into the negatives.
 +# Notation: x y f1 - f2
 +# eg. CurrentCoords 1 @GetCreeperInRadius ->sumcreepergrid3x3
 +:GetCreeperInRadius
 + ->CR_RAD
 + ->CR_Y
 + ->CR_X
 + 0 ->CR_C
 + <-CR_RAD mul(2) add(1) ->CR_LENGTH
 +
 + <-CR_LENGTH 0 do
 + <-CR_LENGTH 0 do
 + <-CR_Y I add <-CR_RAD sub ->CR_FY
 + <-CR_X J add <-CR_RAD sub ->CR_FX
 + <-CR_FX <-CR_FY GetCreeper add(<-CR_C) ->CR_C
 + loop
 + loop
 +
 + <-CR_C
 +
 # Function: :SetImageAlpha # Function: :SetImageAlpha
 # Sets the alpha of the specified image for self. # Sets the alpha of the specified image for self.
Line 636: Line 773:
  false  false
  
 +# Function :OccupyArea
 +# Safety net for @AddOccupy to prevent bad areas.
 +# Notation: x y f1 -
 +# eg. <-targetX <-targetY 1 @OccupyArea # this would occupy an area of land
 +# #in a 3x3 grid around the central point, useful for flying units looking to land
 +:OccupyArea
 + -?OA_OCCUPIED not if
 + # First occupation is legal.
 + ->OA_RAD
 + ->OA_Y
 + ->OA_X
 +
 + <-OA_X <-OA_Y <-OA_RAD true @AddOccupy
 + # Does occupy, is initialized.
 + true ->OA_OCCUPIED
 + else
 + <-OA_OCCUPIED if
 + # If occupying land already, disable occupation for re-assigning.
 + <-OA_X <-OA_Y <-OA_RAD false @AddOccupy
 + endif
 + ->OA_RAD
 + ->OA_Y
 + ->OA_X
 + <-OA_OCCUPY if
 + <-OA_X <-OA_Y <-OA_RAD true @AddOccupy
 + endif
 + <-OA_OCCUPY ->OA_OCCUPIED
 + endif
 +
 +:ReleaseOccupiedArea
 + <-OA_OCCUPIED if
 + # If occupying land already, disable occupation.
 + <-OA_X <-OA_Y <-OA_RAD false @AddOccupy
 + false ->OA_OCCUPIED
 + endif
 +
 # Function :AddOccupy # Function :AddOccupy
 # Returns whether or not a certain area is occupied by one or # Returns whether or not a certain area is occupied by one or
Line 641: Line 814:
 # Notation: x y f1 b1 - # Notation: x y f1 b1 -
 # eg. CurrentCoords 1 false @AddOccupy #this would allow another unit to land # eg. CurrentCoords 1 false @AddOccupy #this would allow another unit to land
-# #in a 3x3 grid around the centarl point.+# #in a 3x3 grid around the central point.
 :AddOccupy :AddOccupy
  ->OC_ADD  ->OC_ADD
Line 1006: Line 1179:
  <-rta_onTarget  <-rta_onTarget
  <-rta_rot  <-rta_rot
- 
 </code> </code>
crpl/crpltutorial/easycrpl.1428965930.txt.gz · Last modified: 2015/04/13 18:58 by Telanir