public void FromActionRow(Actions.ActionRow actionRow) { if (!actionRow.IsIDNull()) { ID = Convert.ToInt32(actionRow.ID); } if (!actionRow.IsAllyActionNull()) { AllyAction = Convert.ToInt32(actionRow.AllyAction); } if (!actionRow.IsAxisActionNull()) { AxisAction = Convert.ToInt32(actionRow.AxisAction); } if (!actionRow.IsRadiusNull()) { Radius = Convert.ToInt32(actionRow.Radius); } if (!actionRow.IsGoalNull()) { Goal = Convert.ToInt32(actionRow.Goal); } if (!actionRow.IsGroupNull()) { Group = Convert.ToInt32(actionRow.Group); } if (!actionRow.IsClassNull()) { Class = Convert.ToInt32(actionRow.Class); } if (!actionRow.IsCloseNodeNull()) { CloseNode = Convert.ToInt32(actionRow.CloseNode); } if (!actionRow.IsLinksNull()) { Links = actionRow.Links; } if (!actionRow.IsProneNull()) { Prone = Convert.ToInt32(actionRow.Prone); } if (!actionRow.IsActiveNull()) { Active = Convert.ToInt32(actionRow.Active); } if (!actionRow.IsEntityNull()) { Entity = Convert.ToInt32(actionRow.Entity); } }
// loop through the defined actions and check against some rules private bool IsValid() { ArrayList dynamiteActions = new ArrayList(); for (int x = 0; x < _actions.Action.Count; x++) { Actions.ActionRow actionRow = _actions.Action[x]; if (!IsActionValid(actionRow)) { return(false); } // if either action is a dynamite action, add to a collection. we will // be checking for identical entity numbers and the existence of links if ((!actionRow.IsAllyActionNull() && actionRow.AllyAction == "4") || (!actionRow.IsAxisActionNull() && actionRow.AxisAction == "4")) { dynamiteActions.Add(actionRow); } } return(DynamiteActionsAreValid(dynamiteActions)); }
public static void WriteActions(string fileName, Actions actions) { fileName = GetActionFile(fileName); StringBuilder buff = new StringBuilder(); StringBuilder execBuff = new StringBuilder(); int startNode = 0; int endNode = 99; int count = 0; foreach (DataRow row in actions.Action.Rows) { Actions.ActionRow actionRow = (Actions.ActionRow)row; if (actionRow.ID == null) { continue; } // action_axis if (!actionRow.IsAxisActionNull()) { buff.Append("action_axis " + actionRow.ID + " " + actionRow.AxisAction + ";"); } else { buff.Append("action_axis " + actionRow.ID + " -1;"); } // action_allies if (!actionRow.IsAllyActionNull()) { buff.Append("action_allies " + actionRow.ID + " " + actionRow.AllyAction + ";"); } else { buff.Append("action_allies " + actionRow.ID + " -1;"); } if (!actionRow.IsCloseNodeNull()) { buff.Append("action_closenode " + actionRow.ID + " " + actionRow.CloseNode + ";"); } if (!actionRow.IsEntityNull()) { buff.Append("action_ent " + actionRow.ID + " " + actionRow.Entity + ";"); } if (!actionRow.IsRadiusNull()) { buff.Append("action_radius " + actionRow.ID + " " + actionRow.Radius + ";"); } if (!actionRow.IsGoalNull()) { buff.Append("action_goal " + actionRow.ID + " " + actionRow.Goal + ";"); } if (!actionRow.IsGroupNull()) { buff.Append("action_group " + actionRow.ID + " " + actionRow.Group + ";"); } if (!actionRow.IsActiveNull()) { buff.Append("action_active " + actionRow.ID + " " + actionRow.Active + ";"); } if (!actionRow.IsClassNull()) { buff.Append("action_class " + actionRow.ID + " " + actionRow.Class + ";"); } if (!actionRow.IsLinksNull()) { buff.Append("action_links " + actionRow.ID + " " + actionRow.Links + ";"); } if (!actionRow.IsProneNull()) { buff.Append("action_prone " + actionRow.ID + " " + actionRow.Prone + ";"); } buff.Append("\r\n"); count++; if (count > endNode) { string subConfigFileName = fileName.Substring(0, fileName.LastIndexOf(".")) + "_" + startNode + "_" + endNode + ".cfg"; WriteConfig(subConfigFileName, buff); buff = new StringBuilder(); startNode = endNode + 1; endNode = startNode + 99; execBuff.Append("exec " + subConfigFileName + "\r\n"); } } if (buff.Length > 0) { string subConfigFileName = fileName.Substring(0, fileName.LastIndexOf(".")) + "_" + startNode + "_" + (count - 1) + ".cfg"; WriteConfig(subConfigFileName, buff); execBuff.Append("exec " + subConfigFileName + "\r\n"); } WriteConfig(fileName, execBuff); }
private bool IsActionValid(Actions.ActionRow actionRow) { bool isValid = true; StringBuilder msg = new StringBuilder(); string id = ""; string allyAction = ""; string axisAction = ""; string ent = ""; string linked = ""; string classNum = ""; if (!actionRow.IsIDNull()) { id = Convert.ToString(actionRow["ID"]); } if (!actionRow.IsAllyActionNull()) { allyAction = Convert.ToString(actionRow["AllyAction"]); } if (!actionRow.IsAxisActionNull()) { axisAction = Convert.ToString(actionRow["AxisAction"]); } if (!actionRow.IsEntityNull()) { ent = Convert.ToString(actionRow["Entity"]); if (ent == "1023") { ent = ""; // default } if (ent == "-1") { ent = ""; // shouldn't be -1 } } if (!actionRow.IsLinksNull()) { linked = Convert.ToString(actionRow["Links"]); } if (!actionRow.IsClassNull()) { classNum = Convert.ToString(actionRow["Class"]); } if ((allyAction == "-1" || allyAction == "") && (axisAction == "-1" || axisAction == "")) { msg.Append("Action " + id + " has no valid ally or axis actions.\r\n"); isValid = false; } if (ent == "") { if (_entityActions.ContainsKey(allyAction)) { msg.Append("Action " + id + " is an " + _entityActions[allyAction] + " action with no entity.\r\n"); isValid = false; } if (_entityActions.ContainsKey(axisAction)) { msg.Append("Action " + id + " is an " + _entityActions[axisAction] + " action with no entity.\r\n"); isValid = false; } } if (_campActions.ContainsKey(allyAction)) { if (linked.Trim() == "") { msg.Append("Action " + id + " is an ally " + _campActions[allyAction] + " with no links.\r\n"); isValid = false; } else { // check the links string[] links = linked.Split(new char[] { ' ' }); for (int x = 0; x < links.Length; x++) { int ndx = Convert.ToInt32(links[x]); // check to see if the action exists!!! if (ndx > _actions.Action.Count - 1) { msg.Append("Action " + id + " has link to an action that doesn't exist [" + ndx + "]"); isValid = false; } else { Actions.ActionRow linkedAction = _actions.Action[ndx]; // we don't allow sorting, so this is ok if (linkedAction.IsAllyActionNull() || linkedAction.AllyAction != "3") { msg.Append("Action " + id + " is an ally " + _campActions[allyAction] + " with an invalid link to Action " + links[x] + " (either no ally action or an ally action that is not an Aim action)\r\n"); isValid = false; } } } } } if (_campActions.ContainsKey(axisAction)) { if (linked.Trim() == "") { msg.Append("Action " + id + " is an axis " + _campActions[axisAction] + " with no links.\r\n"); isValid = false; } else { // check the links string[] links = linked.Split(new char[] { ' ' }); for (int x = 0; x < links.Length; x++) { int ndx = Convert.ToInt32(links[x]); // the axis action should be 3 Actions.ActionRow linkedAction = _actions.Action[ndx]; // we don't allow sorting, so this is ok if (linkedAction.IsAxisActionNull() || linkedAction.AxisAction != "3") { msg.Append("Action " + id + " is an axis " + _campActions[axisAction] + " with an invalid link to Action " + links[x] + " (either no axis action or an axis action that is not an Aim action)\r\n"); isValid = false; } } } } if (!isValid) { MessageBox.Show(this.ParentForm, msg.ToString(), "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(isValid); }
private bool IsRouteValid(Routes.RouteRow route) { try { bool isValid = true; StringBuilder buff = new StringBuilder(); // validate actions if (route.IsActionsNull() || route.Actions.Trim().Length == 0) { // do we need actions? isValid = false; buff.Append("Route " + route.ID + " has no actions defined.\r\n"); } else { // check that the actions exist string[] ids = route.Actions.Split(new char[] { ' ' }); for (int x = 0; x < ids.Length; x++) { int actionID = Int32.MinValue; try { actionID = Convert.ToInt32(ids[x]); } catch { isValid = false; buff.Append("Route " + route.ID + " has an action link that is non-numeric.\r\n"); } if (actionID != Int32.MinValue) { if (actionID < 0 || actionID > _actions.Action.Count - 1) { isValid = false; buff.Append("Route " + route.ID + " is linked to action " + actionID + " which does not exist in the navigation file.\r\n"); } } } } // validate path actions if (route.IsPathActionsNull() || route.PathActions.Trim().Length == 0) { // do we need path actions? isValid = false; buff.Append("Route " + route.ID + " has no path actions defined.\r\n"); } else { // check that the actions exist string[] ids = route.PathActions.Split(new char[] { ' ' }); for (int x = 0; x < ids.Length; x++) { int actionID = Int32.MinValue; try { actionID = Convert.ToInt32(ids[x]); } catch { isValid = false; buff.Append("Route " + route.ID + " has a path action link that is non-numeric.\r\n"); } if (actionID != Int32.MinValue) { if (actionID < 0 || actionID > _actions.Action.Count - 1) { isValid = false; buff.Append("Route " + route.ID + " is linked to path action " + actionID + " which does not exist in the navigation file.\r\n"); } else { Actions.ActionRow actionRow = _actions.Action[actionID]; // these need to be 17, alt-roams switch (route.Team) { case "0": if (actionRow.IsAllyActionNull() || actionRow.IsAxisActionNull()) { isValid = false; buff.Append("Route " + route.ID + " is linked to a path action [" + actionID + "] that is not an Alternate Roam for both teams.\r\n"); } else { if (actionRow.AllyAction != "17" || actionRow.AxisAction != "17") { isValid = false; buff.Append("Route " + route.ID + " is linked to a path action [" + actionID + "] that is not an Alternate Roam for both teams.\r\n"); } } break; case "1": if (actionRow.IsAxisActionNull()) { isValid = false; buff.Append("Route " + route.ID + " is linked to a path action [" + actionID + "] that is not an Axis Alternate Roam action.\r\n"); } else { if (actionRow.AxisAction != "17") { isValid = false; buff.Append("Route " + route.ID + " is linked to a path action [" + actionID + "] that is not an Axis Alternate Roam action.\r\n"); } } break; case "2": if (actionRow.IsAllyActionNull()) { isValid = false; buff.Append("Route " + route.ID + " is linked to a path action [" + actionID + "] that is not an Ally Alternate Roam action.\r\n"); } else { if (actionRow.AllyAction != "17") { isValid = false; buff.Append("Route " + route.ID + " is linked to a path action [" + actionID + "] that is not an Ally Alternate Roam action.\r\n"); } } break; } } } } } if (!isValid) { MessageBox.Show(this.ParentForm, buff.ToString(), "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(isValid); } catch (Exception ex) { MessageBox.Show(this.ParentForm, "Error validation route " + route.ID + ". " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } }