This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
crpl:crpltutorial:easycrpl [2015/04/13 13:51] – created Karsten75 | crpl:crpltutorial:easycrpl [2025/02/14 14:57] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ==== EasyCRPL ==== | + | < |
+ | |||
+ | ===== EasyCRPL ===== | ||
+ | == Version 1.1 == | ||
+ | |||
+ | |||
+ | <code 4rpl># | ||
+ | # ===== :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 | ||
+ | # project to get the full benefits of the pre-written code. | ||
+ | # You can also just copy-paste parts of this you need. | ||
+ | # | ||
+ | # EasyCRPL is a collection of scripts from various community | ||
+ | # projects, members, and maps that have been created by myself | ||
+ | # or modified to meet a more generic purpose. | ||
+ | # | ||
+ | # ----- | ||
+ | # A List of all available functions and their notation: | ||
+ | # @FunctionName: | ||
+ | # x - X coordinate | ||
+ | # y - Y coordinate | ||
+ | # n - numerical value | ||
+ | # i - integer value | ||
+ | # f - float value | ||
+ | # b - boolean value | ||
+ | # s - string value | ||
+ | # u - unit id, integer value | ||
+ | # L - list | ||
+ | # * - any value | ||
+ | # | ||
+ | # NOTE: Non-pixel coords are flipped vertically | ||
+ | # with (0,0) being top-left, whereas pixel (0,0) | ||
+ | # is the bottom left. | ||
+ | # | ||
+ | # -- Special Code -- | ||
+ | # This code can be used at any time if it is in your | ||
+ | # script, and generally comes in blocks of functions. | ||
+ | # Forcefield Manager: A custom forcefield manager that helps safely create functional forcefields. | ||
+ | # @SetForcefieldProperties: | ||
+ | # | ||
+ | # List-Builder: | ||
+ | # @BeginList [* *...] @BuildList | ||
+ | # @DoesListContain: | ||
+ | # | ||
+ | # Pre-Built Beam: A beam with a customizable color, alpha, and width. | ||
+ | # @SetBeamProperties: | ||
+ | # @AnimateBeam: | ||
+ | # @SetBeamTarget: | ||
+ | # @TargetBeam: | ||
+ | # @DestroyBeam: | ||
+ | # | ||
+ | # -- Various Convenience Methods -- | ||
+ | # | ||
+ | # SPECIAL METHODS, READ COMMENTS ABOVE CODE | ||
+ | # -- | ||
+ | # @GetClosestUnit: | ||
+ | # @GetAllUnits: | ||
+ | # @CRPLMatchesValue: | ||
+ | # -- | ||
+ | # | ||
+ | # @GetCreeperInRadius: | ||
+ | # @SetImageAlpha: | ||
+ | # @TerrainAccessible: | ||
+ | # @AreaOccupied: | ||
+ | # @AddOccupy: x y i1 b1 - | ||
+ | # -- Cell-Related Code -- | ||
+ | # @UnitCoords: | ||
+ | # @MovePosition: | ||
+ | # @GetVector: f1 f2 - x y | ||
+ | # @NormalizeVector: | ||
+ | # @GetLength: x y - f1 | ||
+ | # @GetAngle: x y x2 y2 - f1 | ||
+ | # @RotateToAngle: | ||
+ | # @IsPointOnMap: | ||
+ | # -- Pixel-Related Code -- | ||
+ | # @UnitPixelCoords: | ||
+ | # @SetPixelCoords: | ||
+ | # @MovePixelPosition: | ||
+ | # @GetPixelVector: | ||
+ | # @GetPixelAngle: | ||
+ | # @RotateToPixelAngle: | ||
+ | # | ||
+ | # Wiki CRPL Reference: http:// | ||
+ | # | ||
+ | |||
+ | # | ||
+ | #======== 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 | ||
+ | : | ||
+ | -? | ||
+ | -> | ||
+ | -> | ||
+ | -> | ||
+ | true -> | ||
+ | -?FF_X or(-?FF_Y) not if | ||
+ | CurrentCoords ->FF_Y ->FF_X | ||
+ | endif | ||
+ | endif | ||
+ | |||
+ | # Function : | ||
+ | # 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 | ||
+ | : | ||
+ | -? | ||
+ | @WipeForcefield | ||
+ | -> | ||
+ | -> | ||
+ | @CreateForcefield | ||
+ | else | ||
+ | -> | ||
+ | -> | ||
+ | endif | ||
+ | |||
+ | # Function : | ||
+ | # By default initializing forcefield properties locks the | ||
+ | # method and helps prevent leftover forcefields. | ||
+ | : | ||
+ | @WipeForcefield | ||
+ | 0 -> | ||
+ | 0 -> | ||
+ | 0 -> | ||
+ | --FF_INITIALIZED | ||
+ | |||
+ | # Function : | ||
+ | # Safe method to wipe forcefield, if there is none it will be ignored. | ||
+ | # Notation: - | ||
+ | # e.g. @WipeForcefield | ||
+ | : | ||
+ | -? | ||
+ | -? | ||
+ | --FORCEFIELD_AVAILABLE | ||
+ | @ModifyForcefield(< | ||
+ | endif | ||
+ | endif | ||
+ | |||
+ | # Function : | ||
+ | # Creates a Forcefield with the initialized parameters. | ||
+ | # Notation: - | ||
+ | # e.g. @CreateForcefield | ||
+ | : | ||
+ | -? | ||
+ | -? | ||
+ | true -> | ||
+ | @ModifyForcefield(< | ||
+ | endif | ||
+ | endif | ||
+ | |||
+ | # Major props to Tyler, thanks for helping make forcefields work as intended. | ||
+ | # Function : | ||
+ | # 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 | ||
+ | : | ||
+ | neg -> | ||
+ | neg -> | ||
+ | asfloat -> | ||
+ | ->SF_Y | ||
+ | ->SF_X | ||
+ | |||
+ | < | ||
+ | do | ||
+ | < | ||
+ | do | ||
+ | <-SF_X J add < | ||
+ | <-SF_Y I add < | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | @GetVector(@GetAngle(< | ||
+ | @GetVector(@GetAngle(< | ||
+ | GetFieldCell(< | ||
+ | SetFieldCell(< | ||
+ | endif | ||
+ | endif | ||
+ | loop | ||
+ | loop | ||
+ | |||
+ | # | ||
+ | # | ||
+ | # | ||
+ | |||
+ | # How to use: | ||
+ | # If you ever need to quickly build a list of X units then | ||
+ | # you can use these two functions to do it in one line. | ||
+ | # You can use this in conjuction with @DoesListContain listed in the index. | ||
+ | # e.g. @BeginList " | ||
+ | |||
+ | : | ||
+ | StackSize ->BL_I | ||
+ | |||
+ | : | ||
+ | StackSize ->BL_M | ||
+ | CreateList ->BL_L | ||
+ | <-BL_M <-BL_I do | ||
+ | -> | ||
+ | <-BL_L <-BL_O PrependToList | ||
+ | loop | ||
+ | < | ||
+ | |||
+ | # Function : | ||
+ | # This function an object, then a list and returns a boolean value. | ||
+ | # Notation: L1 n1 - b1 | ||
+ | # eg. <-myList < | ||
+ | : | ||
+ | -> | ||
+ | -> | ||
+ | false -> | ||
+ | |||
+ | < | ||
+ | < | ||
+ | true -> | ||
+ | break | ||
+ | endif | ||
+ | loop | ||
+ | |||
+ | < | ||
+ | |||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # How to use: | ||
+ | # Copy the 4 beam methods into your code. | ||
+ | # @AnimateBeam needs to run /every/ script invocation. | ||
+ | # Use @SetBeamProperties at any time to change the | ||
+ | # appearence of the beam. | ||
+ | # Use @TargetBeam at any time to focus the beam on something, | ||
+ | # if it is moving, keep calling @TargetBeam. | ||
+ | # When finished, call @DestroyBeam and the beam will vanish! | ||
+ | # | ||
+ | # Warning: DO NOT USE @BeamInit! | ||
+ | |||
+ | # Function: : | ||
+ | # Sets the properties of the beam. | ||
+ | # Alpha, red, green, and blue range from 0 - 255 | ||
+ | # With 0 being transparent and 255 being opaque | ||
+ | # The string is the " | ||
+ | # http:// | ||
+ | # The two integers after the image name are the indexes for | ||
+ | # the damage icons. If your " | ||
+ | # then if your " | ||
+ | # Notation: s1 i1 i2 i3 i4 i5 i6 f1 - | ||
+ | # eg. " | ||
+ | : | ||
+ | -> | ||
+ | -> | ||
+ | -> | ||
+ | -> | ||
+ | -> | ||
+ | -> | ||
+ | -> | ||
+ | -> | ||
+ | true -> | ||
+ | -? | ||
+ | @BeamInit | ||
+ | endif | ||
+ | |||
+ | # Function: : | ||
+ | # Animates the beam and the explosion animation. | ||
+ | # The boolean indicates whether it is a pixel position. | ||
+ | # Notation: - | ||
+ | # eg. @AnimateBeam | ||
+ | : | ||
+ | -? | ||
+ | if(< | ||
+ | < | ||
+ | else | ||
+ | < | ||
+ | endif | ||
+ | |||
+ | -?BM_T if | ||
+ | GetUnitType(< | ||
+ | if(< | ||
+ | < | ||
+ | endif | ||
+ | if(< | ||
+ | < | ||
+ | endif | ||
+ | endif | ||
+ | |||
+ | self CONST_PIXELCOORDX GetUnitAttribute -> | ||
+ | self CONST_PIXELCOORDY GetUnitAttribute -> | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | <-BM_D 24 div -> | ||
+ | |||
+ | < | ||
+ | < | ||
+ | |||
+ | SetImagePosition(self " | ||
+ | SetImageScaleX(self " | ||
+ | SetImageRotation(self " | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | SetImage(self " | ||
+ | SetImagePosition(self " | ||
+ | endif | ||
+ | endif | ||
+ | |||
+ | # Function: : | ||
+ | # The purpose of this function is for the main | ||
+ | # @AnimateBeam function to be aware if the target | ||
+ | # is a certain type of unit. It will automatically | ||
+ | # make corrections for flying units. | ||
+ | # Use -1 if the target is a non-unit. | ||
+ | : | ||
+ | -> | ||
+ | <-BT_T eq(-1) if | ||
+ | --BM_T | ||
+ | else | ||
+ | <-BT_T ->BM_T | ||
+ | endif | ||
+ | |||
+ | # Function: : | ||
+ | # Focuses the beam on a target location. | ||
+ | # If a beam does not exist, makes one. | ||
+ | # The boolean value indicates whether or not the | ||
+ | # new position is a pixel position. | ||
+ | # IF THE ENEMY IS AN ' | ||
+ | # YOU MUST USE @SetBeamTarget TO CORRECT THE Y-OFFSET. | ||
+ | # Notation: x y b1 - | ||
+ | # eg. @UnitCoords(< | ||
+ | # eg. 100 100 true @TargetBeam | ||
+ | : | ||
+ | -> | ||
+ | -> | ||
+ | -> | ||
+ | -?BM_SET not if | ||
+ | # Set some default values. | ||
+ | " | ||
+ | endif | ||
+ | < | ||
+ | true -> | ||
+ | @BeamInit | ||
+ | endif | ||
+ | |||
+ | # Function: : | ||
+ | # Removes the active beam, if there is one. | ||
+ | # Notation: - | ||
+ | # eg. @DestroyBeam | ||
+ | : | ||
+ | -? | ||
+ | --BM_ACTIVE | ||
+ | self " | ||
+ | self " | ||
+ | endif | ||
+ | |||
+ | # Function: :BeamInit | ||
+ | # Used by the Beam script to update Beam appearance. | ||
+ | :BeamInit | ||
+ | self " | ||
+ | self " | ||
+ | self " | ||
+ | self " | ||
+ | |||
+ | # | ||
+ | #==== VARIOUS CONVENIENCE METHODS ===== | ||
+ | # | ||
+ | |||
+ | # Function : | ||
+ | # WARNING: use this convenience function sparingly, tens of CRPL Cores | ||
+ | # running this all at once every frame will slow the game down significantly. | ||
+ | # | ||
+ | # This function uses a flexible algorithm to filter | ||
+ | # units within a certain distance and retrieve the one | ||
+ | # closest to the position given to the function. | ||
+ | # It requires a position, a maximum distance, and an | ||
+ | # instruction list. | ||
+ | # | ||
+ | # The instruction list can contain multiple objects (but at least one is needed). | ||
+ | # An instruction follows this format: " | ||
+ | # All applicable unit types can be found on: | ||
+ | # https:// | ||
+ | # | ||
+ | # The following parameters are acceptable: | ||
+ | # LANDED BUILT RANK=value | ||
+ | # LANDED and BUILT can accept modifiers. * means __either__, - means NOT, no modifier means IS | ||
+ | # If the parameter is none of the three, and the unit type is defined as " | ||
+ | # parameter type is a CRPLCore variable which is defined like so: myVar=myVal | ||
+ | # | ||
+ | # The unit type can be substituted by ALL which will affect all instructions, | ||
+ | # beginning of the list or it will be assumed to be a unit type. | ||
+ | # ALL does not accept RANK or script variables as parameters. | ||
+ | # | ||
+ | # == EXAMPLE == | ||
+ | # @BeginList " | ||
+ | # CurrentCoords 50 < | ||
+ | # | ||
+ | # Explanation: | ||
+ | # case sensitive is when defining script parameters. CONST_ISLANDED and CONST_ISBUILDING do not affect CRPLCores. | ||
+ | # According to these instructions, | ||
+ | # any relay that is built or not but we give the a half the normal rank so the algorithm will treat them as if | ||
+ | # they are twice the distance away from anything else in the way. A collector and relay at the same distance will | ||
+ | # always return the collector. Next we prioritize any flying pulse cannon and override the ALL parameter, we | ||
+ | # then also look for any CRPLCores we made that had a script variable of " | ||
+ | # | ||
+ | # Notation: x y f1 L1 - u | ||
+ | # e.g. CurrentCoords 50 < | ||
+ | : | ||
+ | -> | ||
+ | asfloat -> | ||
+ | asfloat ->un_y | ||
+ | asfloat ->un_x | ||
+ | |||
+ | -1 -> | ||
+ | -1 -> | ||
+ | |||
+ | <-un_x <-un_y < | ||
+ | < | ||
+ | < | ||
+ | -> | ||
+ | < | ||
+ | # GET INSTRUCTION FOR THIS UNIT TYPE | ||
+ | < | ||
+ | < | ||
+ | # found correct instruction | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | |||
+ | # now we apply the priority and get the closest unit | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | endif | ||
+ | break | ||
+ | endif | ||
+ | loop | ||
+ | loop | ||
+ | endif | ||
+ | < | ||
+ | |||
+ | # Function : | ||
+ | # Grabs all units of specified instruction within a radius of | ||
+ | # a given point. Read : | ||
+ | # Notation: x y f1 L1 - [u1 u2...]i1 | ||
+ | # e.g. | ||
+ | # CurrentCoords 50 < | ||
+ | # < | ||
+ | # # code here | ||
+ | # loop | ||
+ | : | ||
+ | -> | ||
+ | asfloat -> | ||
+ | asfloat ->un_y | ||
+ | asfloat ->un_x | ||
+ | |||
+ | CreateList -> | ||
+ | --un_all_landed | ||
+ | --un_all_built | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | false -> | ||
+ | else | ||
+ | true -> | ||
+ | endif | ||
+ | endif | ||
+ | < | ||
+ | < | ||
+ | false -> | ||
+ | else | ||
+ | true -> | ||
+ | endif | ||
+ | endif | ||
+ | loop | ||
+ | endif | ||
+ | endif | ||
+ | |||
+ | CreateList -> | ||
+ | < | ||
+ | "" | ||
+ | "" | ||
+ | 1.0 ->rank | ||
+ | |||
+ | --un_landed_req | ||
+ | --un_built_req | ||
+ | |||
+ | -? | ||
+ | -? | ||
+ | |||
+ | < | ||
+ | < | ||
+ | |||
+ | < | ||
+ | |||
+ | < | ||
+ | "" | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | true -> | ||
+ | < | ||
+ | < | ||
+ | false -> | ||
+ | else | ||
+ | true -> | ||
+ | endif | ||
+ | < | ||
+ | --un_landed_req | ||
+ | endif | ||
+ | false -> | ||
+ | endif | ||
+ | < | ||
+ | < | ||
+ | false -> | ||
+ | else | ||
+ | true -> | ||
+ | endif | ||
+ | < | ||
+ | --un_built_req | ||
+ | endif | ||
+ | false -> | ||
+ | endif | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | false -> | ||
+ | endif | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | endif | ||
+ | loop | ||
+ | endif | ||
+ | # 2 means not applicable | ||
+ | < | ||
+ | -? | ||
+ | < | ||
+ | -? | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | loop | ||
+ | |||
+ | <-un_x <-un_y < | ||
+ | < | ||
+ | < | ||
+ | -> | ||
+ | < | ||
+ | < | ||
+ | # GET INSTRUCTION FOR THIS UNIT TYPE | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | --une_built | ||
+ | --une_landed | ||
+ | # 0 is the type | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | |||
+ | false ->skip | ||
+ | < | ||
+ | 4 -> | ||
+ | while < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | true ->skip | ||
+ | endif | ||
+ | endwhile | ||
+ | endif | ||
+ | not(< | ||
+ | # MATCH VALUES | ||
+ | < | ||
+ | -? | ||
+ | endif | ||
+ | < | ||
+ | -? | ||
+ | endif | ||
+ | not(< | ||
+ | < | ||
+ | endif | ||
+ | endif | ||
+ | break | ||
+ | endif | ||
+ | loop | ||
+ | endif | ||
+ | loop | ||
+ | endif | ||
+ | < | ||
+ | < | ||
+ | loop | ||
+ | < | ||
+ | |||
+ | : | ||
+ | -> | ||
+ | # list of what DOESN' | ||
+ | -? | ||
+ | @BeginList | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | @BuildList -> | ||
+ | endif | ||
+ | not(< | ||
+ | |||
+ | : | ||
+ | -> | ||
+ | # list of what DOES | ||
+ | -? | ||
+ | @BeginList | ||
+ | " | ||
+ | @BuildList -> | ||
+ | endif | ||
+ | < | ||
+ | |||
+ | # Function : | ||
+ | # Takes a unit, a value and a variable and determines | ||
+ | # without a given script whether or not the CRPLCore | ||
+ | # has a variable with that value. | ||
+ | # Notation: u s1 * - b1 | ||
+ | # e.g. self " | ||
+ | : | ||
+ | -> | ||
+ | -> | ||
+ | -> | ||
+ | false -> | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | -> | ||
+ | < | ||
+ | true -> | ||
+ | endif | ||
+ | loop | ||
+ | endif | ||
+ | < | ||
+ | |||
+ | # Function : | ||
+ | # 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 -> | ||
+ | : | ||
+ | -> | ||
+ | -> | ||
+ | -> | ||
+ | 0 ->CR_C | ||
+ | < | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | loop | ||
+ | loop | ||
+ | |||
+ | < | ||
+ | |||
+ | # Function: : | ||
+ | # Sets the alpha of the specified image for self. | ||
+ | # Alpha ranges from 0 - 255 with 0 transparent and 255 opaque | ||
+ | # Notation: s1 i1 - | ||
+ | # eg. " | ||
+ | : | ||
+ | asint -> | ||
+ | -> | ||
+ | self < | ||
+ | self < | ||
+ | |||
+ | # Function : | ||
+ | # Returns whether or not there is smooth terrain available | ||
+ | # of equivalent height in a certain area of specified radius. | ||
+ | # Radius is measured in cells. | ||
+ | # Area of radius 0 is 1 cell, area of radius 1 is 9 cells, etc. | ||
+ | # Notation: x y i1 - b1 | ||
+ | # eg. 10 10 5 @TerrainAccessible -> | ||
+ | : | ||
+ | -> | ||
+ | -> | ||
+ | -> | ||
+ | |||
+ | -1 -> | ||
+ | < | ||
+ | < | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | false | ||
+ | return | ||
+ | else | ||
+ | < | ||
+ | < | ||
+ | else | ||
+ | < | ||
+ | false | ||
+ | return | ||
+ | else | ||
+ | endif | ||
+ | endif | ||
+ | endif | ||
+ | loop | ||
+ | loop | ||
+ | true | ||
+ | |||
+ | # Function : | ||
+ | # Returns whether or not a certain area is occupied by one or | ||
+ | # more other units. Radius is measured in cells. | ||
+ | # Notation: x y i1 - b1 | ||
+ | # eg. 10 10 5 @AreaOccupied -> | ||
+ | : | ||
+ | -> | ||
+ | -> | ||
+ | -> | ||
+ | |||
+ | < | ||
+ | < | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | true | ||
+ | return | ||
+ | endif | ||
+ | loop | ||
+ | loop | ||
+ | false | ||
+ | |||
+ | # Function : | ||
+ | # Safety net for @AddOccupy to prevent bad areas. | ||
+ | # Notation: x y f1 - | ||
+ | # eg. < | ||
+ | # #in a 3x3 grid around the central point, useful for flying units looking to land | ||
+ | : | ||
+ | -? | ||
+ | # First occupation is legal. | ||
+ | -> | ||
+ | -> | ||
+ | -> | ||
+ | |||
+ | <-OA_X <-OA_Y <-OA_RAD true @AddOccupy | ||
+ | # Does occupy, is initialized. | ||
+ | true -> | ||
+ | else | ||
+ | < | ||
+ | # If occupying land already, disable occupation for re-assigning. | ||
+ | < | ||
+ | endif | ||
+ | -> | ||
+ | -> | ||
+ | -> | ||
+ | < | ||
+ | < | ||
+ | endif | ||
+ | < | ||
+ | endif | ||
+ | |||
+ | : | ||
+ | < | ||
+ | # If occupying land already, disable occupation. | ||
+ | <-OA_X <-OA_Y <-OA_RAD false @AddOccupy | ||
+ | false -> | ||
+ | endif | ||
+ | |||
+ | # Function : | ||
+ | # Returns whether or not a certain area is occupied by one or | ||
+ | # more other units. Radius is measured in cells. | ||
+ | # Notation: x y f1 b1 - | ||
+ | # eg. CurrentCoords 1 false @AddOccupy #this would allow another unit to land | ||
+ | # #in a 3x3 grid around the central point. | ||
+ | : | ||
+ | -> | ||
+ | -> | ||
+ | -> | ||
+ | -> | ||
+ | |||
+ | < | ||
+ | < | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | else | ||
+ | < | ||
+ | endif | ||
+ | loop | ||
+ | loop | ||
+ | |||
+ | # | ||
+ | #========= CELL RELATED CODE ========== | ||
+ | # | ||
+ | |||
+ | # Function : | ||
+ | # Simple convenience method. Takes a unit and returns the coordinates. | ||
+ | # ' | ||
+ | # Notation: n1 - x y | ||
+ | # eg. < | ||
+ | : | ||
+ | asint ->uc_u | ||
+ | <-uc_u CONST_COORDX GetUnitAttribute | ||
+ | <-uc_u CONST_COORDY GetUnitAttribute | ||
+ | |||
+ | # Function : | ||
+ | # Simple convenience method. Sets current units pixel coordinates. | ||
+ | # Notation: x y - | ||
+ | # eg. x y u @SetPixelCoords | ||
+ | : | ||
+ | -> | ||
+ | asfloat ->sp_y | ||
+ | asfloat ->sp_x | ||
+ | SetUnitAttribute(< | ||
+ | SetUnitAttribute(< | ||
+ | |||
+ | # Function : | ||
+ | # Uses the given position, angle, and speed and returns a new position. | ||
+ | # The target position is used for correctional purposes so that it doesn' | ||
+ | # If you want to ignore the correctional functionality set the target coordinates to -5000 -5000. | ||
+ | # Notation: x y x2 y2 f1 f2 - x y | ||
+ | # eg. CurrentCoords < | ||
+ | : | ||
+ | asfloat -> | ||
+ | asfloat -> | ||
+ | asfloat -> | ||
+ | asfloat -> | ||
+ | asfloat -> | ||
+ | asfloat -> | ||
+ | |||
+ | <-mp_an <-mp_ms @GetVector ->mp_vY -> | ||
+ | |||
+ | <-mp_pX <-mp_tX sub <-mp_pY <-mp_tY sub @GetLength <-mp_ms lt if | ||
+ | < | ||
+ | < | ||
+ | else | ||
+ | < | ||
+ | < | ||
+ | endif | ||
+ | |||
+ | # Function : | ||
+ | # Uses two points and a distance to find a position that is | ||
+ | # between the two points, but X distance away from the target. | ||
+ | # Negative distances will go beyond the target. | ||
+ | # Notation: x y x2 y2 f1 - x y | ||
+ | # eg. CurrentPosition @GetUnitCoords(< | ||
+ | : | ||
+ | asfloat -> | ||
+ | asfloat -> | ||
+ | asfloat -> | ||
+ | asfloat -> | ||
+ | asfloat -> | ||
+ | |||
+ | < | ||
+ | <-gip_a < | ||
+ | < | ||
+ | < | ||
+ | |||
+ | # Function : | ||
+ | # Uses an angle, and speed and returns a vector | ||
+ | # You can add the vector to a position to get a moving effect | ||
+ | # Notation: f1 f2 - x y | ||
+ | # eg. <-angle 1.5 @GetVector ->y ->x | ||
+ | : | ||
+ | asfloat -> | ||
+ | asfloat -> | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | |||
+ | # Function : | ||
+ | # Takes an (x,y) coordinate and returns it in terms of 0 to 1, | ||
+ | # with 1 being the maximum length (traveling directly up/down or left/ | ||
+ | # and 0 being the minimum. | ||
+ | # Notation: x y - x y | ||
+ | # eg. < | ||
+ | : | ||
+ | asfloat -> | ||
+ | asfloat -> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | |||
+ | # Function : | ||
+ | # Takes a width and height and calculates a length. | ||
+ | # Notation: x y - f1 | ||
+ | # eg. 4 3 @GetLength ->length #(will return 5) | ||
+ | : | ||
+ | asfloat -> | ||
+ | asfloat -> | ||
+ | < | ||
+ | |||
+ | # Function :GetAngle | ||
+ | # Takes an initial position and a target position, | ||
+ | # then calculates an angle to face the target. | ||
+ | # Value returned in radians. | ||
+ | # Notation: x y x2 y2 - f1 | ||
+ | # eg. CurrentCoords < | ||
+ | :GetAngle | ||
+ | asfloat -> | ||
+ | asfloat -> | ||
+ | asfloat -> | ||
+ | asfloat -> | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | |||
+ | # Function : | ||
+ | # Takes an initial position and a target position, | ||
+ | # calculates an angle, and then returns an angle | ||
+ | # restricted by the specified speed and angle. | ||
+ | # This function can allow for slow rotations. | ||
+ | # It will also return a boolean value which is | ||
+ | # true if the angle directly faces the target. | ||
+ | # Notation: x y x2 y2 f1 f2 - b1 f1 | ||
+ | # eg. CurrentCoords < | ||
+ | : | ||
+ | asfloat -> | ||
+ | asfloat -> | ||
+ | asfloat -> | ||
+ | asfloat -> | ||
+ | asfloat -> | ||
+ | asfloat -> | ||
+ | |||
+ | < | ||
+ | #(vertical 0 is TOP-left) | ||
+ | #cell-y is flipped so we instead subtract target-y from current-y | ||
+ | < | ||
+ | < | ||
+ | |||
+ | < | ||
+ | |||
+ | < | ||
+ | < | ||
+ | else | ||
+ | < | ||
+ | < | ||
+ | endif | ||
+ | endif | ||
+ | |||
+ | < | ||
+ | 1 -> | ||
+ | else | ||
+ | 0 -> | ||
+ | endif | ||
+ | |||
+ | < | ||
+ | |||
+ | < | ||
+ | < | ||
+ | |||
+ | # Function : | ||
+ | # Takes a set of cell-coordinates and returns true | ||
+ | # if the coordinates are on the map. | ||
+ | # Notation: x y - b1 | ||
+ | # eg. -1 -1 @IsPointOnMap ->onMap #(will return false) | ||
+ | : | ||
+ | -> | ||
+ | -> | ||
+ | 1 -> | ||
+ | < | ||
+ | 0 -> | ||
+ | endif | ||
+ | < | ||
+ | 0 -> | ||
+ | endif | ||
+ | < | ||
+ | 0 -> | ||
+ | endif | ||
+ | < | ||
+ | 0 -> | ||
+ | endif | ||
+ | < | ||
+ | |||
+ | # | ||
+ | #========= PIXEL RELATED CODE ========= | ||
+ | # | ||
+ | |||
+ | # Function : | ||
+ | # Simple convenience method. Takes a unit and returns the pixel coordinates. | ||
+ | # ' | ||
+ | # Notation: u - x y | ||
+ | # eg. < | ||
+ | : | ||
+ | asint ->uc_u | ||
+ | <-uc_u CONST_PIXELCOORDX GetUnitAttribute | ||
+ | <-uc_u CONST_PIXELCOORDY GetUnitAttribute | ||
+ | |||
+ | # Function : | ||
+ | # Simple convenience method. Sets current units pixel coordinates. | ||
+ | # Notation: u x y - | ||
+ | # eg. <-unit 10 10 @SetPixelCoords | ||
+ | : | ||
+ | asfloat ->sp_y | ||
+ | asfloat ->sp_x | ||
+ | -> | ||
+ | SetUnitAttribute(< | ||
+ | SetUnitAttribute(< | ||
+ | |||
+ | # Function : | ||
+ | # Simple convenience method. Sets current units pixel coordinates. | ||
+ | # Notation: x y - | ||
+ | # eg. x y @SetPixelCoords | ||
+ | : | ||
+ | asfloat ->sp_y | ||
+ | asfloat ->sp_x | ||
+ | SetUnitAttribute(self CONST_PIXELCOORDX < | ||
+ | SetUnitAttribute(self CONST_PIXELCOORDY < | ||
+ | |||
+ | # Function : | ||
+ | # Uses the given position, angle, and speed and returns a new position. | ||
+ | # The target position is used for correctional purposes so that it doesn' | ||
+ | # Notation: x y x2 y2 f1 f2 - x y | ||
+ | # eg. CurrentPixelCoords < | ||
+ | : | ||
+ | asfloat -> | ||
+ | asfloat -> | ||
+ | asfloat -> | ||
+ | asfloat -> | ||
+ | asfloat -> | ||
+ | asfloat -> | ||
+ | |||
+ | <-mp_an <-mp_ms @GetPixelVector ->mp_vY -> | ||
+ | |||
+ | <-mp_pX <-mp_tX sub <-mp_pY <-mp_tY sub @GetLength <-mp_ms lt if | ||
+ | < | ||
+ | < | ||
+ | else | ||
+ | < | ||
+ | < | ||
+ | endif | ||
+ | |||
+ | # Function : | ||
+ | # Uses two points and a distance to find a position that is | ||
+ | # between the two points, but X distance away from the target. | ||
+ | # Notation: x y x2 y2 f1 - x y | ||
+ | # eg. CurrentPixelPosition @GetUnitPixelCoords(< | ||
+ | : | ||
+ | asfloat -> | ||
+ | asfloat -> | ||
+ | asfloat -> | ||
+ | asfloat -> | ||
+ | asfloat -> | ||
+ | |||
+ | < | ||
+ | <-gip_a < | ||
+ | < | ||
+ | < | ||
+ | |||
+ | # Function : | ||
+ | # Uses an angle, and speed and returns a vector | ||
+ | # You can add the vector to a position to get a moving effect | ||
+ | # Notation: f1 f2 - x y | ||
+ | # eg. <-angle 1.5 @GetPixelVector ->y ->x | ||
+ | : | ||
+ | asfloat -> | ||
+ | asfloat -> | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | |||
+ | # Function : | ||
+ | # Takes an initial position and a target position, | ||
+ | # then calculates an angle to face the target. | ||
+ | # Value returned in radians. | ||
+ | # Notation: x y x2 y2 - f1 | ||
+ | # eg. CurrentPixelCoords < | ||
+ | : | ||
+ | asfloat -> | ||
+ | asfloat -> | ||
+ | asfloat -> | ||
+ | asfloat -> | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | |||
+ | # Function : | ||
+ | # Takes an initial position and a target position, | ||
+ | # calculates an angle, and then returns an angle | ||
+ | # restricted by the specified speed and angle. | ||
+ | # This function can allow for slow rotations. | ||
+ | # It will also return a boolean value which is | ||
+ | # true if the angle directly faces the target. | ||
+ | # Notation: x y x2 y2 f1 f2 - b1 f1 | ||
+ | # eg. CurrentPixelCoords < | ||
+ | : | ||
+ | asfloat -> | ||
+ | asfloat -> | ||
+ | asfloat -> | ||
+ | asfloat -> | ||
+ | asfloat -> | ||
+ | asfloat -> | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | |||
+ | < | ||
+ | |||
+ | < | ||
+ | < | ||
+ | else | ||
+ | < | ||
+ | < | ||
+ | endif | ||
+ | endif | ||
+ | |||
+ | < | ||
+ | 1 -> | ||
+ | else | ||
+ | 0 -> | ||
+ | endif | ||
+ | |||
+ | < | ||
+ | |||
+ | < | ||
+ | < | ||
+ | </ |