/** Something that can be picked up by the Ship, and thrown into a Gate. */ abstract class Cargo : AbstractRole { val velocity = Vector2() var isFree = false @CostumeAttribute var weight = 2.0 var factory : CargoFactory = null /* Allows WaterCargo to tell the factory (if it was made by a factory) to make a new WaterCargo. */ fun pickedUp() { } override fun tick() { if (isFree) { velocity += Play.instance.cargoGravity actor.position += velocity deadlyCheck() } } fun letGo() { isFree = true actor.stage = Play.instance.rocksStage } /* Return true if the ship should disconnect from the cargo. */ fun deadlyCheck() : bool { if (Play.instance.isOutsideDome( this ) ) { explode() return true } val deadly = Play.instance.overlappingSomethingDeadly( actor ) if (deadly != null) { val role = deadly.role if (role is Gate) { return enterGate( role as Gate ) } else { explode() return true } } return false } /** Return true if the cargo should be disconnected */ fun enterGate(gate : Gate) : bool { if (gate.isReady) { return gate.transportCargo( this ) } else { explode() return true } } fun sent() { Play.instance.sentCargo( this ) } fun explode() { actor.event("defaut") // Revert back to an emptyCargo before exploding. Play.instance.explode( actor ) if (factory != null) { factory.create() factory = null } } } class Gold : Cargo { } class WaterCargo : Cargo { @CostumeAttribute var waterWeight = 2.0 var isFull = false override fun explode() { if (isFull) { for ( i in 0..6 ) { actor.createChild( "droplet" ) } } super.explode() } override fun pickedUp() { if ( factory != null ) { factory.create() factory = null } } override fun enterGate( gate : Gate ) : bool { if (!isFull) { explode() return true } else { return super.enterGate( gate ) } } fun fill() { actor.event( "fill" ) isFull = true weight += waterWeight } }