00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef __ACTION_RESOURCE_H__
00031 #define __ACTION_RESOURCE_H__
00032
00033 #include "actions.h"
00034
00036
00037 class COrder_Resource : public COrder
00038 {
00039 friend COrder *COrder::NewActionResource(CUnit &harvester, const Vec2i &pos);
00040 friend COrder *COrder::NewActionResource(CUnit &harvester, CUnit &mine);
00041 friend COrder *COrder::NewActionReturnGoods(CUnit &harvester, CUnit *depot);
00042
00043 public:
00044 COrder_Resource(CUnit &harvester) : COrder(UnitActionResource), worker(&harvester),
00045 CurrentResource(0), State(0), TimeToHarvest(0), DoneHarvesting(false) {
00046 Resource.Pos.x = Resource.Pos.y = -1;
00047 goalPos.x = goalPos.y = -1;
00048 }
00049
00050 ~COrder_Resource();
00051
00052 virtual COrder_Resource *Clone() const { return new COrder_Resource(*this); }
00053
00054 virtual bool IsValid() const;
00055
00056 virtual void Save(CFile &file, const CUnit &unit) const;
00057 virtual bool ParseSpecificData(lua_State *l, int &j, const char *value, const CUnit &unit);
00058
00059 virtual void Execute(CUnit &unit);
00060 virtual PixelPos Show(const CViewport &vp, const PixelPos &lastScreenPos) const;
00061 virtual void UpdatePathFinderData(PathFinderInput &input);
00062 virtual bool OnAiHitUnit(CUnit &unit, CUnit *attacker, int );
00063
00064
00065 int GetCurrentResource() const { return CurrentResource; }
00066 Vec2i GetHarvestLocation() const;
00067 bool IsGatheringStarted() const;
00068 bool IsGatheringFinished() const;
00069 bool IsGatheringWaiting() const;
00070 private:
00071 int MoveToResource_Terrain(CUnit &unit);
00072 int MoveToResource_Unit(CUnit &unit);
00073 int MoveToResource(CUnit &unit);
00074 void UnitGotoGoal(CUnit &unit, CUnit *const goal, int state);
00075 int StartGathering(CUnit &unit);
00076 void LoseResource(CUnit &unit, const CUnit &source);
00077 int GatherResource(CUnit &unit);
00078 int StopGathering(CUnit &unit);
00079 int MoveToDepot(CUnit &unit);
00080 bool WaitInDepot(CUnit &unit);
00081 void DropResource(CUnit &unit);
00082 void ResourceGiveUp(CUnit &unit);
00083 bool ActionResourceInit(CUnit &unit);
00084 private:
00085 CUnitPtr worker;
00086 unsigned char CurrentResource;
00087 struct {
00088 Vec2i Pos;
00089 CUnitPtr Mine;
00090 } Resource;
00091 CUnitPtr Depot;
00092 int State;
00093 int TimeToHarvest;
00094 bool DoneHarvesting;
00095 #if 1
00096
00097 Vec2i goalPos;
00098 #endif
00099 };
00100
00102
00103 #endif // !__ACTION_RESOURCE_H__