| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 | class PowerGeneratorStatic : PowerGeneratorBase{	const int SWITCH_COUNT = 6;	const int LOW_ENERGY_PERCENT = 5;		protected static ref set<PowerGeneratorStatic> m_PowerGenerators = new set<PowerGeneratorStatic>();	protected Land_WarheadStorage_PowerStation m_Parent;		protected int m_ParentID1;	protected int m_ParentID2;	protected int m_ParentID3;	protected int m_ParentID4;		protected int m_LeverStatesBits;		void PowerGeneratorStatic()	{		RegisterPersistentObject(this);	}		void ~PowerGeneratorStatic()	{		UnregisterPersistentObject(this);	}	static void RegisterPersistentObject(PowerGeneratorStatic obj)	{		m_PowerGenerators.Insert(obj);	}		static void UnregisterPersistentObject(PowerGeneratorStatic obj)	{		if (!m_PowerGenerators)			return;		int index = m_PowerGenerators.Find(obj);		if (index != -1)		{			m_PowerGenerators.Remove(index);		}	}		static PowerGeneratorStatic GetClosestGenerator(vector position, float tolerance)	{		float toleranceSq = tolerance * tolerance;		float smallestDist = float.MAX;		PowerGeneratorStatic closest;				foreach (PowerGeneratorStatic obj:m_PowerGenerators)		{			float distSq = vector.DistanceSq(position,obj.GetPosition());			if (distSq < toleranceSq)			{				return obj;			}		}		return null;	}		void SetParent(Land_WarheadStorage_PowerStation parent)	{				m_Parent = parent;	}		// States saved thorugh the generator entity since it doesnt work when done building side	void StoreLeverStates(int leverStateBits)	{		m_LeverStatesBits = leverStateBits;	}		int GetStoredLeverBits()	{		return m_LeverStatesBits;	}		// Generator is working	override void OnWorkStart()	{		super.OnWorkStart();		if (m_Parent)		{			m_Parent.OnGeneratorStart();		}				if (!GetGame().IsServer())			return;				for (int i = 1; i <= SWITCH_COUNT; i++)		{			SetAnimationPhase("Switch" + i.ToString(), 1);		}	}		// Turn off when this runs out of fuel	override void OnWorkStop()	{		super.OnWorkStop();		if (m_Parent)		{			m_Parent.OnGeneratorStop();		}				if (!GetGame().IsServer())			return;				for (int i = 1; i <= SWITCH_COUNT; i++)		{			SetAnimationPhase("Switch" + i.ToString(), 0);		}	}		override void SetLowEnergyState(bool state)	{		super.SetLowEnergyState(state);				if (GetGame().IsServer())		{			Land_WarheadStorage_Main bunker = m_Parent.GetClosestBunker();			if (bunker)				bunker.SetLowEnergyStateServer(state);		}	}			override vector GetSmokeParticlePosition()	{		return "1.1 1.1 -1.1";	}		override vector GetSmokeParticleOrientation()	{		return "90 0 23";	}	// Checks sparkplug	override bool HasSparkplug()	{		int slot = InventorySlots.GetSlotIdFromString("GlowPlug");		EntityAI ent = GetInventory().FindAttachment(slot);		return ent && !ent.IsRuined();	}		// Taking item into inventory	override bool CanPutInCargo( EntityAI parent )	{		return false;	}	// Taking item into inventory	override bool CanPutIntoHands(EntityAI parent)	{		return false;	}	override void OnStoreSave(ParamsWriteContext ctx)	{		super.OnStoreSave(ctx);				if (m_Parent)			m_Parent.GetPersistentID(m_ParentID1,m_ParentID2, m_ParentID3, m_ParentID4);						ctx.Write(m_ParentID1);		ctx.Write(m_ParentID2);		ctx.Write(m_ParentID3);		ctx.Write(m_ParentID4);				ctx.Write(m_LeverStatesBits);	}		override bool OnStoreLoad( ParamsReadContext ctx, int version )	{		if ( !super.OnStoreLoad( ctx, version ) )			return false;		if ( !ctx.Read(m_ParentID1))		{			return false;		}		if ( !ctx.Read(m_ParentID2))		{			return false;		}		if ( !ctx.Read(m_ParentID3))		{			return false;		}		if ( !ctx.Read( m_ParentID4))		{			return false;		}						if (version >= 141 && !ctx.Read(m_LeverStatesBits) )			return false;				return true;	}		override void EEOnAfterLoad()	{		// Does this part actually do anything?		Land_WarheadStorage_PowerStation powerStation = Land_WarheadStorage_PowerStation.Cast(GetGame().GetEntityByPersitentID(m_ParentID1, m_ParentID2, m_ParentID3, m_ParentID4));		if (powerStation)		{			PowerGeneratorStatic otherGenerator = powerStation.GetPowerGenerator();			if (otherGenerator)			{				otherGenerator.SetFuel(GetFuel());				Delete();			}		}	}		override bool CanReleaseAttachment(EntityAI attachment)	{		if (!super.CanReleaseAttachment(attachment))			return false;		return !GetCompEM().IsWorking();	}		override bool IsTakeable()	{		return false;	}		override bool IsActionTargetVisible()	{		return true;	}	override bool DisableVicinityIcon()    {        return true;    }		// DEPRECATED		void SetLowEnergyStateServer(bool state);}
 |