Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.89 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Microsoft.Xna.Framework;
  6. using Microsoft.Xna.Framework.Audio;
  7. using Microsoft.Xna.Framework.Content;
  8. using Microsoft.Xna.Framework.GamerServices;
  9. using Microsoft.Xna.Framework.Graphics;
  10. using Microsoft.Xna.Framework.Input;
  11. using Microsoft.Xna.Framework.Media;
  12.  
  13.  
  14. namespace WindowsGame1
  15. {
  16.     class AirContents
  17.     {
  18.         float oxygen = 0;
  19.         float plasma = 0;
  20.         float nitrogen = 0;
  21.         float carbon = 0;
  22.         float volume = 2500;
  23.         float temperature = 293.15f;
  24.         bool hasSpaceConnection = false;
  25.         Vector2 Pos = Vector2.Zero;
  26.         AirContents temp;
  27.         public AirContents()
  28.         {
  29.             Pos = new Vector2(-1, -1);
  30.         }
  31.         public AirContents(Vector2 X,float oxy, float nitro, float car, float pla)
  32.         {
  33.             Pos = X;
  34.             oxygen = oxy;
  35.             nitrogen = nitro;
  36.  
  37.         }
  38.         public void Tick()
  39.         {
  40.             Tile T = TextureDump.MapGlobal.GetTile(Pos.X,Pos.Y);
  41.             if(T == null)
  42.             {
  43.                 return;
  44.             }
  45.             if (T is Space)
  46.             {
  47.                 T.Air.Zero(); // dump all the air
  48.             }
  49.             if (T.IsDense())
  50.             {
  51.                 if (T.Air.Return_Pressure() > 0)
  52.                 {
  53.                     T.Air.Zero();
  54.                 }
  55.                 return;
  56.             }
  57.             List<Tile> Tiles = new List<Tile>{ T.GetNorth(), T.GetNorth(), T.GetWest(), T.GetEast() };
  58.            Tiles.ForEach(delegate(Tile Y)
  59.            {
  60.                if (Y == null)
  61.                {
  62.                }
  63.                else if (Y.IsDense())
  64.                {
  65.                }
  66.                else if (Y is Space)
  67.                {
  68.                    hasSpaceConnection = true;
  69.                    Remove(5);
  70.  
  71.                }
  72.                else if (PressureDiffrance(Y.Air) > 0)
  73.                {
  74.                    float diff = PressureDiffrance(Y.Air);
  75.                    //Console.WriteLine("Diff" + diff);
  76.                    Share(Y.Air);
  77.  
  78.                }
  79.                
  80.             });
  81.  
  82.         }
  83.         public void Zero()
  84.         {
  85.             oxygen = 0;
  86.             plasma = 0;
  87.             temperature = 0;
  88.             nitrogen = 0;
  89.             carbon = 0;
  90.         }
  91.         public int GetTileGraphics()
  92.         {
  93.             // 1 is plasma
  94.             // 2 is plasma/no2
  95.             int l = 0;
  96.             if (plasma >= 0.5f)
  97.             {
  98.                 l = 1;
  99.             }
  100.             return l;
  101.         }
  102.         public void AddPlasma(float F)
  103.         {
  104.             plasma += F;
  105.         }
  106.         public void Share(AirContents A)
  107.         {
  108.             AirContents container = new AirContents();
  109.             container.oxygen += A.oxygen + oxygen;
  110.             container.nitrogen += A.nitrogen + nitrogen;
  111.             container.plasma += A.plasma + plasma;
  112.             A.oxygen = container.oxygen / 2;
  113.             oxygen = container.oxygen / 2;
  114.             plasma = container.plasma / 2;
  115.             A.nitrogen = container.nitrogen / 2;
  116.             A.plasma = container.plasma / 2;
  117.             return;
  118.  
  119.         }
  120.         public float Total_Moles()
  121.         {
  122.             return (float)Math.Max(oxygen + nitrogen + carbon + plasma, 0.001);
  123.         }
  124.         public float PressureDiffrance(AirContents A)
  125.         {
  126.             float sum = Return_Pressure();
  127.             float Asum = A.Return_Pressure();
  128.             float S = 1;
  129.             if (sum >= Asum)
  130.                 S = sum - Asum;
  131.             else if (sum <= Asum)
  132.                 S = Asum - sum;
  133.             return S;
  134.  
  135.         }
  136.         public AirContents Remove(float amount)
  137.         {
  138.             float sum = Total_Moles();
  139.             amount = Math.Min(amount, sum);
  140.             if (amount <= 0)
  141.             {
  142.                 return null;
  143.             }
  144.             AirContents A = new AirContents();
  145.             A.oxygen = AirLogic.QUANTIZE((this.oxygen / sum) * amount);
  146.             A.plasma = AirLogic.QUANTIZE((this.plasma / sum) * plasma);
  147.             A.nitrogen = AirLogic.QUANTIZE((this.nitrogen / sum) * amount);
  148.             A.carbon = AirLogic.QUANTIZE((this.carbon / sum) * amount);
  149.            
  150.             oxygen -= A.oxygen;
  151.             nitrogen -= A.nitrogen;
  152.             carbon -= A.carbon;
  153.             plasma -= A.plasma;
  154.             A.temperature = temperature;
  155.             return A;
  156.  
  157.  
  158.         }
  159.         public float Return_Pressure()
  160.         {
  161.             float moles = Total_Moles();
  162.             return Total_Moles()* AirLogic.R_IDEAL_GAS_EQUATION * temperature / volume;
  163.         }
  164.         public void Merge(AirContents Air)
  165.         {
  166.             this.oxygen += Air.oxygen;
  167.             this.nitrogen += Air.nitrogen;
  168.             this.plasma += Air.plasma;
  169.             this.carbon += Air.carbon;
  170.         }
  171.  
  172.     }
  173. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement