Alright, I'm pleased with this one, so bear with me whilst I type this out to make sure I comprehend the code (yes, I admit that I'm weird that I have to do this).
The reload plot object: Rather than drop eat items or whatnot, as I was originally planning to do, instead the plot object will run a script, using one of the only methods the game engine has of running a script on something other than the player: Creature Closest to the Mouse.
- Since the Reload plot object is right on top of the turret, it will (hopefully) run on the turret. - A series of scripts will run under a master control script that first has three sequential script checks: 1: Is the creature the player? 2: Is the player within 150px? 3: Is the Creature's Side = Mecha Friendly? Failure on any of these leads to a simple informational script "Reload Failed". This is insurance, if the player tries to reload but the creature dies, or has been moved away from the reload plot object within the last second then either the player will be closest to the mouse or another creature.
After these checks are performed, there is another Master script that runs several scripts with a simple check as to what type of turret it is, followed by executing a series of scripts determining if the player has: Gun: Bullets, Clips, Magazines. Sonic Turret: Tzo Crystals. Energy Turret: Energy/Battery. Replicator "Turrets": Sand/Pebbles and a separate check for Energy/Battery. Medical "Turrets": Reaper corpses, Red Plants, Medikits. Flame Turrets: Ether, Vitriolic Sacs (Red Aliens will have them). Rocket Turrets: Explosive Shells.
Other devices (Such as furnaces) will have their own unique scripts for their own items.
- These scripts then use the smallest quantity/quality item present in the players inventory.
This will be most complicated for the Gun Turret - the first script will start with a check: Player has 1 Bullets? Energy (ammo) <100%? Add 1 Energy, Remove 1 bullets from player inventory. Run This Script with conditions (Loop). When the player no longer has any bullets, it moves onto next script: Player has 1 Bullet Clip, Energy <100%? Remove Clip from Player inventory, add 20 Bullets. Run script #1. Run script #2 (Loops first the Bullets script again, then the Clip script again until either the turret is fully reloaded, or the player runs out of clips). When the player hasn't any clips, it runs on Magazines exactly the same way, splitting them into bullets, then loading as many bullets into the Turret as it needs them.
All this will happen instantly, without the need for a repeating script on the part of the turret, or any risk of things going funky with location detection or turrets sharing reloads.
Likewise, this will add another step to disabling turrets: On hit by Deactivate, turrets will drop a Deactivation marker, destroy any nearby Reload marker, switch the AI tactic to Stand Still, and disable the dropping of Reload markers. If the deactivation marker isn't pressed within 5 seconds, then it will disappear, and the turret will resume normal operation within a second or so (and it's deactivation bar will set to zero again, with a secondary check to make sure if it's hit whilst in Deactivation mode it'll just set to -1 again).
If the Deactivation marker is activated, then a counter script will run for the turret, checking its Energy bar and reducing it by 1 each time, giving whatever it used back to the player. Sonic - Tzo Surplus (200 of these invisible shards return as a tzo crystal). Gun - Bullets. Flame - If it's on full ammo, it will check for an empty cannister to fill, or if there isn't one, drop an ether spill. Medical Turrets - 1 Medikit per 25/50 energy (meaning the player can use them to produce medikits out of base materials as a valuable secondary use in addition to a powered medical bay). Replicator Turrets - Again, if it's got full ammo, it'll check for empty cannisters for "Sand", as well as performing a secondary check for Energy. Rocket Turrets - Explosive shells. Energy Turrets - Will add their energy to the player's until they're at zero or below it, or if the player has full energy (or is a Psionic/Scavenger), it'll check to see if its energy is >20, and if so, charge a battery. And so on.
With this extra step, this will once again instantly (from the player's perspective) sort out returning resources to the player.
It's going to push the number of total scripts in FM over the three hundred mark, but if this works (and having written all this out, I hope it does), then not only is it going to allow me to easily implement any number of different types of structures, this is going to completely change the way fruit trees work as well (and probably poisonous berries if I pull this off):
Is season incorrect? Informational message: The fruit on this tree is not ripe yet. Season correct: Fruited Bar > X? Informational: You gather some fruit, lower Fruited Bar. Season correct: Fruited Bar < X? There's no fruit left on this tree.
No looping checks, no need for a dozen creature checks making sure it only drops one set of fruit, just direct, easy harvesting.
This is about half coded now, so watch this space and hopefully I'll have good news to report in the next day or two.
|