void ResetSentence() { _activeVerb = VerbsV0.WalkTo; _activeObject = 0; _activeObject2 = 0; _walkToObjectState = WalkToObjectState.Done; _redrawSentenceLine = true; SentenceNum = 0; _sentenceNestedCount = 0; }
bool CheckPendingWalkAction() { // before a sentence script is executed, it might be necessary to walk to // and pickup objects before. Check if such an action is pending and handle // it if available. if (_walkToObjectState == WalkToObjectState.Done) { return(false); } var actor = Variables[VariableEgo.Value]; var a = Actors[actor]; // wait until walking or turning action is finished if (a.Moving != MoveFlags.InLeg) { return(true); } // after walking and turning finally execute the script if (_walkToObjectState == WalkToObjectState.Turn) { RunSentenceScript(); // change actor facing } else { int distX, distY; Point p; if (IsActor(_walkToObject)) { var b = Actors[ObjToActor(_walkToObject)]; p = b.RealPosition; if (p.X < a.RealPosition.X) { p.X += 4; } else { p.X -= 4; } } else { p = GetObjectXYPos(_walkToObject); } var abr = a.AdjustXYToBeInBox(p); distX = Math.Abs(a.RealPosition.X - abr.Position.X); distY = Math.Abs(a.RealPosition.Y - abr.Position.Y); if (distX <= 4 && distY <= 8) { if (IsActor(_walkToObject)) { // walk to actor finished // make actors turn to each other a.FaceToObject(_walkToObject); int otherActor = ObjToActor(_walkToObject); // ignore the plant if (otherActor != 19) { var b = Actors[otherActor]; b.FaceToObject(ActorToObj(actor)); } } else { // walk to object finished int dir; Point pTmp; GetObjectXYPos(_walkToObject, out pTmp, out dir); a.TurnToDirection(dir); } _walkToObjectState = WalkToObjectState.Turn; return(true); } } _walkToObjectState = WalkToObjectState.Done; return(false); }
protected override void CheckAndRunSentenceScript() { if (CheckPendingWalkAction()) { return; } if (SentenceNum == 0 || Sentence[SentenceNum - 1].IsFrozen) { return; } var st = Sentence[SentenceNum - 1]; if (st.Preposition && st.ObjectB == st.ObjectA) { SentenceNum--; return; } CurrentScript = 0xFF; // assert(st.objectA); // If two objects are involved, at least one must be in the actors inventory if (st.ObjectB != 0 && (OBJECT_V0_TYPE(st.ObjectA) != ObjectV0Type.Foreground || ResourceManager.ObjectOwnerTable[st.ObjectA] != Variables[VariableEgo.Value]) && (OBJECT_V0_TYPE(st.ObjectB) != ObjectV0Type.Foreground || ResourceManager.ObjectOwnerTable[st.ObjectB] != Variables[VariableEgo.Value])) { if (GetVerbEntrypointCore(st.ObjectA, (int)VerbsV0.PickUp) != 0) { DoSentence((int)VerbsV0.PickUp, st.ObjectA, 0); } else if (GetVerbEntrypointCore(st.ObjectB, (int)VerbsV0.PickUp) != 0) { DoSentence((int)VerbsV0.PickUp, st.ObjectB, 0); } else { SentenceNum--; } return; } _cmdVerb = (VerbsV0)st.Verb; _cmdObject = st.ObjectA; _cmdObject2 = st.ObjectB; SentenceNum--; // abort sentence execution if the number of nested scripts is too high. // This might happen for instance if the sentence command depends on an // object that the actor has to pick-up in a nested doSentence() call. // If the actor is not able to pick-up the object (e.g. because it is not // reachable or pickupable) a nested pick-up command is triggered again // and again, so the actual sentence command will never be executed. // In this case the sentence command has to be aborted. _sentenceNestedCount++; if (_sentenceNestedCount > 6) { _sentenceNestedCount = 0; SentenceNum = 0; return; } if (GetWhereIsObject(st.ObjectA) != WhereIsObject.Inventory) { if (_currentMode != Engine0Mode.Keypad) { WalkToActorOrObject(st.ObjectA); return; } } else if (st.ObjectB != 0 && GetWhereIsObject(st.ObjectB) != WhereIsObject.Inventory) { WalkToActorOrObject(st.ObjectB); return; } RunSentenceScript(); if (_currentMode == Engine0Mode.Keypad) { _walkToObjectState = WalkToObjectState.Done; } }
bool CheckPendingWalkAction() { // before a sentence script is executed, it might be necessary to walk to // and pickup objects before. Check if such an action is pending and handle // it if available. if (_walkToObjectState == WalkToObjectState.Done) return false; var actor = Variables[VariableEgo.Value]; var a = Actors[actor]; // wait until walking or turning action is finished if (a.Moving != MoveFlags.InLeg) return true; // after walking and turning finally execute the script if (_walkToObjectState == WalkToObjectState.Turn) { RunSentenceScript(); // change actor facing } else { int distX, distY; Point p; if (IsActor(_walkToObject)) { var b = Actors[ObjToActor(_walkToObject)]; p = b.RealPosition; if (p.X < a.RealPosition.X) p.X += 4; else p.X -= 4; } else { p = GetObjectXYPos(_walkToObject); } var abr = a.AdjustXYToBeInBox(p); distX = Math.Abs(a.RealPosition.X - abr.Position.X); distY = Math.Abs(a.RealPosition.Y - abr.Position.Y); if (distX <= 4 && distY <= 8) { if (IsActor(_walkToObject)) { // walk to actor finished // make actors turn to each other a.FaceToObject(_walkToObject); int otherActor = ObjToActor(_walkToObject); // ignore the plant if (otherActor != 19) { var b = Actors[otherActor]; b.FaceToObject(ActorToObj(actor)); } } else { // walk to object finished int dir; Point pTmp; GetObjectXYPos(_walkToObject, out pTmp, out dir); a.TurnToDirection(dir); } _walkToObjectState = WalkToObjectState.Turn; return true; } } _walkToObjectState = WalkToObjectState.Done; return false; }
protected override void CheckAndRunSentenceScript() { if (CheckPendingWalkAction()) return; if (SentenceNum == 0 || Sentence[SentenceNum - 1].IsFrozen) return; var st = Sentence[SentenceNum - 1]; if (st.Preposition && st.ObjectB == st.ObjectA) { SentenceNum--; return; } CurrentScript = 0xFF; // assert(st.objectA); // If two objects are involved, at least one must be in the actors inventory if (st.ObjectB != 0 && (OBJECT_V0_TYPE(st.ObjectA) != ObjectV0Type.Foreground || ResourceManager.ObjectOwnerTable[st.ObjectA] != Variables[VariableEgo.Value]) && (OBJECT_V0_TYPE(st.ObjectB) != ObjectV0Type.Foreground || ResourceManager.ObjectOwnerTable[st.ObjectB] != Variables[VariableEgo.Value])) { if (GetVerbEntrypointCore(st.ObjectA, (int)VerbsV0.PickUp) != 0) DoSentence((int)VerbsV0.PickUp, st.ObjectA, 0); else if (GetVerbEntrypointCore(st.ObjectB, (int)VerbsV0.PickUp) != 0) DoSentence((int)VerbsV0.PickUp, st.ObjectB, 0); else SentenceNum--; return; } _cmdVerb = (VerbsV0)st.Verb; _cmdObject = st.ObjectA; _cmdObject2 = st.ObjectB; SentenceNum--; // abort sentence execution if the number of nested scripts is too high. // This might happen for instance if the sentence command depends on an // object that the actor has to pick-up in a nested doSentence() call. // If the actor is not able to pick-up the object (e.g. because it is not // reachable or pickupable) a nested pick-up command is triggered again // and again, so the actual sentence command will never be executed. // In this case the sentence command has to be aborted. _sentenceNestedCount++; if (_sentenceNestedCount > 6) { _sentenceNestedCount = 0; SentenceNum = 0; return; } if (GetWhereIsObject(st.ObjectA) != WhereIsObject.Inventory) { if (_currentMode != Engine0Mode.Keypad) { WalkToActorOrObject(st.ObjectA); return; } } else if (st.ObjectB != 0 && GetWhereIsObject(st.ObjectB) != WhereIsObject.Inventory) { WalkToActorOrObject(st.ObjectB); return; } RunSentenceScript(); if (_currentMode == Engine0Mode.Keypad) { _walkToObjectState = WalkToObjectState.Done; } }