public int Set(TechnoType unit, uint count) { TaskForceEntry entry = GetEntry(unit); uint oldcount = (entry == null) ? 0 : entry.Count; return(Mod(unit, (int)(count - oldcount))); }
public int Mod(TechnoType unit, int count) { TaskForceEntry entry = GetEntry(unit); if (entry == null) { if (count > 0) { Add(unit, (uint)count); return(1); } return(0); } count = Math.Max(0, count + (int)entry.Count); if (count == 0) { this.units.Remove(entry); return(-1); } else { entry.Count = (uint)count; return(0); } }
private TaskForceEntry Add(TechnoType unit, uint count) { TaskForceEntry entry = new TaskForceEntry(unit, count); this.units.Add(entry); return(entry); }
public void Remove(TechnoType unit) { TaskForceEntry entry = GetEntry(unit); if (entry != null) { this.units.Remove(entry); } }
private TaskForceEntry GetEntry(TechnoType unit) { foreach (TaskForceEntry entry in units) { if (entry.Unit == unit) { return(entry); } } return(null); }
private void UpdateTFUnit(int mod) { TechnoType tt = cmbTFUnit.SelectedItem as TechnoType; TaskForce tf = SelectedTaskForce(); if (tf.Mod(tt, mod) != 0) { olvTFUnits.SetObjects(tf); } else { TaskForceEntry tfe = tf.SingleOrDefault(s => s.Unit == tt); olvTFUnits.RefreshObject(tfe); } UpdateTFCost(); }
private void ParseTechnoTypes(List <TechnoType> technos, IniDictionary ini, string type, string editorName) { uint tableIndex = 0; foreach (DictionaryEntry de in ini[type]) { string id = de.Value as string; if (ini.ContainsKey(id)) { OrderedDictionary section = ini[id]; string name = id; int cost = (section.Contains("Cost")) ? int.Parse(section["Cost"] as string) : 0; if (section.Contains(editorName)) { name = section[editorName] as string; } else if (section.Contains("Name")) { name = section["Name"] as string; } name = name + " [" + id + "]"; TechnoType tt = technos.SingleOrDefault(t => t.ID == id); if (tt == null) { tt = new TechnoType(id, name, cost, tableIndex++); technos.Add(tt); } else { logger.Add("Duplicate " + type + " [" + id + "] in rules!"); } } else { tableIndex++; } } }
private void olvTFUnits_CellEditFinishing(object sender, BrightIdeasSoftware.CellEditEventArgs e) { if (!e.Cancel && e.SubItemIndex == 1) { ComboBox cmb = e.Control as ComboBox; TaskForce tf = SelectedTaskForce(); TaskForceEntry tfe = e.RowObject as TaskForceEntry; TechnoType unit = cmb.SelectedItem as TechnoType; TaskForceEntry exists = tf.SingleOrDefault(s => s.Unit == unit); if (exists != null && exists != tfe) { tf.Remove(tfe.Unit); exists.Count = exists.Count + tfe.Count; olvTFUnits.SetObjects(tf); } else { tfe.Unit = unit; olvTFUnits.RefreshItem(e.ListViewItem); } } }
public TaskForceEntry(TaskForceEntry other) { this.unit = other.unit; this.count = other.count; }
public TaskForceEntry(TechnoType unit, uint count) { this.unit = unit; this.count = count; }
public static TaskForce Parse(string id, OrderedDictionary section, List <TechnoType> technoTypes, List <AITypeListEntry> groupTypes, Logger logger) { string name = id; int groupi = -1; List <TaskForceEntry> units = new List <TaskForceEntry>(); try { foreach (DictionaryEntry entry in section) { string currKey = entry.Key as string; string currValue = entry.Value as string; if (currKey == "Name") { name = currValue; } else if (currKey == "Group") { groupi = int.Parse(currValue); } else { string[] split = currValue.Split(','); if (split.Length < 2) { logger.Add("Task Force [" + id + "] not in format: <Index>=<Unit Count>,<Unit Id>"); } else { uint count = uint.Parse(split[0] as string); string unitid = split[1] as string; TechnoType tt = technoTypes.SingleOrDefault(t => t.ID == unitid); if (tt == null) { logger.Add("TechnoType [" + unitid + "] referenced by Task Force [" + id + "] does not exist!"); tt = new TechnoType(unitid, unitid, 0, 0); technoTypes.Add(tt); } if (int.Parse(currKey) > 5) { logger.Add("Task Force [" + id + "]: Game ignores unit entry index greater than 5."); } units.Add(new TaskForceEntry(tt, count)); } } } } catch (Exception) { string msg = "Error occured at TaskForce: [" + id + "]" + "\nPlease verify its format. Application will now close."; MessageBox.Show(msg, "Parse Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); Application.Exit(); } AITypeListEntry group = groupTypes.SingleOrDefault(g => g.Index == groupi); if (group == null) { group = groupTypes[0]; } return(new TaskForce(id, name, group, units)); }
public static TriggerType Parse(string id, string data, Dictionary <string, TriggerTypeOption> triggerTypeOptions, TeamType noneTeam, TechnoType noneTechno, Logger logger) { string[] split = data.Split(','); string tag; string name = split[0]; TriggerTypeOption option; Dictionary <string, TriggerTypeEntry> entries = new Dictionary <string, TriggerTypeEntry>(); object value; // no name given if (name.Length == 0) { name = id; } if (split.Length < 18) { logger.Add("Trigger [" + name + "] cannot be parsed because it has an invalid number of parameters!"); return(null); } try { // team 1 tag = "Team1"; option = triggerTypeOptions[tag]; value = option.FindByString(split[1], noneTeam); entries.Add(tag, new TriggerTypeEntry(option, value)); // owner tag = "Owner"; option = triggerTypeOptions[tag]; value = option.FindByString(split[2]); entries.Add(tag, new TriggerTypeEntry(option, value)); // techlevel tag = "TechLevel"; option = triggerTypeOptions[tag]; value = uint.Parse(split[3]); entries.Add(tag, new TriggerTypeEntry(option, value)); // condition tag = "Condition"; option = triggerTypeOptions[tag]; value = option.FindByIndex(int.Parse(split[4])); entries.Add(tag, new TriggerTypeEntry(option, value)); // techtype tag = "TechType"; option = triggerTypeOptions[tag]; string unitid = split[5]; value = noneTechno; if (unitid != "<none>") { value = option.FindByString(unitid); if (value == null) { logger.Add("TechnoType [" + split[5] + "] referenced by Trigger [" + id + "] does not exist!"); value = new TechnoType(unitid, unitid, 0, 0); option.List.Add(value); } } entries.Add(tag, new TriggerTypeEntry(option, value)); // amount tag = "Amount"; option = triggerTypeOptions[tag]; value = Convert.ToUInt32(split[6].Substring(0, 8), 16).SwapEndianness(); entries.Add(tag, new TriggerTypeEntry(option, value)); // operator tag = "Operator"; option = triggerTypeOptions[tag]; value = uint.Parse(split[6].Substring(9, 1)); value = option.FindByIndex((int)(uint)value); entries.Add(tag, new TriggerTypeEntry(option, value)); // starting probability tag = "Prob"; option = triggerTypeOptions[tag]; value = (uint)float.Parse(split[7], CultureInfo.InvariantCulture); entries.Add(tag, new TriggerTypeEntry(option, value)); // minimum probability tag = "ProbMin"; option = triggerTypeOptions[tag]; value = (uint)float.Parse(split[8], CultureInfo.InvariantCulture); entries.Add(tag, new TriggerTypeEntry(option, value)); // maximum probability tag = "ProbMax"; option = triggerTypeOptions[tag]; value = (uint)float.Parse(split[9], CultureInfo.InvariantCulture); entries.Add(tag, new TriggerTypeEntry(option, value)); // skirmish tag = "Skirmish"; option = triggerTypeOptions[tag]; value = option.FindByIndex(int.Parse("0" + split[10])); entries.Add(tag, new TriggerTypeEntry(option, value)); // [11] is unknown and always zero // side tag = "Side"; option = triggerTypeOptions[tag]; int side = int.Parse(split[12]); value = option.FindByIndex(side); entries.Add(tag, new TriggerTypeEntry(option, value)); // base defense tag = "BaseDefense"; option = triggerTypeOptions[tag]; value = option.FindByIndex(int.Parse(split[13])); entries.Add(tag, new TriggerTypeEntry(option, value)); // team 2 tag = "Team2"; option = triggerTypeOptions[tag]; value = option.FindByString(split[14], noneTeam); entries.Add(tag, new TriggerTypeEntry(option, value)); // easy tag = "Easy"; option = triggerTypeOptions[tag]; value = option.FindByIndex(int.Parse(split[15])); entries.Add(tag, new TriggerTypeEntry(option, value)); // medium tag = "Medium"; option = triggerTypeOptions[tag]; value = option.FindByIndex(int.Parse(split[16])); entries.Add(tag, new TriggerTypeEntry(option, value)); // hard tag = "Hard"; option = triggerTypeOptions[tag]; value = option.FindByIndex(int.Parse(split[17])); entries.Add(tag, new TriggerTypeEntry(option, value)); } catch (Exception) { string msg = "Error occured at AITriggerType: " + id + "\nPlease verify its format. Application will now close."; MessageBox.Show(msg, "Parse Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); Application.Exit(); } return(new TriggerType(id, name, entries)); }