This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
4rpl:commands:setcelloccupiedcount [2021/09/15 14:53] – added another example Grabz | 4rpl:commands:setcelloccupiedcount [2025/02/14 14:57] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 13: | Line 13: | ||
Sets the occupied count for a map cell. Extreme caution must be exercised when using this command. Normally units will increase the count for cells they occupy when they land or are created. The units will also decrease the count by 1 whenever they take off or are destroyed. Messing with the count can create ' | Sets the occupied count for a map cell. Extreme caution must be exercised when using this command. Normally units will increase the count for cells they occupy when they land or are created. The units will also decrease the count by 1 whenever they take off or are destroyed. Messing with the count can create ' | ||
- | The effect of SetCellOccupiedCount does not persist between save and loads, as all units rebuild their cell occupied counts whenever the game is loaded and units are rebuilt from the save file. | + | The effect of SetCellOccupiedCount does not persist between save and loads, as all units rebuild their cell occupied counts whenever the game is loaded and units are rebuilt from the save file.\\ |
+ | :WARNING: This also applies to using this API in :Gameloaded and :Awake (when game is also loaded). This API will not function as desired should it be called in :Gameloaded or :Awake (:Awake will work fine when placing units, just not when units are loaded in). This is due to the game rebuilding cell occupy counts latter than :Awake and : | ||
+ | |||
+ | If you're trying to make a custom unit occupy cells in a custom shape rather than the default box shape, refer to [[cw4: | ||
===== Examples ===== | ===== Examples ===== | ||
Line 33: | Line 36: | ||
loop | loop | ||
loop | loop | ||
- | </ | ||
- | |||
- | ===== Handling all the cases ===== | ||
- | Here's an example of how to handle all the cases with setting custom occupied count on a unit. This is an example of a 9x9 unit that only wants the outer rim of the unit to occupy space, with a hollow middle. Make sure the unit is set to not occupy land in unit settings. | ||
- | <code 4rpl> | ||
- | :Awake | ||
- | once | ||
- | RegisterForMSG(" | ||
- | endonce | ||
- | :Once | ||
- | @Awake | ||
- | :PostUpdate | ||
- | Self GetUnitMoveCell pop -> | ||
- | Self GetUnitCell ->POU_iZ ->POU_iX | ||
- | |||
- | #If a movable unit is moved by the player | ||
- | #Remove custom occupied cells when the unit takes off | ||
- | #Add them back when the unit has landed | ||
- | < | ||
- | < | ||
- | Self GetUnitCell TRUE @SetCustomOccupiedLand | ||
- | else | ||
- | Self GetUnitCell FALSE @SetCustomOccupiedLand | ||
- | endif | ||
- | #Update occupied count when the unit is forcibly moved in the editor | ||
- | #Only occurs when the unit is landed | ||
- | else < | ||
- | < | ||
- | < | ||
- | < | ||
- | endif | ||
- | endif endif | ||
- | |||
- | < | ||
- | < | ||
- | #i1 i2 b3 - | ||
- | #Uniformly set or unset a chunk of occupied land | ||
- | #Arguments: CellX and CellY of the last position (if unsetting) or current position (if setting), | ||
- | # | ||
- | #Result: None | ||
- | : | ||
- | -> | ||
- | 4 -> | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | I J GetCellOccupiedCount -> | ||
- | < | ||
- | I J < | ||
- | else | ||
- | I J < | ||
- | endif | ||
- | endif | ||
- | loop | ||
- | loop | ||
</ | </ | ||
< | < |