Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Audio;
- using Microsoft.Xna.Framework.Content;
- using Microsoft.Xna.Framework.GamerServices;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- using Microsoft.Xna.Framework.Media;
- namespace WindowsGame1
- {
- class AirContents
- {
- float oxygen = 0;
- float plasma = 0;
- float nitrogen = 0;
- float carbon = 0;
- float volume = 2500;
- float temperature = 293.15f;
- bool hasSpaceConnection = false;
- Vector2 Pos = Vector2.Zero;
- AirContents temp;
- public AirContents()
- {
- Pos = new Vector2(-1, -1);
- }
- public AirContents(Vector2 X,float oxy, float nitro, float car, float pla)
- {
- Pos = X;
- oxygen = oxy;
- nitrogen = nitro;
- }
- public void Tick()
- {
- Tile T = TextureDump.MapGlobal.GetTile(Pos.X,Pos.Y);
- if(T == null)
- {
- return;
- }
- if (T is Space)
- {
- T.Air.Zero(); // dump all the air
- }
- if (T.IsDense())
- {
- if (T.Air.Return_Pressure() > 0)
- {
- T.Air.Zero();
- }
- return;
- }
- List<Tile> Tiles = new List<Tile>{ T.GetNorth(), T.GetNorth(), T.GetWest(), T.GetEast() };
- Tiles.ForEach(delegate(Tile Y)
- {
- if (Y == null)
- {
- }
- else if (Y.IsDense())
- {
- }
- else if (Y is Space)
- {
- hasSpaceConnection = true;
- Remove(5);
- }
- else if (PressureDiffrance(Y.Air) > 0)
- {
- float diff = PressureDiffrance(Y.Air);
- //Console.WriteLine("Diff" + diff);
- Share(Y.Air);
- }
- });
- }
- public void Zero()
- {
- oxygen = 0;
- plasma = 0;
- temperature = 0;
- nitrogen = 0;
- carbon = 0;
- }
- public int GetTileGraphics()
- {
- // 1 is plasma
- // 2 is plasma/no2
- int l = 0;
- if (plasma >= 0.5f)
- {
- l = 1;
- }
- return l;
- }
- public void AddPlasma(float F)
- {
- plasma += F;
- }
- public void Share(AirContents A)
- {
- AirContents container = new AirContents();
- container.oxygen += A.oxygen + oxygen;
- container.nitrogen += A.nitrogen + nitrogen;
- container.plasma += A.plasma + plasma;
- A.oxygen = container.oxygen / 2;
- oxygen = container.oxygen / 2;
- plasma = container.plasma / 2;
- A.nitrogen = container.nitrogen / 2;
- A.plasma = container.plasma / 2;
- return;
- }
- public float Total_Moles()
- {
- return (float)Math.Max(oxygen + nitrogen + carbon + plasma, 0.001);
- }
- public float PressureDiffrance(AirContents A)
- {
- float sum = Return_Pressure();
- float Asum = A.Return_Pressure();
- float S = 1;
- if (sum >= Asum)
- S = sum - Asum;
- else if (sum <= Asum)
- S = Asum - sum;
- return S;
- }
- public AirContents Remove(float amount)
- {
- float sum = Total_Moles();
- amount = Math.Min(amount, sum);
- if (amount <= 0)
- {
- return null;
- }
- AirContents A = new AirContents();
- A.oxygen = AirLogic.QUANTIZE((this.oxygen / sum) * amount);
- A.plasma = AirLogic.QUANTIZE((this.plasma / sum) * plasma);
- A.nitrogen = AirLogic.QUANTIZE((this.nitrogen / sum) * amount);
- A.carbon = AirLogic.QUANTIZE((this.carbon / sum) * amount);
- oxygen -= A.oxygen;
- nitrogen -= A.nitrogen;
- carbon -= A.carbon;
- plasma -= A.plasma;
- A.temperature = temperature;
- return A;
- }
- public float Return_Pressure()
- {
- float moles = Total_Moles();
- return Total_Moles()* AirLogic.R_IDEAL_GAS_EQUATION * temperature / volume;
- }
- public void Merge(AirContents Air)
- {
- this.oxygen += Air.oxygen;
- this.nitrogen += Air.nitrogen;
- this.plasma += Air.plasma;
- this.carbon += Air.carbon;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement