$Count:32 $Speed:2.0 $Enemy:0 $Timer:0 $Direction:0 once if (<-Enemy) Self "main" <-ImageEnemy SetImage # needs to be an 128x128 pixel image else Self "main" <-ImageFriendly SetImage # needs to be an 128x128 pixel image endif Self "main" "Ships" SetImageLayer Self "main" 1 SetImageOrder Self "main" 2 2 SetImageScale 0 OperateWhilePaused 0 ->dx 0 ->dy # Phase variable 0 ->virusPhase # Phase 0 10 ->invulnerableCountdown # Phase 1 -1 ->trackingParticle # Phase 2 6 ->detectRadius # Phase 3 0 ->stolenEnergy 10 ->copies <-Count ->energyPerCopy 5 ->maxEnergyToSteal endonce once <-Timer ->lifetime endonce if (<-virusPhase 0 eq) "100%" SetText # Create a particle to carry the virus around if (<-trackingParticle ParticleExists not <-trackingParticle -1 eq or) CurrentPixelCoords <-Direction <-Speed 0 <-Enemy CreateParticle ->trackingParticle <-trackingParticle <-Speed SetParticleMaxSpeed <-trackingParticle 0 SetParticleDestroyAtEdge 100 ->trackingParticle.particleHealth endif # Prevent instant explosion of virus after creation if (<-invulnerableCountdown 0 gt) <-invulnerableCountdown 1 sub ->invulnerableCountdown else <-Count ->trackingParticle.particleHealth 1 ->virusPhase endif else if (<-virusPhase 1 eq) # Check virus lifetime <-lifetime 1 sub ->lifetime <-lifetime 0 lte if @Explode endif # Virus will follow the original particle if (<-trackingParticle ParticleExists) Self <-trackingParticle GetParticlePosition SetUnitPixelCoords <-trackingParticle GetParticleMotion ->dx ->dy <-trackingParticle.particleHealth 100.0 mul <-Count div 0 Round "%" concat SetText # Detect if there is a nearby ship CurrentCoords <-detectRadius <-Enemy not 0 0 0 1 GetNearestTarget ->target if (<-target -1 neq <-target isHull and) # No need for the tracking particle anymore <-trackingParticle 0 DestroyParticle 2 ->virusPhase "" SetText endif else # Case 1: Target Particle will bounce on edge and not destroyed (Not supposed to happen here) # Case 2: Target Particle got on land and died # Case 3: Target Particle got destroyed (Mutation happens) CurrentCoords ->y ->x <-x <-dx add 0 Round ->x <-y <-dy add 0 Round ->y 0 ->foundLand do (3 -2) do (3 -2) if (<-x I add <-y J add GetLand) 1 ->foundLand break endif loop loop if (<-foundLand) @Explode else # Mutation to enemy virus <-Enemy not ->Enemy 0 ->virusPhase 10 ->invulnerableCountdown -1 ->trackingParticle if (<-Enemy) Self "main" <-ImageEnemy SetImage # needs to be an 128x128 pixel image else Self "main" <-ImageFriendly SetImage # needs to be an 128x128 pixel image endif endif endif else if (<-virusPhase 2 eq) CurrentCoords <-detectRadius <-Enemy not 0 0 0 1 GetNearestTarget ->target if (<-target -1 neq <-target isHull and) # Cut through the ship to find the center of the ship Self <-target GetParticlePosition SetUnitPixelCoords CurrentPixelCoords 0 0 0 <-Enemy CreateParticle ->trackingParticle <-trackingParticle <-Timer SetParticleMaxAge # Check if it is close to the center of the ship CurrentCoords <-detectRadius 0 GetAllShipsInRange ->ships <-ships GetListCount 0 do <-ships[I] GetShipIsEnemy <-Enemy xor if <-ships[I] ->target 3 ->virusPhase endif loop else @Explode endif else if (<-virusPhase 3 eq) if (<-target GetShipIsDestroyed not) <-target GetShipEnergy ->targetShipEnergy Self <-target GetShipPixelCoords SetUnitPixelCoords # Steal energy from enemy ship until a fixed limit if (<-targetShipEnergy <-maxEnergyToSteal gt) <-target <-targetShipEnergy <-maxEnergyToSteal sub SetShipEnergy <-stolenEnergy <-maxEnergyToSteal add ->stolenEnergy else <-stolenEnergy <-targetShipEnergy add ->stolenEnergy <-target 0 SetShipEnergy endif if (<-stolenEnergy <-copies <-energyPerCopy mul gt) 4 ->virusPhase endif <-stolenEnergy 1.0 mul <-copies <-energyPerCopy mul div 3.0 mul 2.0 add ->size Self "main" <-size <-size SetImageScale else 4 ->virusPhase endif else if (<-virusPhase 4 eq) do (<-stolenEnergy <-energyPerCopy div floor 0) "Virus.prpl" ->scriptName "PRPLCORE" CurrentCoords CreateUnit ->virus <-virus <-scriptName AddScriptToUnit <-virus <-scriptName "Enemy" <-Enemy SetScriptVar <-virus <-scriptName "ImageEnemy" <-ImageEnemy SetScriptVar <-virus <-scriptName "ImageFriendly" <-ImageFriendly SetScriptVar <-virus <-scriptName "Count" <-Count SetScriptVar <-virus <-scriptName "Timer" <-Timer SetScriptVar <-virus <-scriptName "Speed" <-Speed SetScriptVar <-detectRadius neg <-detectRadius 1 add RandInt ->dx <-detectRadius neg <-detectRadius 1 add RandInt ->dy <-virus <-scriptName "Direction" <-dy <-dx atan2 SetScriptVar <-virus CurrentX <-dx add CurrentY <-dy add SetUnitCoords loop 5 ->virusPhase # Kill the ship @Explode2 endif endif endif endif endif :Awake Self 0 SetUnitTakeMapSpace Self 0 SetUnitIsGoal Self 0 SetUnitLatheTargets Self 0 SetUnitCreateFootprint Self 0 SetUnitMissionGoal :Explode if (<-trackingParticle ParticleExists) <-trackingParticle 0 DestroyParticle endif CurrentPixelCoords ->y ->x <-Count 0 do I <-Count asfloat div 360 mul Deg2Rad mul ->angle <-x <-angle cos 8 mul add <-y <-angle sin 8 mul add <-angle 4 0 <-Enemy CreateParticle ->trackingParticle <-trackingParticle 30 SetParticleMaxAge loop Self 0 DestroyUnit :Explode2 if (<-trackingParticle ParticleExists) <-trackingParticle 0 DestroyParticle endif CurrentPixelCoords ->y ->x <-Count 0 do I <-Count asfloat div 360 mul Deg2Rad mul ->angle <-x <-angle cos 8 mul add <-y <-angle sin 8 mul add <-angle 4 0 <-Enemy CreateParticle ->trackingParticle <-trackingParticle 30 SetParticleMaxAge loop Self 1 DestroyUnit