Planeshift
|
00001 /* 00002 * npcoperations.h 00003 * 00004 * Copyright (C) 2007 Atomic Blue ([email protected], http://www.atomicblue.org) 00005 * 00006 * 00007 * This program is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU General Public License 00009 * as published by the Free Software Foundation (version 2 of the License) 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 * 00018 */ 00019 #ifndef __NPCOPERATIONS_H__ 00020 #define __NPCOPERATIONS_H__ 00021 00022 #include <psstdint.h> 00023 00024 //============================================================================= 00025 // Crystal Space Includes 00026 //============================================================================= 00027 #include <csgeom/vector3.h> 00028 #include <csutil/csstring.h> 00029 00030 struct iDocumentNode; 00031 struct iSector; 00032 00033 //============================================================================= 00034 // Library Includes 00035 //============================================================================= 00036 #include "util/psconst.h" 00037 #include "util/pspath.h" 00038 #include "util/pspathnetwork.h" 00039 #include <tools/celhpf.h> 00040 #include "net/npcmessages.h" 00041 #include "util/edge.h" 00042 #include "util/mathscript.h" 00043 00044 //============================================================================= 00045 // Project Includes 00046 //============================================================================= 00047 #include "npc.h" 00048 #include "reaction.h" 00049 #include "perceptions.h" 00050 00055 class NPC; 00056 class gemNPCObject; 00057 class gemNPCActor; 00058 class MoveOperation; 00059 class Waypoint; 00060 class Behavior; 00061 00069 class ScriptOperation 00070 { 00071 public: 00072 enum VelSource 00073 { 00074 VEL_DEFAULT, 00075 VEL_USER, 00076 VEL_WALK, 00077 VEL_RUN 00078 }; 00079 00080 // Used to indicate the result of the Run and Advance operations. 00081 enum OperationResult 00082 { 00083 OPERATION_NOT_COMPLETED, 00084 OPERATION_COMPLETED, 00085 OPERATION_FAILED 00086 }; 00087 00088 enum State 00089 { 00090 READY_TO_RUN, 00091 RUNNING, 00092 INTERRUPTED, 00093 COMPLETED 00094 }; 00095 00096 protected: 00098 // Start of instance temp variables. These dosn't need to be copied. 00099 csString name; 00100 00101 csVector3 interrupted_position; 00102 iSector* interrupted_sector; 00103 float interrupted_angle; 00104 00105 int consecCollisions; 00106 00107 Behavior* parent; 00108 00109 State state; 00110 // End of instance temp variables. 00112 00114 // Start of shared values between operation 00115 00116 // Failure handling 00117 csString failurePerception; 00118 00119 // Velocity is shared for all move operations 00120 VelSource velSource; 00121 float vel; 00122 float ang_vel; 00123 00124 // Start Check Move OK parameters 00125 // Configuration paramters. Set by using LoadCheckMoveOk 00126 csString collision; 00127 csString outOfBounds; 00128 csString inBounds; 00129 csString falling; 00130 bool checkTribeHome; 00131 // End Check Move OK parameters 00132 00133 00134 // End of shared values between operations 00136 00138 int StartMoveTo(NPC* npc, const csVector3 &dest, iSector* sector, float vel,const char* action, float &angle); 00139 00140 void TurnTo(NPC* npc,const csVector3 &dest, iSector* destsect, csVector3 &forward, float &angle); 00141 00143 static void StopMovement(NPC* npc); 00144 00145 public: 00146 00147 ScriptOperation(const char* sciptName); 00148 ScriptOperation(const ScriptOperation* other); 00149 virtual ~ScriptOperation() {} 00150 00151 virtual OperationResult Run(NPC* npc,bool interrupted)=0; 00152 virtual OperationResult Advance(float timedelta,NPC* npc); 00153 00154 virtual void InterruptOperation(NPC* npc); 00155 virtual bool AtInterruptedPosition(const csVector3 &pos, const iSector* sector); 00156 virtual bool AtInterruptedAngle(const csVector3 &pos, const iSector* sector, float angle); 00157 virtual bool AtInterruptedPosition(NPC* npc); 00158 virtual bool AtInterruptedAngle(NPC* npc); 00159 00160 virtual void SetState(State state) 00161 { 00162 this->state = state; 00163 } 00164 virtual State GetState() const 00165 { 00166 return state; 00167 } 00168 00169 00170 private: 00178 void SendCollitionPerception(NPC* npc); 00179 00180 public: 00187 virtual bool CheckMoveOk(NPC* npc, csVector3 oldPos, iSector* oldSector, 00188 const csVector3 &newPos, iSector* newSector, int resultFromExtrapolate); 00189 00196 virtual bool CheckEndPointOk(NPC* npc, const csVector3 &myPos, iSector* mySector, 00197 const csVector3 &endPos, iSector* endSector); 00198 00204 virtual const csString &GetCollisionPerception(NPC* npc); 00205 00211 virtual const csString &GetOutOfBoundsPerception(NPC* npc); 00212 00218 virtual const csString &GetInBoundsPerception(NPC* npc); 00219 00225 virtual const csString &GetFallingPerception(NPC* npc); 00226 00227 virtual bool Load(iDocumentNode* node); 00228 virtual ScriptOperation* MakeCopy()=0; 00229 00235 virtual float GetVelocity(NPC* npc); 00236 00237 virtual float GetAngularVelocity(NPC* npc); 00238 bool LoadVelocity(iDocumentNode* node); 00239 00244 bool LoadCheckMoveOk(iDocumentNode* node); 00245 00251 void CopyCheckMoveOk(ScriptOperation* source); 00252 00264 void AddRandomRange(csVector3 &dest, float radius, float margin = 0.0); 00265 00269 void SetAnimation(NPC* npc, const char* name); 00270 00271 virtual const char* GetName() const 00272 { 00273 return name.GetDataSafe(); 00274 }; 00275 00280 virtual void Failure(NPC* npc); 00281 00283 void SetParent(Behavior* behavior); 00284 }; 00285 00286 //----------------------------------------------------------------------------- 00287 00291 class MovementOperation : public ScriptOperation 00292 { 00293 protected: 00294 00295 // Instance variables 00296 csRef<iCelHPath> path; 00297 00298 // Cache values for end position 00299 csVector3 endPos; 00300 iSector* endSector; 00301 00302 float currentDistance; 00303 00304 // Operation parameters 00305 csString action; 00306 00307 // Constructor 00308 MovementOperation(const MovementOperation* other); 00309 00310 public: 00311 00312 MovementOperation(const char* name); 00313 00314 virtual ~MovementOperation() { } 00315 00316 virtual bool Load(iDocumentNode* node); 00317 00318 bool EndPointChanged(const csVector3 &endPos, const iSector* endSector) const; 00319 00320 virtual bool GetEndPosition(NPC* npc, const csVector3 &myPos, const iSector* mySector, 00321 csVector3 &endPos, iSector* &endSector) = 0; 00322 00323 virtual bool UpdateEndPosition(NPC* npc, const csVector3 &myPos, const iSector* mySector, 00324 csVector3 &endPos, iSector* &endSector) = 0; 00325 00326 virtual OperationResult Run(NPC* npc,bool interrupted); 00327 00328 virtual OperationResult Advance(float timedelta,NPC* npc); 00329 00330 virtual void InterruptOperation(NPC* npc); 00331 00332 }; 00333 00334 //--------------------------------------------------------------------------- 00335 // Following section contain specefix NPC operations. 00336 // Ordered alphabeticaly, with exception for when needed 00337 // due to inheritance. MoveOperation is out of order compared 00338 // to the implementation file. 00339 //--------------------------------------------------------------------------- 00340 00341 //----------------------------------------------------------------------------- 00342 00347 class AssessOperation : public ScriptOperation 00348 { 00349 protected: 00350 csString physicalAssessmentPerception; 00351 csString magicalAssessmentPerception; 00352 csString overallAssessmentPerception; 00353 public: 00354 00355 AssessOperation(): ScriptOperation("Assess") {}; 00356 virtual ~AssessOperation() {}; 00357 virtual OperationResult Run(NPC* npc,bool interrupted); 00358 virtual bool Load(iDocumentNode* node); 00359 virtual ScriptOperation* MakeCopy(); 00360 }; 00361 00362 //----------------------------------------------------------------------------- 00363 00367 class BuildOperation : public ScriptOperation 00368 { 00369 protected: 00370 bool pickupable; 00371 public: 00372 00373 BuildOperation(): ScriptOperation("Build"),pickupable(false) {}; 00374 virtual ~BuildOperation() {}; 00375 virtual OperationResult Run(NPC* npc,bool interrupted); 00376 virtual bool Load(iDocumentNode* node); 00377 virtual ScriptOperation* MakeCopy(); 00378 }; 00379 00380 //----------------------------------------------------------------------------- 00381 00385 class UnbuildOperation : public ScriptOperation 00386 { 00387 protected: 00388 public: 00389 00390 UnbuildOperation(): ScriptOperation("Unbuild") {}; 00391 virtual ~UnbuildOperation() {}; 00392 virtual OperationResult Run(NPC* npc,bool interrupted); 00393 virtual bool Load(iDocumentNode* node); 00394 virtual ScriptOperation* MakeCopy(); 00395 }; 00396 00397 //----------------------------------------------------------------------------- 00398 00402 class BusyOperation : public ScriptOperation 00403 { 00404 protected: 00405 bool busy; 00406 public: 00407 00408 BusyOperation(bool busy): ScriptOperation(busy?"Busy":"Idle"),busy(busy) {}; 00409 virtual ~BusyOperation() {}; 00410 virtual OperationResult Run(NPC* npc,bool interrupted); 00411 virtual bool Load(iDocumentNode* node); 00412 virtual ScriptOperation* MakeCopy(); 00413 }; 00414 00415 //----------------------------------------------------------------------------- 00416 00420 class CastOperation : public ScriptOperation 00421 { 00422 protected: 00423 csString spell; 00424 csString kFactor; 00425 00432 CastOperation(const CastOperation* other); 00433 00434 public: 00435 CastOperation(); 00436 virtual ~CastOperation() {}; 00437 virtual OperationResult Run(NPC* npc,bool interrupted); 00438 virtual bool Load(iDocumentNode* node); 00439 virtual ScriptOperation* MakeCopy(); 00440 }; 00441 00442 //----------------------------------------------------------------------------- 00443 00447 class ChangeBrainOperation : public ScriptOperation 00448 { 00449 protected: 00450 csString brain; 00451 00458 ChangeBrainOperation(const ChangeBrainOperation* other); 00459 00460 public: 00461 ChangeBrainOperation(); 00462 virtual ~ChangeBrainOperation() {}; 00463 virtual OperationResult Run(NPC* npc,bool interrupted); 00464 virtual bool Load(iDocumentNode* node); 00465 virtual ScriptOperation* MakeCopy(); 00466 }; 00467 00468 //----------------------------------------------------------------------------- 00469 00474 class ChaseOperation : public MovementOperation 00475 { 00476 protected: 00481 EID targetEID; 00482 float offsetAngle; 00483 csVector3 offsetDelta; 00484 float adaptivVelScale; 00485 MathScript* calcAdaptivVelocity; 00486 00487 00493 int type; 00494 float searchRange; 00495 float chaseRange; 00496 00497 csString offsetAttribute; 00498 float offsetAngleMax; 00499 float sideOffset; 00500 bool offsetRelativeHeading; 00501 csString adaptivVelocityScript; 00502 00503 00504 enum 00505 { 00506 NEAREST_ACTOR, 00507 NEAREST_NPC, 00508 NEAREST_PLAYER, 00509 OWNER, 00510 TARGET 00511 }; 00512 static const char* typeStr[]; 00513 00520 ChaseOperation(const ChaseOperation* other); 00521 00522 public: 00528 ChaseOperation(); 00529 00532 virtual ~ChaseOperation() {} 00533 00541 csVector3 CalculateOffsetDelta(NPC* npc, const csVector3 &myPos, const iSector* mySector, 00542 const csVector3 &endPos, const iSector* endSector, 00543 float endRot) const; 00544 00550 virtual bool GetEndPosition(NPC* npc, const csVector3 &myPos, const iSector* mySector, 00551 csVector3 &endPos, iSector* &endSector); 00552 00558 virtual gemNPCActor* UpdateChaseTarget(NPC* npc, const csVector3 &myPos, const iSector* mySector); 00559 00565 virtual bool UpdateEndPosition(NPC* npc, const csVector3 &myPos, const iSector* mySector, 00566 csVector3 &endPos, iSector* &endSector); 00567 00573 virtual bool Load(iDocumentNode* node); 00574 00578 virtual float GetOffset(NPC* npc) const; 00579 00585 float AdaptivVelocity(NPC* npc, float distance); 00586 00590 virtual float GetVelocity(NPC* npc); 00591 00592 00598 virtual ScriptOperation* MakeCopy(); 00599 }; 00600 00601 00602 //----------------------------------------------------------------------------- 00603 00607 class CopyLocateOperation : public ScriptOperation 00608 { 00609 protected: 00610 csString source; 00611 csString destination; 00612 unsigned int flags; 00613 public: 00614 00615 CopyLocateOperation(): ScriptOperation("CopyLocate"), flags(NPC::LOCATION_ALL) {}; 00616 virtual ~CopyLocateOperation() {}; 00617 virtual OperationResult Run(NPC* npc,bool interrupted); 00618 virtual bool Load(iDocumentNode* node); 00619 virtual ScriptOperation* MakeCopy(); 00620 }; 00621 00622 //----------------------------------------------------------------------------- 00623 00627 class DeleteNPCOperation : public ScriptOperation 00628 { 00629 protected: 00637 DeleteNPCOperation(const DeleteNPCOperation* other); 00638 00639 public: 00640 DeleteNPCOperation(); 00641 virtual ~DeleteNPCOperation() {}; 00642 virtual OperationResult Run(NPC* npc,bool interrupted); 00643 virtual bool Load(iDocumentNode* node); 00644 virtual ScriptOperation* MakeCopy(); 00645 }; 00646 00647 //----------------------------------------------------------------------------- 00648 00652 class MoveOperation : public ScriptOperation 00653 { 00654 protected: 00655 csString action; 00656 float duration; 00657 00658 float angle; 00659 00660 // Instance temp variables. These dosn't need to be copied. 00661 float remaining; 00662 00663 MoveOperation(const char* n): ScriptOperation(n),remaining(0.0f) 00664 { 00665 duration = 0; 00666 ang_vel = 0; 00667 angle = 0; 00668 } 00669 public: 00670 00671 MoveOperation(): ScriptOperation("Move"),remaining(0.0f) 00672 { 00673 duration = 0; 00674 ang_vel = 0; 00675 angle = 0; 00676 } 00677 virtual ~MoveOperation() { } 00678 virtual bool Load(iDocumentNode* node); 00679 virtual ScriptOperation* MakeCopy(); 00680 00681 virtual OperationResult Run(NPC* npc,bool interrupted); 00682 virtual OperationResult Advance(float timedelta,NPC* npc); 00683 virtual void InterruptOperation(NPC* npc); 00684 00685 }; 00686 00687 //----------------------------------------------------------------------------- 00688 00692 class AutoMemorizeOperation : public ScriptOperation 00693 { 00694 protected: 00695 csString types; 00696 bool enable; 00697 public: 00698 00699 AutoMemorizeOperation(): ScriptOperation("AutoMemorize"), enable(false) { } 00700 virtual ~AutoMemorizeOperation() { } 00701 virtual bool Load(iDocumentNode* node); 00702 virtual ScriptOperation* MakeCopy(); 00703 00704 virtual OperationResult Run(NPC* npc,bool interrupted); 00705 }; 00706 00707 //----------------------------------------------------------------------------- 00708 00712 class CircleOperation : public MoveOperation 00713 { 00714 protected: 00715 float radius; 00716 public: 00717 00718 CircleOperation(): MoveOperation("Circle") 00719 { 00720 radius = 0.0f; 00721 } 00722 virtual ~CircleOperation() { } 00723 virtual bool Load(iDocumentNode* node); 00724 virtual ScriptOperation* MakeCopy(); 00725 00726 virtual OperationResult Run(NPC* npc,bool interrupted); 00727 }; 00728 00729 //----------------------------------------------------------------------------- 00730 00734 class ControlOperation : public ScriptOperation 00735 { 00736 protected: 00737 bool control; // Should this operation take or release control 00738 public: 00739 00740 ControlOperation(bool control): ScriptOperation("Control"), control(control) { } 00741 virtual ~ControlOperation() { } 00742 virtual bool Load(iDocumentNode* node); 00743 virtual ScriptOperation* MakeCopy(); 00744 00745 virtual OperationResult Run(NPC* npc,bool interrupted); 00746 }; 00747 00748 //----------------------------------------------------------------------------- 00749 00753 class DebugOperation : public ScriptOperation 00754 { 00755 protected: 00756 int level; 00757 csString exclusive; 00758 00759 public: 00760 00761 DebugOperation(): ScriptOperation("Debug"),level(0) {}; 00762 virtual ~DebugOperation() {}; 00763 virtual OperationResult Run(NPC* npc,bool interrupted); 00764 virtual bool Load(iDocumentNode* node); 00765 virtual ScriptOperation* MakeCopy(); 00766 }; 00767 00768 //----------------------------------------------------------------------------- 00769 00773 class DequipOperation : public ScriptOperation 00774 { 00775 protected: 00776 csString slot; 00777 00778 public: 00779 00780 DequipOperation(): ScriptOperation("Dequip") {}; 00781 virtual ~DequipOperation() {}; 00782 virtual OperationResult Run(NPC* npc,bool interrupted); 00783 virtual bool Load(iDocumentNode* node); 00784 virtual ScriptOperation* MakeCopy(); 00785 }; 00786 00787 //----------------------------------------------------------------------------- 00788 00798 class WorkOperation : public ScriptOperation 00799 { 00800 protected: 00801 csString type; 00802 csString resource; 00803 00804 public: 00805 00806 WorkOperation(): ScriptOperation("Work") {}; 00807 virtual ~WorkOperation() {}; 00808 virtual OperationResult Run(NPC* npc,bool interrupted); 00809 virtual bool Load(iDocumentNode* node); 00810 virtual ScriptOperation* MakeCopy(); 00811 }; 00812 00813 //----------------------------------------------------------------------------- 00814 00819 class DropOperation : public ScriptOperation 00820 { 00821 protected: 00822 csString slot; 00823 00824 public: 00825 00826 DropOperation(): ScriptOperation("Drop") {}; 00827 virtual ~DropOperation() {}; 00828 virtual OperationResult Run(NPC* npc,bool interrupted); 00829 virtual bool Load(iDocumentNode* node); 00830 virtual ScriptOperation* MakeCopy(); 00831 }; 00832 00833 //----------------------------------------------------------------------------- 00834 00842 class EatOperation : public ScriptOperation 00843 { 00844 protected: 00845 csString resource; 00846 00847 public: 00848 00849 EatOperation(): ScriptOperation("Eat") {}; 00850 virtual ~EatOperation() {}; 00851 virtual OperationResult Run(NPC* npc,bool interrupted); 00852 virtual bool Load(iDocumentNode* node); 00853 virtual ScriptOperation* MakeCopy(); 00854 }; 00855 00856 //----------------------------------------------------------------------------- 00857 00866 class EmoteOperation : public ScriptOperation 00867 { 00868 protected: 00869 csString cmd; 00870 00871 public: 00872 00873 EmoteOperation(): ScriptOperation("Emote") {}; 00874 virtual ~EmoteOperation() {}; 00875 virtual OperationResult Run(NPC* npc,bool interrupted); 00876 virtual bool Load(iDocumentNode* node); 00877 virtual ScriptOperation* MakeCopy(); 00878 }; 00879 00880 //----------------------------------------------------------------------------- 00881 00888 class EquipOperation : public ScriptOperation 00889 { 00890 protected: 00891 csString item; 00892 csString slot; 00893 int count; // Number of items to pick up from a stack 00894 00895 public: 00896 00897 EquipOperation(): ScriptOperation("Equip"),count(0) {}; 00898 virtual ~EquipOperation() {}; 00899 virtual OperationResult Run(NPC* npc,bool interrupted); 00900 virtual bool Load(iDocumentNode* node); 00901 virtual ScriptOperation* MakeCopy(); 00902 }; 00903 00904 //----------------------------------------------------------------------------- 00905 00909 class HateListOperation : public ScriptOperation 00910 { 00911 protected: 00915 enum 00916 { 00917 MAX_HATE = 0x0001, 00918 MIN_HATE = 0x0002, 00919 ABS_HATE = 0x0004, 00920 DELTA_HATE = 0x0008, 00921 HATE_PERCEPTION = 0x0010 00922 }; 00923 00924 unsigned int flags; 00925 float maxHate; 00926 float minHate; 00927 float absoluteHate; 00928 float deltaHate; 00929 public: 00930 00931 HateListOperation(): ScriptOperation("HateList"), flags(0),maxHate(0.0),minHate(0.0),absoluteHate(0.0),deltaHate(0.0) {}; 00932 virtual ~HateListOperation() {}; 00933 virtual OperationResult Run(NPC* npc,bool interrupted); 00934 virtual bool Load(iDocumentNode* node); 00935 virtual ScriptOperation* MakeCopy(); 00936 }; 00937 00938 00939 //----------------------------------------------------------------------------- 00940 00944 class InvisibleOperation : public ScriptOperation 00945 { 00946 public: 00947 00948 InvisibleOperation(): ScriptOperation("Invisible") {}; 00949 virtual ~InvisibleOperation() {}; 00950 virtual OperationResult Run(NPC* npc,bool interrupted); 00951 virtual bool Load(iDocumentNode* node); 00952 virtual ScriptOperation* MakeCopy(); 00953 }; 00954 00955 //----------------------------------------------------------------------------- 00956 00961 class LocateOperation : public ScriptOperation 00962 { 00963 protected: 00964 // Instance variables 00965 bool staticLocated; 00966 NPC::Locate storedStaticLocated; 00967 00968 // Operation parameters 00969 csString object; 00970 float range; 00971 bool static_loc; 00972 bool random; 00973 csString locateOutsideRegion; 00974 bool locateInvisible; 00975 bool locateInvincible; 00976 csString destination; 00977 00978 00979 public: 00980 LocateOperation(); 00981 LocateOperation(const LocateOperation* other); 00982 virtual ~LocateOperation() { } 00983 00985 Waypoint* CalculateWaypoint(NPC* npc, csVector3 located_pos, iSector* located_sector, float located_range); 00986 00987 virtual OperationResult Run(NPC* npc,bool interrupted); 00988 virtual bool Load(iDocumentNode* node); 00989 virtual ScriptOperation* MakeCopy(); 00990 private: 00991 }; 00992 00993 //----------------------------------------------------------------------------- 00994 00999 class LoopBeginOperation : public ScriptOperation 01000 { 01001 public: 01002 int iterations; 01003 01004 public: 01005 01006 LoopBeginOperation(): ScriptOperation("BeginLoop") 01007 { 01008 iterations=0; 01009 } 01010 virtual ~LoopBeginOperation() { } 01011 01012 virtual OperationResult Run(NPC* npc,bool interrupted); 01013 virtual bool Load(iDocumentNode* node); 01014 virtual ScriptOperation* MakeCopy(); 01015 }; 01016 01017 //----------------------------------------------------------------------------- 01018 01023 class LoopEndOperation : public ScriptOperation 01024 { 01025 protected: 01026 int loopback_op; 01027 int current; 01028 int iterations; 01029 01030 public: 01031 01032 LoopEndOperation(int which,int iterations): ScriptOperation("LoopEnd") 01033 { 01034 loopback_op = which; 01035 this->iterations = iterations; 01036 current = 0; 01037 } 01038 virtual ~LoopEndOperation() { } 01039 virtual OperationResult Run(NPC* npc,bool interrupted); 01040 virtual bool Load(iDocumentNode* node); 01041 virtual ScriptOperation* MakeCopy(); 01042 }; 01043 01044 //----------------------------------------------------------------------------- 01045 01050 class MeleeOperation : public ScriptOperation 01051 { 01052 protected: 01053 float seek_range, melee_range; 01054 gemNPCActor* attacked_ent; 01055 csString attackOutsideRegion; 01056 bool attackInvisible; 01057 bool attackInvincible; 01058 csString attack_type; 01059 csString stance; 01060 csString attackMostHatedTribeTarget; 01061 01062 01063 public: 01064 01065 MeleeOperation(): ScriptOperation("Melee"), 01066 attackInvisible(false),attackInvincible(false) 01067 { 01068 attacked_ent=NULL; 01069 seek_range=0; 01070 melee_range=0; 01071 } 01072 virtual ~MeleeOperation() {} 01073 01074 virtual bool Load(iDocumentNode* node); 01075 virtual ScriptOperation* MakeCopy(); 01076 01077 virtual OperationResult Run(NPC* npc,bool interrupted); 01078 virtual OperationResult Advance(float timedelta,NPC* npc); 01079 virtual void InterruptOperation(NPC* npc); 01080 }; 01081 01082 //----------------------------------------------------------------------------- 01083 01087 class MemorizeOperation : public ScriptOperation 01088 { 01089 protected: 01090 01091 public: 01092 01093 MemorizeOperation(): ScriptOperation("Memorize") {}; 01094 virtual ~MemorizeOperation() {}; 01095 virtual OperationResult Run(NPC* npc,bool interrupted); 01096 virtual bool Load(iDocumentNode* node); 01097 virtual ScriptOperation* MakeCopy(); 01098 }; 01099 01100 //----------------------------------------------------------------------------- 01101 01102 // MoveOperation - Definition has been moved before the first user of this 01103 // class as a base class. 01104 01105 //----------------------------------------------------------------------------- 01106 01110 class MovePathOperation : public ScriptOperation 01111 { 01112 protected: 01113 // Parameters 01114 csString anim; 01115 csString pathname; 01116 psPath::Direction direction; 01117 01118 // Internal variables 01119 psPath* path; 01120 psPathAnchor* anchor; 01121 01122 public: 01123 01124 MovePathOperation(): ScriptOperation("MovePath"), direction(psPath::FORWARD), path(0), anchor(0) { } 01125 virtual ~MovePathOperation() 01126 { 01127 delete anchor; 01128 } 01129 virtual bool Load(iDocumentNode* node); 01130 virtual ScriptOperation* MakeCopy(); 01131 01132 virtual OperationResult Run(NPC* npc,bool interrupted); 01133 virtual OperationResult Advance(float timedelta,NPC* npc); 01134 virtual void InterruptOperation(NPC* npc); 01135 }; 01136 01137 //----------------------------------------------------------------------------- 01138 01143 class MoveToOperation : public MovementOperation 01144 { 01145 protected: 01146 csVector3 destPos; 01147 iSector* destSector; 01148 01149 csString memoryCheck; 01150 csString action; 01151 public: 01152 MoveToOperation(); 01153 MoveToOperation(const MoveToOperation* other); 01154 virtual ~MoveToOperation() { } 01155 01156 virtual bool GetEndPosition(NPC* npc, const csVector3 &myPos, const iSector* mySector, 01157 csVector3 &endPos, iSector* &endSector); 01158 01159 virtual bool UpdateEndPosition(NPC* npc, const csVector3 &myPos, const iSector* mySector, 01160 csVector3 &endPos, iSector* &endSector); 01161 01162 virtual bool Load(iDocumentNode* node); 01163 virtual ScriptOperation* MakeCopy(); 01164 }; 01165 01166 //----------------------------------------------------------------------------- 01167 01172 class NavigateOperation : public MovementOperation 01173 { 01174 protected: 01175 csString action; 01176 bool forceEndPosition; 01177 01178 float endAngle; 01179 iSector* endSector; 01180 csVector3 endPos; 01181 01182 public: 01183 01184 NavigateOperation(); 01185 protected: 01186 NavigateOperation(const NavigateOperation* other); 01187 public: 01188 virtual ~NavigateOperation() {}; 01189 01190 virtual ScriptOperation* MakeCopy(); 01191 01192 virtual bool GetEndPosition(NPC* npc, const csVector3 &myPos, const iSector* mySector, 01193 csVector3 &endPos, iSector* &endSector); 01194 01195 virtual bool UpdateEndPosition(NPC* npc, const csVector3 &myPos, const iSector* mySector, 01196 csVector3 &endPos, iSector* &endSector); 01197 01198 virtual bool Load(iDocumentNode* node); 01199 }; 01200 01201 //----------------------------------------------------------------------------- 01202 01206 class NOPOperation : public ScriptOperation 01207 { 01208 protected: 01209 public: 01210 01211 NOPOperation(): ScriptOperation("NOPE") {}; 01212 virtual ~NOPOperation() {}; 01213 virtual OperationResult Run(NPC* npc,bool interrupted); 01214 virtual bool Load(iDocumentNode* node); 01215 virtual ScriptOperation* MakeCopy(); 01216 }; 01217 01218 //----------------------------------------------------------------------------- 01219 01224 class PerceptOperation : public ScriptOperation 01225 { 01226 protected: 01227 enum TargetType 01228 { 01229 SELF, 01230 ALL, 01231 TRIBE, 01232 TARGET 01233 }; 01234 01235 class DelayedPerceptOperationGameEvent : public psGameEvent 01236 { 01237 protected: 01238 NPC* npc; 01239 Perception pcpt; 01240 TargetType target; 01241 float maxRange; 01242 01243 public: 01244 DelayedPerceptOperationGameEvent(int offsetTicks, NPC* npc, Perception &pcpt, TargetType target, float maxRange); 01245 virtual void Trigger(); // Abstract event processing function 01246 virtual csString ToString() const; 01247 }; 01248 01249 csString perception; 01250 csString type; 01251 TargetType target; 01252 float maxRange; 01253 csString condition; 01254 csString failedPerception; 01255 csString delayed; 01256 01257 MathScript* calcCondition; 01258 public: 01259 01260 PerceptOperation() : 01261 ScriptOperation("Percept"), 01262 target(SELF), 01263 maxRange(0.0), 01264 calcCondition(0) 01265 { 01266 } 01267 virtual ~PerceptOperation() {} 01268 virtual OperationResult Run(NPC* npc,bool interrupted); 01269 virtual bool Load(iDocumentNode* node); 01270 virtual ScriptOperation* MakeCopy(); 01271 virtual bool CheckCondition(NPC* npc); 01272 static void TriggerEvent(NPC* npc, Perception &pcpt, TargetType target, float maxRange); 01273 }; 01274 01275 //----------------------------------------------------------------------------- 01276 01281 class PickupOperation : public ScriptOperation 01282 { 01283 protected: 01284 csString object; 01285 csString slot; 01286 int count; // Number of items to pick up from a stack 01287 01288 public: 01289 01290 PickupOperation(): ScriptOperation("Pickup"),count(0) {}; 01291 virtual ~PickupOperation() {}; 01292 virtual OperationResult Run(NPC* npc,bool interrupted); 01293 virtual bool Load(iDocumentNode* node); 01294 virtual ScriptOperation* MakeCopy(); 01295 }; 01296 01297 //----------------------------------------------------------------------------- 01298 01302 class ReproduceOperation : public ScriptOperation 01303 { 01304 protected: 01305 csString tribeMemberType; 01306 public: 01307 01308 ReproduceOperation(): ScriptOperation("Reproduce") {}; 01309 virtual ~ReproduceOperation() {}; 01310 virtual OperationResult Run(NPC* npc,bool interrupted); 01311 virtual bool Load(iDocumentNode* node); 01312 virtual ScriptOperation* MakeCopy(); 01313 }; 01314 01315 //----------------------------------------------------------------------------- 01316 01320 class ResurrectOperation : public ScriptOperation 01321 { 01322 protected: 01323 01324 public: 01325 01326 ResurrectOperation(): ScriptOperation("Resurrect") {}; 01327 virtual ~ResurrectOperation() {}; 01328 virtual OperationResult Run(NPC* npc,bool interrupted); 01329 virtual bool Load(iDocumentNode* node); 01330 virtual ScriptOperation* MakeCopy(); 01331 }; 01332 01333 //----------------------------------------------------------------------------- 01334 01344 class RewardOperation : public ScriptOperation 01345 { 01346 protected: 01347 csString resource; 01348 int count; 01349 01350 public: 01351 01352 RewardOperation(): ScriptOperation("Reward"), count(0) {}; 01353 virtual ~RewardOperation() {}; 01354 virtual OperationResult Run(NPC* npc,bool interrupted); 01355 virtual bool Load(iDocumentNode* node); 01356 virtual ScriptOperation* MakeCopy(); 01357 }; 01358 01359 //----------------------------------------------------------------------------- 01360 01365 class RotateOperation : public ScriptOperation 01366 { 01367 protected: 01368 enum 01369 { 01370 ROT_UNKNOWN, 01371 ROT_ABSOLUTE, // Rotate to this world angle 01372 ROT_RELATIVE, // Rotate delta angle from current npd heading 01373 ROT_TARGET, // Rotate to face target 01374 ROT_LOCATE_DESTINATION, // Rotate to face located destination 01375 ROT_LOCATE_ROTATION, // Rotate to face located rotatation 01376 ROT_RANDOM, // Rotate a random angle 01377 ROT_REGION, // Rotate to an angle within the region 01378 ROT_TRIBE_HOME // Rotate to an angle within tribe home 01379 }; 01380 int op_type; // Type of rotation. See enum above. 01381 float min_range, max_range; // Min,Max values for random and region rotation 01382 float delta_angle; // Value to rotate for relative rotation 01383 01384 float target_angle; // Calculated end rotation for every rotation and 01385 // input to absolute rotation 01386 float angle_delta; // Calculated angle that is needed to rotate to target_angle 01387 01388 csString action; // Animation to use in the rotation 01389 01390 // Instance temp variables. These dosn't need to be copied. 01391 float remaining; 01392 public: 01393 01394 RotateOperation(): ScriptOperation("Rotate") 01395 { 01396 vel=0; 01397 ang_vel=999; 01398 op_type=ROT_UNKNOWN; 01399 min_range=0; 01400 max_range=0; 01401 delta_angle=0; 01402 target_angle=0; 01403 angle_delta=0; 01404 remaining = 0.0; 01405 } 01406 virtual ~RotateOperation() { } 01407 virtual bool Load(iDocumentNode* node); 01408 virtual ScriptOperation* MakeCopy(); 01409 01410 virtual OperationResult Run(NPC* npc,bool interrupted); 01411 virtual OperationResult Advance(float timedelta,NPC* npc); 01412 virtual void InterruptOperation(NPC* npc); 01413 01414 float SeekAngle(NPC* npc, float targetYRot); // Finds an angle which won't lead to a collision 01415 }; 01416 01417 //----------------------------------------------------------------------------- 01418 01422 class VelSourceOperation : public ScriptOperation 01423 { 01424 protected: 01425 public: 01426 01427 VelSourceOperation(): ScriptOperation("VelSource") 01428 { 01429 } 01430 virtual ~VelSourceOperation() { } 01431 virtual bool Load(iDocumentNode* node); 01432 virtual ScriptOperation* MakeCopy(); 01433 virtual OperationResult Run(NPC* npc,bool interrupted); 01434 }; 01435 01436 //----------------------------------------------------------------------------- 01437 01446 class ProgressScriptOperation : public ScriptOperation 01447 { 01448 protected: 01449 csString scriptName; 01450 01451 // Instance temp variables. These dosn't need to be copied. 01452 01453 public: 01454 01455 ProgressScriptOperation(): ScriptOperation("Script") {}; 01456 virtual ~ProgressScriptOperation() {}; 01457 virtual OperationResult Run(NPC* npc,bool interrupted); 01458 virtual bool Load(iDocumentNode* node); 01459 virtual ScriptOperation* MakeCopy(); 01460 }; 01461 01462 //----------------------------------------------------------------------------- 01463 01467 class SequenceOperation : public ScriptOperation 01468 { 01469 protected: 01470 enum // Sequence commands, should use same values as in the psSequenceMessage 01471 { 01472 UNKNOWN = 0, 01473 START = 1, 01474 STOP = 2, 01475 LOOP = 3 01476 }; 01477 01478 csString sequenceName; 01479 int cmd; // See enum above 01480 int count; // Number of times to run the sequence 01481 01482 public: 01483 01484 SequenceOperation(): ScriptOperation("Sequence"),cmd(UNKNOWN),count(0) {}; 01485 virtual ~SequenceOperation() {}; 01486 virtual OperationResult Run(NPC* npc,bool interrupted); 01487 virtual bool Load(iDocumentNode* node); 01488 virtual ScriptOperation* MakeCopy(); 01489 }; 01490 01491 //----------------------------------------------------------------------------- 01492 01496 class SetBufferOperation : public ScriptOperation 01497 { 01498 protected: 01499 enum // Sequence commands, should use same values as in the psSequenceMessage 01500 { 01501 NPC_BUFFER = 0, 01502 TRIBE_BUFFER = 1 01503 }; 01504 01505 csString buffer; 01506 csString value; 01507 int type; 01508 01509 public: 01510 01511 SetBufferOperation(): ScriptOperation("SetBuffer"), type(NPC_BUFFER) {}; 01512 virtual ~SetBufferOperation() {}; 01513 virtual OperationResult Run(NPC* npc,bool interrupted); 01514 virtual bool Load(iDocumentNode* node); 01515 virtual ScriptOperation* MakeCopy(); 01516 }; 01517 01518 //----------------------------------------------------------------------------- 01519 01523 class ShareMemoriesOperation : public ScriptOperation 01524 { 01525 protected: 01526 01527 public: 01528 01529 ShareMemoriesOperation(): ScriptOperation("ShareMemories") {}; 01530 virtual ~ShareMemoriesOperation() {}; 01531 virtual OperationResult Run(NPC* npc,bool interrupted); 01532 virtual bool Load(iDocumentNode* node); 01533 virtual ScriptOperation* MakeCopy(); 01534 }; 01535 01536 //----------------------------------------------------------------------------- 01537 01547 class SitOperation : public ScriptOperation 01548 { 01549 protected: 01550 bool sit; 01551 01552 // Instance temp variables. These dosn't need to be copied. 01553 float remaining; 01554 01555 public: 01556 01557 SitOperation(bool sit): ScriptOperation("Sit"), sit(sit), remaining(0.0) {}; 01558 virtual ~SitOperation() {}; 01559 virtual OperationResult Run(NPC* npc,bool interrupted); 01560 virtual bool Load(iDocumentNode* node); 01561 virtual OperationResult Advance(float timedelta,NPC* npc); 01562 virtual ScriptOperation* MakeCopy(); 01563 }; 01564 01565 //----------------------------------------------------------------------------- 01566 01571 class TalkOperation : public ScriptOperation 01572 { 01573 protected: 01574 typedef psNPCCommandsMessage::PerceptionTalkType TalkType; 01575 01576 csString talkText; 01577 TalkType talkType; 01578 bool talkPublic; 01579 bool target; 01580 csString command; 01581 01582 public: 01583 01584 TalkOperation(): ScriptOperation("Talk"),talkType(psNPCCommandsMessage::TALK_SAY),talkPublic(false),target(false) {}; 01585 virtual ~TalkOperation() {}; 01586 virtual OperationResult Run(NPC* npc,bool interrupted); 01587 virtual bool Load(iDocumentNode* node); 01588 virtual ScriptOperation* MakeCopy(); 01589 }; 01590 01591 //----------------------------------------------------------------------------- 01592 01596 class TeleportOperation : public ScriptOperation 01597 { 01598 protected: 01599 01600 public: 01601 01602 TeleportOperation(): ScriptOperation("Teleport") {}; 01603 virtual ~TeleportOperation() {}; 01604 virtual OperationResult Run(NPC* npc,bool interrupted); 01605 virtual bool Load(iDocumentNode* node); 01606 virtual ScriptOperation* MakeCopy(); 01607 }; 01608 01609 //----------------------------------------------------------------------------- 01610 01615 class TransferOperation : public ScriptOperation 01616 { 01617 protected: 01618 csString item; 01619 int count; 01620 csString target; 01621 01622 public: 01623 01624 TransferOperation(): ScriptOperation("Transfer"), count(0) {}; 01625 virtual ~TransferOperation() {}; 01626 virtual OperationResult Run(NPC* npc,bool interrupted); 01627 virtual bool Load(iDocumentNode* node); 01628 virtual ScriptOperation* MakeCopy(); 01629 }; 01630 01631 //----------------------------------------------------------------------------- 01632 01636 class TribeHomeOperation : public ScriptOperation 01637 { 01638 protected: 01639 01640 public: 01641 01642 TribeHomeOperation(): ScriptOperation("Tribe_Home") {}; 01643 virtual ~TribeHomeOperation() {}; 01644 virtual OperationResult Run(NPC* npc,bool interrupted); 01645 virtual bool Load(iDocumentNode* node); 01646 virtual ScriptOperation* MakeCopy(); 01647 }; 01648 01649 //----------------------------------------------------------------------------- 01650 01654 class TribeTypeOperation : public ScriptOperation 01655 { 01656 protected: 01657 csString tribeType; 01658 public: 01659 01660 TribeTypeOperation(): ScriptOperation("Tribe_Type") {}; 01661 virtual ~TribeTypeOperation() {}; 01662 virtual OperationResult Run(NPC* npc,bool interrupted); 01663 virtual bool Load(iDocumentNode* node); 01664 virtual ScriptOperation* MakeCopy(); 01665 }; 01666 01667 //----------------------------------------------------------------------------- 01668 01672 class VisibleOperation : public ScriptOperation 01673 { 01674 public: 01675 01676 VisibleOperation(): ScriptOperation("Visible") {}; 01677 virtual ~VisibleOperation() {}; 01678 virtual OperationResult Run(NPC* npc,bool interrupted); 01679 virtual bool Load(iDocumentNode* node); 01680 virtual ScriptOperation* MakeCopy(); 01681 }; 01682 01683 //----------------------------------------------------------------------------- 01684 01690 class WaitOperation : public ScriptOperation 01691 { 01692 protected: 01693 csString duration; 01694 csString random; 01695 csString action; 01696 01697 // Instance temp variables. These dosn't need to be copied. 01698 float remaining; 01699 01700 public: 01701 01702 WaitOperation(): ScriptOperation("Wait"),remaining(0.0f) 01703 { 01704 duration=0; 01705 } 01706 virtual ~WaitOperation() { } 01707 01708 virtual OperationResult Run(NPC* npc,bool interrupted); 01709 virtual bool Load(iDocumentNode* node); 01710 virtual OperationResult Advance(float timedelta,NPC* npc); 01711 virtual ScriptOperation* MakeCopy(); 01712 }; 01713 01714 //----------------------------------------------------------------------------- 01715 01720 class WanderOperation : public ScriptOperation 01721 { 01722 protected: 01724 // Start of instance temp variables. These dosn't need to be copied. 01725 01726 class WanderRouteFilter : public psPathNetwork::RouteFilter 01727 { 01728 public: 01729 WanderRouteFilter(WanderOperation* parent):parent(parent) {}; 01730 virtual bool Filter(const Waypoint* waypoint) const; 01731 protected: 01732 WanderOperation* parent; 01733 }; 01734 01735 WanderRouteFilter wanderRouteFilter; 01736 01737 csList<Edge*> edgeList; 01738 01739 csList<Edge*>::Iterator edgeIterator; 01740 Edge* currentEdge; 01741 Edge::Iterator* currentPathPointIterator; 01742 psPathPoint* currentPathPoint; 01743 csVector3 currentPointOffset; 01744 float currentDistance; 01745 // psPath::PathPointIterator pointIterator; 01746 01747 // End of instance temp variables. 01749 01751 // Start of operation parameters 01752 csString action; 01753 bool random; 01754 bool undergroundValid,underground; 01755 bool underwaterValid,underwater; 01756 bool privValid,priv; 01757 bool pubValid,pub; 01758 bool cityValid,city; 01759 bool indoorValid,indoor; 01760 bool pathValid,path; 01761 bool roadValid,road; 01762 bool groundValid,ground; 01763 // End of operation parameters 01765 01770 bool StartMoveTo(NPC* npc, psPathPoint* point); 01771 01776 bool MoveTo(NPC* npc, psPathPoint* point); 01777 01783 OperationResult CalculateEdgeList(NPC* npc); 01784 01785 01788 void SetPathPointIterator(Edge::Iterator* iterator); 01789 01790 public: 01791 01792 WanderOperation(); 01793 WanderOperation(const WanderOperation* other); 01794 virtual ~WanderOperation(); 01795 01796 virtual ScriptOperation* MakeCopy(); 01797 01798 01801 void EdgeListClear() 01802 { 01803 edgeList.DeleteAll(); 01804 } 01805 01811 Edge* GetNextEdge(NPC* npc); 01812 01813 01820 psPathPoint* GetNextPathPoint(NPC* npc, bool &teleport); 01821 01825 psPathPoint* GetCurrentPathPoint(NPC* npc); 01826 01827 01828 /* Utility function to calcualte distance from npc to destPoint. 01829 */ 01830 static float DistanceToDestPoint(NPC* npc, const csVector3 &destPos, const iSector* destSector); 01831 01832 01833 virtual OperationResult Run(NPC* npc,bool interrupted); 01834 virtual OperationResult Advance(float timedelta,NPC* npc); 01835 virtual void InterruptOperation(NPC* npc); 01836 virtual bool Load(iDocumentNode* node); 01837 }; 01838 01839 //----------------------------------------------------------------------------- 01840 01844 class WatchOperation : public ScriptOperation 01845 { 01846 protected: 01847 float watchRange; 01848 int type; 01849 float searchRange; 01850 bool watchInvisible; 01851 bool watchInvincible; 01852 01853 csWeakRef<gemNPCObject> watchedEnt; 01854 01855 enum 01856 { 01857 NEAREST_ACTOR, 01858 NEAREST_NPC, 01859 NEAREST_PLAYER, 01860 OWNER, 01861 TARGET 01862 }; 01863 static const char* typeStr[]; 01864 01865 public: 01866 01867 WatchOperation():ScriptOperation("Watch"),watchRange(0.0f), 01868 type(TARGET),searchRange(0.0f),watchInvisible(false),watchInvincible(false) 01869 { 01870 watchedEnt=NULL; 01871 } 01872 virtual ~WatchOperation() {} 01873 01874 virtual bool Load(iDocumentNode* node); 01875 virtual ScriptOperation* MakeCopy(); 01876 01877 virtual OperationResult Run(NPC* npc,bool interrupted); 01878 virtual OperationResult Advance(float timedelta,NPC* npc); 01879 virtual void InterruptOperation(NPC* npc); 01880 01881 private: 01882 bool OutOfRange(NPC* npc); 01883 }; 01884 01885 //----------------------------------------------------------------------------- 01886 01896 class LootOperation : public ScriptOperation 01897 { 01898 protected: 01899 csString type; 01900 01901 public: 01902 01903 LootOperation(): ScriptOperation("Loot") {}; 01904 virtual ~LootOperation() {}; 01905 virtual OperationResult Run(NPC* npc,bool interrupted); 01906 virtual bool Load(iDocumentNode* node); 01907 virtual ScriptOperation* MakeCopy(); 01908 }; 01909 01910 //----------------------------------------------------------------------------- 01911 01914 #endif