public static void LoadDataFromFile() { int id = 0, mass = 0, firer = 0, hp = 0, energy = 0, slots = 0, rad = 0, tbi = -1, tti = -1, ii = -1, explf = -1, rech = -1, fired = -1, firem = -1, price = -1, rr = -1; float shield = 0; bool connect = false; string type = "", name = "", explt = "", firet = "", targt = "", re = "", he = ""; Loder data = new Loder(Path); while (data.Next()) { if (data.Key == "Constructions") { InfoMas = new Body[Convert.ToInt32(data.Value)]; ConstrInfo = new ConstrOption[Convert.ToInt32(data.Value)]; } if (data.Key == "ID") id = Convert.ToInt32(data.Value); if (data.Key == "Type") type = data.Value; if (data.Key == "Name") name = data.Value; if (data.Key == "MaxHp") hp = Convert.ToInt32(data.Value); if (data.Key == "Mass") mass = Convert.ToInt32(data.Value); if (data.Key == "Price") price = Convert.ToInt32(data.Value); if (data.Key == "Energy") energy = Convert.ToInt32(data.Value); if (data.Key == "Connecting") connect = Convert.ToBoolean(data.Value); if (data.Key == "MaxSlots") slots = Convert.ToInt32(data.Value); if (data.Key == "RadSize") rad = Convert.ToInt32(data.Value); if (data.Key == "Shield") shield = (float)(Convert.ToDouble(data.Value)); if (data.Key == "ExplType") explt = data.Value; if (data.Key == "ExplForse") explf = Convert.ToInt32(data.Value); if (data.Key == "Recharge") rech = Convert.ToInt32(data.Value); if (data.Key == "FireRang") firer = Convert.ToInt32(data.Value); if (data.Key == "TargetType") targt = data.Value; if (data.Key == "FireType") firet = data.Value; if (data.Key == "FireDemage") fired = Convert.ToInt32(data.Value); if (data.Key == "FireMass") firem = Convert.ToInt32(data.Value); if (data.Key == "RodRadius") rr = Convert.ToInt32(data.Value); if (data.Key == "RodEffect") re = data.Value; if (data.Key == "HitEffect") he = data.Value; if (data.Key == "IconIndex") // индекс текстуры иконки ii = Convert.ToInt32(data.Value); if (data.Key == "TBI") // индекс основной текстуры tbi = Convert.ToInt32(data.Value); if (data.Key == "TTI") // индекс текстуры турели (если есть) tti = Convert.ToInt32(data.Value); if (data.Key == "End") { Body body = new Body(hp, energy, rad, shield, mass); ConstrInfo[id] = new ConstrOption(name, type, hp, rad, slots, connect, explt, explf, ii, firer, price); if (type == Building.ConstrType) InfoMas[id] = new Building(0, 0, 0, body, tbi); if (type == Tower.ConstrType) InfoMas[id] = new Tower(0, 0, 0, body, firer, firem, fired, firet, targt, rech, tbi, tti, rr, re, he); firer = 0; } } data.EndReading(); }
// Соеденяет постройку путями, если возможно, существующие пути не трогает private static int RebildWay(Body el, int type) { int x2, y2, r; int[] temp; List<int[]> tW = new List<int[]>(); int slots = el.Slots; int x = el.X; int y = el.Y; for (int i = 0; i < Mas.Length; i++) for (int j = 0; j < Mas[i].Count; j++) { if ((i != type) || (j != el.PozList)) { if ((ConstrInfo[type].Connecting) || (ConstrInfo[i].Connecting)) { x2 = Mas[i][j].X; y2 = Mas[i][j].Y; r = (int)Math.Sqrt((x - x2) * (x - x2) + (y - y2) * (y - y2)); if ((Mas[i][j].Slots < ConstrInfo[i].MaxSlots) && (RadVisibl >= r)) { bool flag = true; for (int k = 0; k < Ways.Count; k++) { if ((Ways[k][0] == i) && (Ways[k][1] == j)) { if ((Ways[k][2] == type) && (Ways[k][3] == el.PozList)) flag = false; } if ((Ways[k][2] == i) && (Ways[k][3] == j)) { if ((Ways[k][0] == type) && (Ways[k][1] == el.PozList)) flag = false; } } if ((flag) && (ChekWay(x, y, x2, y2))) { temp = new int[3]; temp[0] = i; temp[1] = j; temp[2] = r; tW.Add(temp); } } } } } for (int i = 0; i < tW.Count - 1; i++) for (int j = i + 1; j < tW.Count; j++) { if (tW[i][2] > tW[j][2]) { temp = tW[i]; tW[i] = tW[j]; tW[j] = temp; } } for (int i = 0; (i < tW.Count) && (slots < ConstrInfo[type].MaxSlots); i++) { Mas[tW[i][0]][tW[i][1]].Slots++; slots++; temp = new int[4]; temp[0] = type; temp[1] = el.PozList; temp[2] = tW[i][0]; temp[3] = tW[i][1]; Ways.Add(temp); } return slots; }
public static void SkipRef() { Ref = null; }
// если нету - int[1], иначе - [type==pozMas, pozList] public static int[] GetConstr(int x, int y) { int[] rez = { -1 }; int x1, y1, r1; for (int i = 0; (i < Mas.Length) && (rez.Length == 1); i++) for (int j = 0; (j < Mas[i].Count) && (rez.Length == 1); j++) { x1 = Mas[i][j].X; y1 = Mas[i][j].Y; r1 = ConstrInfo[i].RadSize; if (r1 >= (int)Math.Sqrt((x1 - x) * (x1 - x) + (y1 - y) * (y1 - y))) { rez = new int[2]; rez[0] = i; rez[1] = j; Ref = Mas[i][j]; } } return rez; }
public static void Destroy(int pozMas, int pozList) { if (Ref != null) { if (Ref.Equals(Mas[pozMas][pozList])) Ref = null; } ExplosionsExist = true; Explosions.Add(ConstrInfo[pozMas].ExplType, Mas[pozMas][pozList].X, Mas[pozMas][pozList].Y); AsterField.Explode(new Point(Mas[pozMas][pozList].X, Mas[pozMas][pozList].Y), ConstrInfo[pozMas].ExplForse); Explode(pozMas, pozList); List<int[]> tW = new List<int[]>(); List<int> removing = new List<int>(); for (int i = 0; i < Ways.Count; i++) { if ((Ways[i][0] == pozMas) && (Ways[i][1] == pozList)) { int[] poz = { Ways[i][2], Ways[i][3] }; tW.Add(poz); Mas[poz[0]][poz[1]].Slots--; removing.Add(i); } if ((Ways[i][2] == pozMas) && (Ways[i][3] == pozList)) { int[] poz = { Ways[i][0], Ways[i][1] }; tW.Add(poz); Mas[poz[0]][poz[1]].Slots--; removing.Add(i); } } for (int i = removing.Count - 1; i >= 0; i--) Ways.RemoveAt(removing[i]); for (int i = pozList+1; i < Mas[pozMas].Count; i++) Mas[pozMas][i].PozList--; for (int i = 0; i < Ways.Count; i++) { if ((Ways[i][0] == pozMas) && (Ways[i][1] > pozList)) Ways[i][1]--; if ((Ways[i][2] == pozMas) && (Ways[i][3] > pozList)) Ways[i][3]--; } Mas[pozMas].RemoveAt(pozList); for (int i = 0; i < tW.Count; i++) { if ((tW[i][0] == pozMas) && (tW[i][1] > pozList)) tW[i][1]--; Mas[tW[i][0]][tW[i][1]].Slots = RebildWay(Mas[tW[i][0]][tW[i][1]], tW[i][0]); } RebildGroups(); }
public static void CreateWorld() { Ref = null; ExplosionsExist = false; Ways = new List<int[]>(); Mas = new List<Body>[InfoMas.Length]; PowerList = new List<int>(); int[] temp = new int[100]; for (int i = 0; i < temp.Length; i++) temp[i] = 0; PowerList.AddRange(temp); for (int i = 0; i < Mas.Length; i++) Mas[i] = new List<Body>(); }