CustomSporeTower image

Started by stewbasic, May 21, 2014, 08:08:34 PM

Previous topic - Next topic

stewbasic

If I set a core's image to "CustomSporeTower", it displays as an unbuilt spore tower. Is there a trick to make it display as built? Or is the built spore tower image available somewhere?

I also considered creating a spore tower under the core, but I don't know if the popup text and timer can be suppressed.

Grayzzur

If you want a custom CRPL unit's image to be animated, you have to apply the various sub images and do the animation yourself in CRPL. You also can't hook in to the built-in spore warning bar and the actual game's spore sounds aren't in the custom sounds you can play, so there's currently no way to emulate it perfectly. I played with emulating a spore tower back in October. This doesn't include the new popup notifier in the latest version, but that could probably be added easily. Ultimately, I wouldn't recommend doing a custom spore tower mainly because of all the built-in game functionality that a user would expect that you can't mimic. It would be better to have a custom unit that looks quite different so that the lack of integration with the sounds and warning bar doesn't confuse them. This should give you an idea of what you can do to animate a CRPL unit, though.

Set Custom4 to SporeTowerFlower and Custom5 to SporeCirclePulse (or put them where you want and edit the first script). The helper script needs to be in your project, but not attached to a core (my way of getting two lines of popup text). You can set one of these up next to a real spore tower with the same parameters and watch how they both behave. Note that this still uses the CustomSporeTower image as it's base image, and animates the "flower" on top of it. I've attached my crude flower and circle-pulse graphics, as the game's spore tower parts aren't currently available on the wiki.

SporeTower.cprl

# SporeTower.crpl
# Created on: 10/23/2013 2:54:58 PM
# Author: Grayzzur
# ------------------------------------------
# Attempt to roughly approximate a standard spore tower as a CRPL Core
# If you modify and use this script, please keep the following note in
# the comments:
# Based on SporeTower.crpl and SporeTowerHelper.crpl by Grayzzur
# Original scripts available at ________
#
# Purpose: Learn CRPL, provide platform for custom modified spore towers,
# help other map makers build challenging maps
#
# Discrepancies:
# * The flower and red circles are not exact images. I had to make them, as I could
#   not locate the originals. They are close enough for demonstration, and can be
#   easily swapped out later.
# * Sounds: The 60-second warning and firing siren sounds do not appear to be available
#   to CRPL scripting at this time.
# * Target selection: not sure how the game engine does it, this unit just uses
#   RandUnitCoords for each spore.
# * Doesn't display incoming spores in the red spore count warning bar above the command panel.
#   I have some ideas on how to make a custom spore warning bar that would work for all custom
#   spore towers, but I have no idea how to combine the two. Also, there doesn't seem to be a
#   way to place something on the screen relative to the window, it's always relative to the map.
# * Displays "1 spore" instead of "1 spores" on mouseover when there's only one.
#
# Create CRPL Core object
# Add 2 custom images to your project, SporeTowerFlower.png and CirclePulse.png
# Adjust the variables

# Setup Instructions:
# 1) Import SporeTower.crpl and SporeTowerHelper.crpl into your map project
# 2) Add SporeTowerFlower.png and SporeCirclePulse.png to your custom images
# 3) Adjust these two variables to contain the custom image locations for the
#    images imported in step 2
"Custom4" ->SporeTowerFlower
"Custom5" ->SporeCirclePulse

# Add Custom Sport Tower to Map:
# 1) Add a CRPL Core to your map
# 2) Add the SporeTower.crpl script to the CRPL Core
# 3) Adjust the properties (they mimic a standard spore tower)
#
# You do not need to change the default image of the core. It will set itself when the game starts.

# Spore Tower properties and default values
$InitialDelay:3600 #2-minute delay, 30x120
$WaveInterval:2250 #1:15 fire interval, 30x75
$SporeCount:1
$SporePayload:50

once
HideTraceLog
# main image
self "main" "CustomSporeTower" SetImage

