// A IPatrol variables // //public Transform[] moveSpots; // //private int randomSpot; // //public float distToPlayer = 5.0f; // //private float randomStrafeStartTime; // //private float waitStrafeTime; // //public float minStrafe; // //public float maxStrafe; // //public Transform strafeRight; // //public Transform strafeLeft; // //private int randomStrafeDir; // //public float chaseRadius = 20f; // //public float facePlayerFactor = 20f; // //private float waitTime; // //public float startWaitTime = 1f; // //public bool playerIsInLOS = false; // //public float fieldOfViewAngle = 160f; // //public float losRadius = 45f; // //private bool AIMemorizePlayer = false; // //public float memoryStartTime = 10f; // //private float increasingMemoryTime; // //Vector3 noisePosition; // //private bool AIHeardPlayer = false; // //public float noiseTravelDistance = 50f; // //public float spinSpeed = 3f; // //private bool canSpin = false; // //private float isSpinningTime; // //public float spinTime = 3f; // Function definition for ChangeState // AITypes newState set as paramters public void ChangeState(AITypes newState) { // Record the time the tank entered the state stateStartTime = Time.time; // Set the current AI state into a new state currentAIType = newState; }
/// <summary> /// For if n enemies are attacking /// </summary> public void StopAttack(AITypes whichAI, int numOfAI = 1)//(int numStopAttacking = 1) { SetTotal(whichAI, -numOfAI); //int points = numOfAI / countsPer1Point[(int)whichAI]; //aiManager.CurAttack -= points; if (aiManager.CurAttack < 0) { Debug.LogError("Y'all fudged up. AICount < 0"); aiManager.CurAttack = 0; } }
/// <summary> /// For if n enemies are attacking /// </summary> public bool CanAttack(AITypes whichAI, int numOfAI = 1)//(int numAttacking = 1) { float points = TestTotal(whichAI, numOfAI); bool willAttack = points <= aiManager.MaxAttack; if (willAttack) { SetTotal(whichAI, numOfAI); } return(willAttack); }
// Start is called before the first frame update void Start() { player = GameObject.FindGameObjectWithTag("Player"); animator = GetComponent <Animator>(); controller = GetComponent <CharacterController>(); vertical = 0; horizontal = 0; state = GetComponent <StateManager>(); state.Init(); artInt = GetComponent <AITypes>(); }
private void SetTotal(AITypes whichAI, int numOfAI) { countsOfAI[(int)whichAI] += numOfAI; if (countsOfAI[(int)whichAI] < 0) { countsOfAI[(int)whichAI] = 0; Debug.Log("Either kill all was pressed, or you f-ed up"); } float total = 0; for (int i = 1; i < countsOfAI.Length; i++) { total += (float)countsOfAI[i] / countsPer1Point[i]; } aiManager.CurAttack = total; }
public static void AITypeChanger(Unit u, AITypes changeTo) { switch (changeTo) { case AITypes.Aggressive: u.ChangeAI((IAIBehaviour)u.gameObject.AddComponent <Aggressive>()); break; case AITypes.Defensive: u.ChangeAI((IAIBehaviour)u.gameObject.AddComponent <Defensive>()); break; case AITypes.Stationary: u.ChangeAI((IAIBehaviour)u.gameObject.AddComponent <Stationary>()); break; } }
private float TestTotal(AITypes whichAI, int numOfAI) { int[] counts = new int[countsOfAI.Length]; float total = 0; for (int i = 1; i < counts.Length; i++) { counts[i] = countsOfAI[i]; } counts[(int)whichAI] += numOfAI; for (int i = 1; i < counts.Length; i++) { total += (float)counts[i] / countsPer1Point[i]; } return(total); }
public AIHate(BaseCreature _bc, AITypes _AiTypes, AIStates _AiState, float _area) : base(_AiTypes, _bc) { Area = _area; From.AIState = _AiState; }
public string ToString(Perso perso, TranslatedROMScript.TranslationSettings ts, bool advanced = false) { R2ROMLoader l = Loader; short mask = 0; AITypes aiTypes = Settings.s.aiTypes; Vector3 vector3 = new Vector3 { x = 0, y = 0, z = 0 }; switch (nodeType) { case NodeType.KeyWord: // KeyWordFunctionPtr if (param < aiTypes.keywordTable.Length) { if (ts.exportMode) { if (aiTypes.keywordTable[param] == "Me") { return("this"); } if (aiTypes.keywordTable[param] == "MainActor") { return("Controller.MainActor"); } if (aiTypes.keywordTable[param] == "Nobody" || aiTypes.keywordTable[param] == "NoInput" || aiTypes.keywordTable[param] == "Nowhere" || aiTypes.keywordTable[param] == "NoGraph" || aiTypes.keywordTable[param] == "NoAction" || aiTypes.keywordTable[param] == "CapsNull") { return("null"); } } return(aiTypes.keywordTable[param]); } return("UnknownKeyword_" + param); case NodeType.Condition: // GetConditionFunctionPtr if (param < aiTypes.conditionTable.Length) { return(aiTypes.conditionTable[param]); } return("UnknownCondition_" + param); case NodeType.Operator: // GetOperatorFunctionPtr if (advanced) { if (param < aiTypes.operatorTable.Length) { return(aiTypes.operatorTable[param] + " (" + param + ")"); } } if (param < aiTypes.operatorTable.Length) { return(aiTypes.operatorTable[param]); } return("UnknownOperator_" + param); case NodeType.Function: // GetFunctionFunctionPtr if (param < aiTypes.functionTable.Length) { return(aiTypes.functionTable[param]); } return("UnknownFunction_" + param); case NodeType.Procedure: // ProcedureFunctionReturn if (param < aiTypes.procedureTable.Length) { return(aiTypes.procedureTable[param]); } return("UnknownProcedure_" + param); case NodeType.MetaAction: // meta action if (param < aiTypes.metaActionTable.Length) { return(aiTypes.metaActionTable[param]); } return("UnknownMetaAction_" + param); case NodeType.BeginMacro: return("BeginMacro"); case NodeType.EndMacro: return("EndMacro"); case NodeType.Field: if (param < aiTypes.fieldTable.Length) { return(aiTypes.fieldTable[param]); } return("UnknownField_" + param); case NodeType.DsgVarRef: // Dsg Var /*if (perso != null && perso.brain != null && perso.brain.mind != null) { * Mind mind = perso.brain.mind; * if (mind.dsgMem != null && mind.dsgMem.dsgVar != null) { * if (param < mind.dsgMem.dsgVar.dsgVarInfos.Length) { * return mind.dsgMem.dsgVar.dsgVarInfos[param].NiceVariableName; * } * } else if (mind.AI_model != null && mind.AI_model.dsgVar != null) { * if (param < mind.AI_model.dsgVar.dsgVarInfos.Length) { * return mind.AI_model.dsgVar.dsgVarInfos[param].NiceVariableName; * } * } * }*/ return("dsgVar_" + param); case NodeType.Constant: if (advanced) { return("Constant: " + paramInt.Value?.value); } return(paramInt.Value?.value + ""); case NodeType.Real: NumberFormatInfo nfi = new NumberFormatInfo() { NumberDecimalSeparator = "." }; return(paramFloat.Value?.value.ToString(nfi) + "f"); case NodeType.Button: // Button/entryaction EntryAction ea = paramButton.Value; if (ea == null) { return("ERR_ENTRYACTION_NOTFOUND"); } string eaName = (advanced ? ea.ToString() : ea.ToScriptString()); if (advanced) { return("Button: " + eaName + "(" + ea.Offset + ")"); } if (!ts.expandEntryActions && ea != null) { return("\"" + eaName + "\""); } return(eaName); case NodeType.ConstantVector: return("Constant Vector: " + paramVector3.Value?.value.ToString()); case NodeType.Vector: return("new Vector3"); // TODO: same case NodeType.Mask: mask = (short)param; // TODO: as short if (advanced) { return("Mask: " + (mask).ToString("x4")); } if (ts.exportMode) { return("\"" + (mask).ToString("x4") + "\""); } return("Mask(" + (mask).ToString("x4") + ")"); case NodeType.ModuleRef: if (advanced) { return("ModuleRef: " + "0x" + (param).ToString("x8")); } return("GetModule(" + (int)param + ")"); case NodeType.DsgVarId: if (advanced) { return("DsgVarId: " + "0x" + (param).ToString("x8")); } return("DsgVarId(" + param + ")"); case NodeType.String: return(paramString.Value.ToString()); case NodeType.LipsSynchroRef: return("LipsSynchroRef: " + param); case NodeType.FamilyRef: return("Family.FromIndex(" + ParamString + ")"); case NodeType.PersoRef: return("Perso.FromIndex(" + ParamString + ")"); case NodeType.ActionRef: return("GetAction(" + ParamString + ")"); case NodeType.SuperObjectRef: return("SuperObject.FromIndex(" + ParamString + ")"); case NodeType.WayPointRef: return("WayPoint.FromIndex(" + ParamString + ")"); case NodeType.TextRef: if (param == 0xFFFF || l.localizationROM == null) { return("TextRef.Null"); } /*if (advanced) return "TextRef: " + param + " (" + l.localizationROM.GetTextForHandleAndLanguageID((int)param, 0) + ")"; * if (ts.expandStrings) { * return "\"" + l.localizationROM[0].GetTextForHandleAndLanguageID((int)param, 0) + "\""; // Preview in english * } else { * return "new TextReference(" + (int)param + ")"; * }*/ int txtIndex = param; string result = l.localizationROM.Lookup(txtIndex); if (result != null) { return("\"" + result + "\""); } else { return("TextRef_" + param); } case NodeType.ComportRef: return("Comport.FromIndex(" + ParamString + ")"); case NodeType.SoundEventRef: if (advanced) { return("SoundEventRef: " + (int)param); } return("SoundEvent.FromID(0x" + ((int)param).ToString("X8") + ")"); case NodeType.ObjectTableRef: return("ObjectTable.FromIndex(" + ParamString + ")"); case NodeType.GameMaterialRef: return("GameMaterial.FromIndex(" + ParamString + ")"); case NodeType.ParticleGenerator: return("ParticleGenerator: " + "0x" + (param).ToString("x8")); case NodeType.VisualMaterial: return("VisualMaterial.FromIndex(" + ParamString + ")"); case NodeType.ModelRef: // ModelCast return("AIModel.FromIndex(" + ParamString + ")"); case NodeType.DataType42: if (advanced) { return("EvalDataType42: " + "0x" + (param).ToString("x8")); } return("EvalDataType42(" + "0x" + (param).ToString("x8") + ")"); case NodeType.CustomBits: if (advanced) { return("CustomBits: " + "0x" + (param).ToString("x8")); } if (ts.exportMode) { return("0x" + (param).ToString("x8")); } return("CustomBits(" + "0x" + (param).ToString("x8") + ")"); case NodeType.Caps: if (advanced) { return("Caps: " + "0x" + (param).ToString("x8")); } if (ts.exportMode) { return("0x" + (param).ToString("x8")); } return("Caps(" + "0x" + (param).ToString("x8") + ")"); case NodeType.SubRoutine: string macroString = "/* Subroutine */"; macroString += Environment.NewLine; TranslatedROMScript macroScript = new TranslatedROMScript(paramScript.Value, perso); macroString += macroScript.ToString(); macroString += Environment.NewLine + "/* End Subroutine */"; return(macroString); case NodeType.Null: return("null"); case NodeType.GraphRef: if (advanced) { return("Graph: " + "0x" + (param).ToString("x8")); } return("Graph.FromIndex(" + ParamString + ")"); } return("unknown"); }
public Mobile() : base( Server.Object.GUID++ ) { if ( this is Corps ) this.Guid += 0xE000A00000000000; if ( this is BaseCreature ) { localTime = DateTime.Now.Ticks; moveVector = new MoveVector( this, X, Y, Z ); aiType = AITypes.Beast; this.Guid += 0xF000A00000000000; movementTimer = new MovementTimer( this ); } else items = new Item[ 104 ]; }
public BaseAIType( AITypes _aiType, BaseCreature bc ) { aiType = _aiType; from = bc; }
public string ToString(Perso perso) { if (scriptNode != null) { string firstChildNode = (this.children.Count > 0 && this.children[0] != null) ? this.children[0].ToString() : "null"; string secondChildNode = (this.children.Count > 1 && this.children[1] != null) ? this.children[1].ToString() : "null"; string prefix = (ts.printAddresses ? "{" + scriptNode.offset + "}" : ""); AITypes aiTypes = Settings.s.aiTypes; uint param = scriptNode.param; switch (scriptNode.nodeType) { case ScriptNode.NodeType.KeyWord: string keyword = param < aiTypes.keywordTable.Length ? aiTypes.keywordTable[param] : ""; switch (keyword) { // If keywords case "If": return(prefix + "if ({condition})".Replace("{condition}", firstChildNode)); case "IfNot": return(prefix + "if (!({condition}))".Replace("{condition}", firstChildNode)); case "If2": return(prefix + "if (globalRandomizer % 2 == 0 && ({condition}))".Replace("{condition}", firstChildNode)); case "If4": return(prefix + "if (globalRandomizer % 4 == 0 && ({condition}))".Replace("{condition}", firstChildNode)); case "If8": return(prefix + "if (globalRandomizer % 8 == 0 && ({condition}))".Replace("{condition}", firstChildNode)); case "If16": return(prefix + "if (globalRandomizer % 16 == 0 && ({condition}))".Replace("{condition}", firstChildNode)); case "If32": return(prefix + "if (globalRandomizer % 32 == 0 && ({condition}))".Replace("{condition}", firstChildNode)); case "If64": return(prefix + "if (globalRandomizer % 64 == 0 && ({condition}))".Replace("{condition}", firstChildNode)); case "IfNot2": return(prefix + "if (globalRandomizer % 2 != 0 && ({condition}))".Replace("{condition}", firstChildNode)); case "IfNot4": return(prefix + "if (globalRandomizer % 4 != 0 && ({condition}))".Replace("{condition}", firstChildNode)); case "IfNot8": return(prefix + "if (globalRandomizer % 8 != 0 && ({condition}))".Replace("{condition}", firstChildNode)); case "IfNot16": return(prefix + "if (globalRandomizer % 16 != 0 && ({condition}))".Replace("{condition}", firstChildNode)); case "IfNot32": return(prefix + "if (globalRandomizer % 32 != 0 && ({condition}))".Replace("{condition}", firstChildNode)); case "IfNot64": return(prefix + "if (globalRandomizer % 64 != 0 && ({condition}))".Replace("{condition}", firstChildNode)); case "IfDebug": return(prefix + "if (debug && {condition})".Replace("{condition}", firstChildNode)); case "IfNotU64": return(prefix + "if (!u64)\n{\n{childNodes}\n}\n".Replace("{childNodes}", string.Join("\n", Array.ConvertAll <Node, string>(this.children.ToArray(), x => x.ToString())))); // Then case "Then": return(prefix + "{\n{childNodes}\n}\n".Replace("{childNodes}", string.Join("\n", Array.ConvertAll <Node, string>(this.children.ToArray(), x => x.ToString())))); // Else case "Else": return(prefix + "else\n{\n{childNodes}\n}\n".Replace("{childNodes}", string.Join("\n", Array.ConvertAll <Node, string>(this.children.ToArray(), x => x.ToString())))); default: return(prefix + scriptNode.ToString(perso, ts.settings)); } case ScriptNode.NodeType.Condition: string cond = param < aiTypes.conditionTable.Length ? aiTypes.conditionTable[param] : ""; switch (cond) { // Boolean conditions: case "Cond_And": return(prefix + firstChildNode + " && " + secondChildNode); case "Cond_Or": return(prefix + firstChildNode + " || " + secondChildNode); case "Cond_Not": return(prefix + "!" + "(" + firstChildNode + ")"); case "Cond_XOR": return(prefix + firstChildNode + " xor " + secondChildNode); // XOR // Real (float) comparisons: case "Cond_Equal": return(prefix + firstChildNode + " == " + secondChildNode); case "Cond_Different": return(prefix + firstChildNode + " != " + secondChildNode); case "Cond_Lesser": return(prefix + firstChildNode + " < " + secondChildNode); case "Cond_Greater": return(prefix + firstChildNode + " > " + secondChildNode); case "Cond_LesserOrEqual": return(prefix + firstChildNode + " <= " + secondChildNode); case "Cond_GreaterOrEqual": return(prefix + firstChildNode + " >= " + secondChildNode); // Button condition: /*case 44: * case 45: * case 46: * case 47: * return prefix + firstChildNode;*/ default: if (firstChildNode != null) { return(prefix + scriptNode.ToString(perso, ts.settings) + "(" + string.Join(", ", Array.ConvertAll <Node, string>(this.children.ToArray(), x => x.ToString())) + ")"); } else { return(prefix + scriptNode.ToString(perso, ts.settings) + "()"); } } case ScriptNode.NodeType.Function: string function = param < aiTypes.functionTable.Length ? aiTypes.functionTable[param] : ""; string ternaryCheck = ""; switch (function) { // Ternary real operators (e.g. x > y ? true : false) case "Func_TernInf": case "Func_TernSup": case "Func_TernEq": case "Func_TernInfEq": case "Func_TernSupEq": switch (function) { case "Func_TernInf": ternaryCheck = " < "; break; case "Func_TernSup": ternaryCheck = " > "; break; case "Func_TernEq": ternaryCheck = " == "; break; case "Func_TernInfEq": ternaryCheck = " <= "; break; case "Func_TernSupEq": ternaryCheck = " >= "; break; } if (this.children.Count >= 4) { return(prefix + "((" + this.children[0] + ternaryCheck + this.children[1] + ") ? " + this.children[2] + " : " + this.children[3] + ")"); } else { return("ERROR"); } case "Func_TernOp": // conditional ternary operator (cond ? true : false) string childCast1 = ""; string childCast2 = ""; if (this.children[1].scriptNode.nodeType == ScriptNode.NodeType.DsgVarRef && this.children[2].scriptNode.nodeType == ScriptNode.NodeType.Real) { childCast1 = "(float)"; } if (this.children[2].scriptNode.nodeType == ScriptNode.NodeType.DsgVarRef && this.children[1].scriptNode.nodeType == ScriptNode.NodeType.Real) { childCast2 = "(float)"; } return(prefix + "((" + this.children[0] + ") ? " + childCast1 + this.children[1] + " : " + childCast2 + this.children[2] + ")"); default: string func = scriptNode.ToString(perso, ts.settings); return(prefix + func + "(" + string.Join(", ", Array.ConvertAll <Node, string>(this.children.ToArray(), x => x.ToString())) + ")"); } case ScriptNode.NodeType.Procedure: string procedure = param < aiTypes.procedureTable.Length ? aiTypes.procedureTable[param] : ""; switch (procedure) { case "Proc_Loop": return(prefix + "for(int i = 0; i < " + firstChildNode + "; i++)\n{"); case "Proc_EndLoop": return(prefix + "}\n"); case "Proc_Break": return(prefix + "break;\n"); default: string proc = scriptNode.ToString(perso, ts.settings); return(prefix + proc + "(" + string.Join(", ", Array.ConvertAll <Node, string>(this.children.ToArray(), x => x.ToString())) + ");"); } case ScriptNode.NodeType.Operator: string op = param < aiTypes.operatorTable.Length ? aiTypes.operatorTable[param] : ""; //Pointer persoPtr = null; switch (op) { // scalar: case "Operator_Plus": return("(" + firstChildNode + (children[1].scriptNode.param >= 0 ? " + " : "") + secondChildNode + ")"); case "Operator_Minus": case "Operator_UnaryMinus": if (children.Count > 1) { return("(" + firstChildNode + " - " + secondChildNode + ")"); } else { return("-" + firstChildNode); } case "Operator_Mul": return("(" + firstChildNode + " * " + secondChildNode + ")"); case "Operator_Div": return("(" + firstChildNode + " / " + secondChildNode + ")"); case "Operator_Mod": return("(" + firstChildNode + " % " + secondChildNode + ")"); // affect: case "Operator_PlusAffect": case "Operator_PlusPlusAffect": return(children.Count > 1 ? (firstChildNode + " += " + secondChildNode + ";") : firstChildNode + "++" + ";"); case "Operator_MinusAffect": case "Operator_MinusMinusAffect": return(children.Count > 1 ? (firstChildNode + " -= " + secondChildNode + ";") : firstChildNode + "--" + ";"); case "Operator_MulAffect": return(firstChildNode + " *= " + secondChildNode + ";"); case "Operator_DivAffect": return(firstChildNode + " /= " + secondChildNode + ";"); case "Operator_Affect": return(firstChildNode + " = " + secondChildNode + ";"); case "Operator_Dot": // dot operator return(firstChildNode + "." + secondChildNode); case ".X": return(firstChildNode + ".x"); // vector case ".Y": return(firstChildNode + ".y"); // vector case ".Z": return(firstChildNode + ".z"); // vector case "Operator_VectorPlusVector": return(firstChildNode + " + " + secondChildNode); case "Operator_VectorMinusVector": return(firstChildNode + " - " + secondChildNode); case "Operator_VectorMulScalar": return(firstChildNode + " * " + secondChildNode); case "Operator_VectorDivScalar": return(firstChildNode + " / " + secondChildNode); case "Operator_VectorUnaryMinus": return("-" + firstChildNode); case ".X:=": return(firstChildNode + ".x = " + secondChildNode + ";"); // vector case ".Y:=": return(firstChildNode + ".y = " + secondChildNode + ";"); // vector case ".Z:=": return(firstChildNode + ".z = " + secondChildNode + ";"); // vector case "Operator_Ultra": // Ultra operator (execute code for different object) return(firstChildNode + ".{code}".Replace("{code}", secondChildNode)); case "Operator_ModelCast": return("((" + firstChildNode + ")(" + secondChildNode + "))"); case "Operator_Array": return(firstChildNode + "[" + secondChildNode + "]"); default: string proc = "(" + scriptNode.param + ")" + scriptNode.ToString(perso, ts.settings); return(prefix + proc + "(" + string.Join(", ", Array.ConvertAll <Node, string>(this.children.ToArray(), x => x.ToString())) + ");"); } case ScriptNode.NodeType.Field: if (firstChildNode != null) { return(prefix + scriptNode.ToString(perso, ts.settings) + "(" + string.Join(", ", Array.ConvertAll <Node, string>(this.children.ToArray(), x => x.ToString())) + ")"); } else { return(prefix + scriptNode.ToString(perso, ts.settings)); } case ScriptNode.NodeType.Vector: case ScriptNode.NodeType.ConstantVector: return(prefix + scriptNode.ToString(perso, ts.settings) + "(" + string.Join(", ", Array.ConvertAll <Node, string>(this.children.ToArray(), x => x.ToString())) + ")"); case ScriptNode.NodeType.MetaAction: return(prefix + scriptNode.ToString(perso, ts.settings) + "(" + string.Join(", ", Array.ConvertAll <Node, string>(this.children.ToArray(), x => x.ToString())) + ");"); case ScriptNode.NodeType.SubRoutine: return(prefix + scriptNode.ToString(perso, ts.settings)); default: return(prefix + scriptNode.ToString(perso, ts.settings)); } } else // Root node returns all children concatenated { string result = ""; foreach (Node child in this.children) { result += child.ToString() + '\n'; } return(result); } }
public BaseAIType(AITypes _aiType, BaseCreature bc) { aiType = _aiType; from = bc; }