1 /* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
2 
3 #ifndef _FACTORY_H
4 #define _FACTORY_H
5 
6 #include "Building.h"
7 #include "Sim/Misc/NanoPieceCache.h"
8 #include "Sim/Units/CommandAI/Command.h"
9 #include "System/float3.h"
10 
11 struct UnitDef;
12 struct Command;
13 class CFactory;
14 
15 typedef void (*FinishBuildCallBackFunc) (CFactory*, const Command&);
16 
17 class CFactory : public CBuilding
18 {
19 public:
20 	CR_DECLARE(CFactory)
21 
22 	CFactory();
23 
24 	void PostLoad();
25 
26 	void StartBuild(const UnitDef* buildeeDef);
27 	void UpdateBuild(CUnit* buildee);
28 	void FinishBuild(CUnit* buildee);
29 	void StopBuild();
30 	/// @return whether the to-be-built unit is enqueued
31 	unsigned int QueueBuild(const UnitDef* buildeeDef, const Command& buildCmd, FinishBuildCallBackFunc buildCB);
32 
33 	void Update();
34 
35 	void DependentDied(CObject* o);
36 	void CreateNanoParticle(bool highPriority = false);
37 
38 	/// supply the build piece to speed up
39 	float3 CalcBuildPos(int buildPiece = -1);
40 
41 	void KillUnit(CUnit* attacker, bool selfDestruct, bool reclaimed, bool showDeathSequence = true);
42 	void PreInit(const UnitLoadParams& params);
43 	bool ChangeTeam(int newTeam, ChangeType type);
44 
GetNanoPieceCache()45 	const NanoPieceCache& GetNanoPieceCache() const { return nanoPieceCache; }
GetNanoPieceCache()46 	      NanoPieceCache& GetNanoPieceCache()       { return nanoPieceCache; }
47 
48 private:
49 	void SendToEmptySpot(CUnit* unit);
50 	void AssignBuildeeOrders(CUnit* unit);
51 
52 public:
53 	float buildSpeed;
54 
55 	/// whether we are currently opening in preparation to start building
56 	bool opening;
57 
58 	const UnitDef* curBuildDef;
59 	CUnit* curBuild;
60 
61 	enum {
62 		FACTORY_SKIP_BUILD_ORDER = 0,
63 		FACTORY_KEEP_BUILD_ORDER = 1,
64 		FACTORY_NEXT_BUILD_ORDER = 2,
65 	};
66 
67 private:
68 	int nextBuildUnitDefID;
69 	int lastBuildUpdateFrame;
70 
71 	FinishBuildCallBackFunc finishedBuildFunc;
72 	Command finishedBuildCommand;
73 
74 	NanoPieceCache nanoPieceCache;
75 };
76 
77 #endif // _FACTORY_H
78