# "flower" part of spore tower image
self "flower" <-SporeTowerFlower SetImage
self "flower" 0 0 -0.2 SetImagePosition
self "flower" 0 0 SetImageScale # initially tiny

# red pulsing circle
self "pulse" <-SporeCirclePulse SetImage
self "pulse" 0 0 -0.1 SetImagePosition
self "pulse" 191 0 0 0 SetImageColor # initially transparent

# set up ammo bar
self CONST_SHOWAMMOBAR true SetUnitAttribute
self CONST_MAXAMMO 1.0 SetUnitAttribute
self CONST_AMMO 0.0 SetUnitAttribute

#Create Helper
"CRPLCore" CurrentX CurrentY CreateUnit ->display
<-display "SporeTowerHelper.crpl" AddScriptToUnit
<-display "SporeTowerHelper.crpl" "SporeBlank" <-SporeBlank SetScriptVar
<-display CONST_PIXELCOORDY CurrentCoords CellToPixel swap pop 10 add SetUnitAttribute

false ->SentWarning
# These are not the actual sounds of a normal spore tower. Those sounds are not
# made available to CRPL scripts at this time. I chose these instead, you can change them.
"Misc0" ->WarningSound # 60 second warning
"Misc19" ->FiringSirenSound # Siren on firing spores
endonce

# HeartBeat for helper CRPL Core
# If the helper core doesn't get a heartbeat every update, it will destroy itself
# This is useless during game play, but when editing and play testing a map,
# this tower can spawn and abandon multiple helpers.
<-display "SporeTowerHelper.crpl" "HeartBeat" true SetScriptVar

# set mouseover text to show number of spores
# note that actual spore towers will say "1 spores", but I can't live with that
<-SporeCount " spore" concat
<-SporeCount 1 gt if "s" concat endif # do plural right!
SetPopupText

# Build Phase
# Show the initial growth of the flower and build progress during the initial delay
GetUpdateCount <-InitialDelay lt if
GetUpdateCount asfloat <-InitialDelay div ->percent
<-display "SporeTowerHelper.crpl" "Display" "Build: " <-percent 100 mul asint concat "%" concat SetScriptVar
self "flower" <-percent <-percent SetImageScale

return
endif

# Pulse Flower
# Once we're pst the initial delay, the flower pulses slowly
0.15 ->pulseVariance
180 ->pulseDuration
GetUpdateCount <-InitialDelay sub <-pulseDuration mod asfloat <-pulseDuration div PI mul 2 mul sin <-pulseVariance mul 1.0 add ->pulseScale
self "flower" <-pulseScale <-pulseScale SetImageScale

# Start initial wave timer
# We don't just set the timer if it is zero, because that would reset the timer
# when the tower is actually ready to fire but can't find a target
# (player has no targetable units on the field)
GetUpdateCount <-InitialDelay eq if
<-WaveInterval SetTimer0
endif

# Time Remaining Display
# Show time in minutes:seconds until the next wave hits
<-display "SporeTowerHelper.crpl" "Display"
GetTimer0 30 div ->remainingSeconds
<-remainingSeconds 60 div ":" concat
<-remainingSeconds 60 mod
dup 10 lt if "0" swap concat endif # add leading zero if seconds<10
concat SetScriptVar

# Ammo Bar
# Timer runs from WaveInterval to 0, convert that to the range 0.0 - 1.0
# As the wave interval counts down, the ammo charges up
self CONST_AMMO <-WaveInterval GetTimer0 sub asfloat <-WaveInterval asfloat div SetUnitAttribute

# Pulse Circle
# When there's less than a minute left on the wave interval, spore towers
# have a red warning pulse
GetTimer0 1800 lte if
30 GetTimer0 30 mod sub asfloat 30 div PI mul 2 div sin ->pulseIteration

<-pulseIteration 1.5 mul ->pulseFlare
1.0 <-pulseIteration sub 223 mul 32 add ->pulseAlpha

