00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 using System;
00018 using System.Collections.Generic;
00019 using System.Text;
00020 using Microsoft.DirectX;
00021
00022 namespace Game
00023 {
00024 public delegate void ActionCompletedHandler(Action thisisfinished);
00025
00026 public class Action
00027 {
00028 protected IWorldEntity actor;
00029
00030 public IWorldEntity complement = null;
00031
00032 public bool iamdone;
00033
00034 public event ActionCompletedHandler completed;
00035
00036 public Action()
00037 {
00038 iamdone = false;
00039 }
00040
00041 public Action(IWorldEntity theActor) : base()
00042 {
00043 SetActor(theActor);
00044 }
00045
00046 public virtual void SetActor(IWorldEntity theActor)
00047 {
00048 actor = theActor;
00049 }
00050
00051 public virtual bool CheckFeasibility(WorldEntity selectedEntity)
00052 {
00053 return false;
00054 }
00055
00056 public virtual void Update(double appTime, float elapsedTime)
00057 {
00058 if (iamdone)
00059 {
00060 IAmDone();
00061 }
00062 }
00063
00064 public virtual void IAmDone()
00065 {
00066 iamdone = true;
00067 if (completed != null)
00068 {
00069 completed(this);
00070 }
00071 }
00072
00073 public virtual bool Similar(Action action)
00074 {
00075 return false;
00076 }
00077
00078 public static bool Similar(Action ac1, Action ac2)
00079 {
00080 return ac1.Similar(ac2);
00081 }
00082 }
00083
00084 public interface ICanMove : IWorldEntity
00085 {
00086 void Move(Vector3 dir, float elapsedTime);
00087 }
00088
00089 public class Moving : Action
00090 {
00091 public WorldLocation destination;
00092
00093 public Moving(ICanMove theActor)
00094 : base(theActor)
00095 {
00096 }
00097
00098 public override void SetActor(IWorldEntity theActor)
00099 {
00100 ICanMove movingActor = theActor as ICanMove;
00101
00102 if (movingActor == null)
00103 {
00104 throw new ArgumentException("The actor can not move (doesn't implement ICanMove) which is not accepted for this type of action!");
00105 }
00106 else
00107 {
00108 base.SetActor(theActor);
00109 }
00110 }
00111
00112 public override bool CheckFeasibility(WorldEntity selectedEntity)
00113 {
00114 return true;
00115 }
00116
00117 public override void Update(double appTime, float elapsedTime)
00118 {
00119 base.Update(appTime, elapsedTime);
00120
00121 Vector3 dir = Vector3.Subtract(destination.SceneObject.Position, actor.SceneObject.Position);
00122
00123 if (dir.Length() > destination.radius)
00124 {
00125 ((ICanMove)actor).Move(Vector3.Normalize(dir), elapsedTime);
00126 }
00127 else
00128 {
00129 IAmDone();
00130 }
00131 }
00132
00133 public override bool Similar(Action action)
00134 {
00135 bool ret = false;
00136 Moving mov = action as Moving;
00137 if (mov!=null)
00138 {
00139 if (destination.Distance(mov.destination) < 5.0f)
00140 ret = true;
00141 }
00142 return ret;
00143 }
00144 }
00145
00146 public class Sleeping : Action
00147 {
00148 public Sleeping(IWorldEntity theActor)
00149 : base(theActor)
00150 {
00151 }
00152
00153 public override bool Similar(Action action)
00154 {
00155
00156
00157 return false;
00158 }
00159 }
00160
00161 public class Eating : Action
00162 {
00163 public Eating(IWorldEntity theActor)
00164 : base(theActor)
00165 {
00166 }
00167
00168 public override void Update(double appTime, float elapsedTime)
00169 {
00170 IAmDone();
00171 }
00172 public override bool Similar(Action action)
00173 {
00174 return (complement == action.complement);
00175 }
00176 }
00177
00178 public class MovingAround : Action
00179 {
00180 public MovingAround(IWorldEntity theActor)
00181 : base(theActor)
00182 {
00183 }
00184
00185 public override bool Similar(Action action)
00186 {
00187
00188
00189 return false;
00190 }
00191 }
00192
00193 public class LookingForFood : Action
00194 {
00195 public LookingForFood(IWorldEntity theActor)
00196 : base(theActor)
00197 {
00198 }
00199
00200 public override bool Similar(Action action)
00201 {
00202
00203
00204 return false;
00205 }
00206 }
00207
00208 public class Drinking : Action
00209 {
00210 public Drinking(IWorldEntity theActor)
00211 : base(theActor)
00212 {
00213 }
00214
00215 public override bool Similar(Action action)
00216 {
00217
00218
00219 return false;
00220 }
00221 }
00222
00223 public class Fleeing : Action
00224 {
00225 public Fleeing(IWorldEntity theActor)
00226 : base(theActor)
00227 {
00228 }
00229
00230 public override bool Similar(Action action)
00231 {
00232
00233
00234 return false;
00235 }
00236 }
00237
00238 public class Talking : Action
00239 {
00240 public Talking(IWorldEntity theActor)
00241 : base(theActor)
00242 {
00243 }
00244
00245 public override bool Similar(Action action)
00246 {
00247
00248
00249 return false;
00250 }
00251 }
00252 }