/// <summary> /// Tries to place a Character at the given place in a unit /// </summary> /// <param name="u">Unit to place the Character in</param> /// <param name="c">Character to place</param> /// <param name="x">Position in x</param> /// <param name="y">Position in y</param> /// <returns>true if the unit was placed, false if there was already someon in the spot</returns> private bool place(Unit u, Character c, int x, int y) { if (u.get(x, y) != null) return false; u.set(x, y, c); return true; }
/// <summary> /// Deploy unit on the battlefield and set up the Character Map /// </summary> /// <param name="u">The unit deployed</param> /// <param name="m">The unit's organization is "main" (player-controlled)</param> private void deploy(Unit u, bool m) { Point off; if (m) off = new Point(4, 5); else off = new Point(4, 0); for (int i = 0; i < 4; i++) for (int e = 0; e < 4; e++) if (u.isChar(i, e)) { if (m) u.get(i, e).Organization = "main"; cmap.set(off.X + i, off.Y + e, u.get(i, e)); } }
/// <summary> /// Tries to place a Character in the Unit in the first available spot /// </summary> /// <param name="u">Unit to place the Character in</param> /// <param name="c">Character to place</param> /// <returns>true if the unit was placed, false if there is no spot left</returns> private bool place(Unit u, Character c) { for (int i=0; i<4; i++) for (int e = 0; e < 4; e++) if (u.get(i, e) == null) { u.set(i, e, c); return true; } return false; }
public static XmlElement unit(XmlDocument doc, Unit u) { XmlElement e = doc.CreateElement("Unit"); XmlElement te; e.SetAttribute("name", u.Name); e.SetAttribute("org", u.Organization); for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) { if (!u.isChar(i, j)) continue; te = doc.CreateElement("Pos"); te.SetAttribute("x", i.ToString()); te.SetAttribute("y", j.ToString()); te.SetAttribute("leader", u.isLeader(i, j).ToString()); te.AppendChild(charToXml(doc, u.get(i, j))); e.AppendChild(te); } e.AppendChild(inventory(doc, u.Inventory)); return e; }