self "pulse" <-pulseFlare <-pulseFlare SetImageScale
self "pulse" 191 0 0 <-pulseAlpha SetImageColor
else
self "pulse" 191 0 0 0 SetImageColor # hide
endif

# Warning sound at 60 second mark
GetTimer0 1800 lte <-SentWarning not and if # if Timer0<=1800 and we've not SentWarning
<-WarningSound PlaySound
true ->SentWarning
endif

# Ready to Fire
GetTimer0 eq0 if
#########################<-display "SporeTowerHelper.crpl" "Display" "0:00" SetScriptVar
# Continue the Pulse Circle until we actually fire
30 GetTimer1 sub asfloat 30 div PI mul 2 div sin ->pulseIteration

<-pulseIteration 1.5 mul ->pulseFlare
1.0 <-pulseIteration sub 223 mul 32 add ->pulseAlpha

self "pulse" <-pulseFlare <-pulseFlare SetImageScale
self "pulse" 191 0 0 <-pulseAlpha SetImageColor
GetTimer1 eq0 if 30 SetTimer1 endif

# Firing Logic
# If you want to adjust the targeting logic on a custom tower, this would be the place to do it
# Look to see if there are any units
CurrentCoords 9999 GetUnitCountInRange 0 gt if
0 SetTimer1 # reset pulse timer, probably not necessary
# Found units, select a target for each spore and fire
<-SporeCount 0 do
CurrentCoords RandUnitCoords 1 <-SporePayload CreateSpore
loop
<-FiringSirenSound PlaySound
# Start the next wave interval and reset ammo and warning
<-WaveInterval SetTimer0
self CONST_AMMO 0.0 SetUnitAttribute
false ->SentWarning
endif
endif

# When Destroyed, destroy the helper
:destroyed
<-display 0 Destroy


SporeTowerHelper.crpl

# SporeTowerHelper.crpl.crpl
# Created on: 10/24/2013 8:54:39 AM
# Author: Grayzzur
# ------------------------------------------
#
# Helper script for SporeTower.crpl
# See SporeTower.crpl code comments for instructions
#
# This helper is used to display the build progress
# and wave interval countdown timer

once
"" ->Display
self "main" "NONE" SetImage
true SetPopupTextAlwaysVisible
# As this is a helper CRPL Core, set some attributes so it
# remains invisible and doesn't affect the game
self CONST_CELLHEIGHT 0 SetUnitAttribute
self CONST_CELLWIDTH 0 SetUnitAttribute
self CONST_COUNTSFORVICTORY false SetUnitAttribute
self CONST_CREATEPZ false SetUnitAttribute
self CONST_DESTROYMODE 0 SetUnitAttribute
self CONST_DESTROYONDAMAGE false SetUnitAttribute
self CONST_NULLIFIERDAMAGES false SetUnitAttribute
self CONST_SNIPERTARGET false SetUnitAttribute
self CONST_SUPPORTSDIGITALIS false SetUnitAttribute
self CONST_TAKEMAPSPACE false SetUnitAttribute
self CONST_THORTARGET false SetUnitAttribute

# HeartBeat
false ->HeartBeat
15 SetTimer0
endonce

<-Display SetPopupText

# HeartBeat
# Detect when abandoned (parent tower does not send a heartbeat
# for 15 update cycles) and self Destroy.
#
# This only happens when editing and play testing a map, usually
# when recompiling CRPL scripts. The helpers on the map are
# abandoned, and the towers generate new helpers when you
# restart the map. This keeps your map from being cluttered
# with abandoned helpers.
<-HeartBeat if
15 SetTimer0
false ->HeartBeat
endif

GetTimer0 eq0 if
# No heartbeat detected for 15 ticks!
"ABANDONED Helper" SetPopupText
30 Delay
self 0 Destroy
endif
"Fate. It protects fools, little children, and ships named 'Enterprise.'" -William T. Riker

stewbasic

Thanks! I'll just put your flower image on top for now.