1 /* 2 * OpenClonk, http://www.openclonk.org 3 * 4 * Copyright (c) 1998-2000, Matthes Bender 5 * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/ 6 * Copyright (c) 2009-2016, The OpenClonk Team and contributors 7 * 8 * Distributed under the terms of the ISC license; see accompanying file 9 * "COPYING" for details. 10 * 11 * "Clonk" is a registered trademark of Matthes Bender, used with permission. 12 * See accompanying file "TRADEMARK" for details. 13 * 14 * To redistribute this file separately, substitute the full license texts 15 * for the above references. 16 */ 17 18 /* Object definition */ 19 20 #ifndef INC_C4Def 21 #define INC_C4Def 22 23 #include "c4group/C4ComponentHost.h" 24 #include "c4group/C4LangStringTable.h" 25 #include "graphics/C4Facet.h" 26 #include "lib/C4InputValidation.h" 27 #include "object/C4DefGraphics.h" 28 #include "object/C4IDList.h" 29 #include "object/C4InfoCore.h" 30 #include "object/C4Shape.h" 31 #include "script/C4PropList.h" 32 #include "script/C4ScriptHost.h" 33 #include "script/C4ValueMap.h" 34 35 #include <functional> 36 37 const int32_t 38 C4D_None = 0, 39 C4D_All = ~0, 40 C4D_StaticBack = 1<<0, 41 C4D_Structure = 1<<1, 42 C4D_Vehicle = 1<<2, 43 C4D_Living = 1<<3, 44 C4D_Object = 1<<4, 45 46 C4D_Goal = 1<<5, 47 C4D_Rule = 1<<6, 48 C4D_Environment = 1<<7, 49 50 C4D_Background = 1<<12, 51 C4D_Parallax = 1<<13, 52 C4D_MouseSelect = 1<<14, 53 C4D_Foreground = 1<<15, 54 C4D_MouseIgnore = 1<<16, 55 C4D_IgnoreFoW = 1<<17, 56 57 C4D_SortLimit = C4D_StaticBack | C4D_Structure | C4D_Vehicle | C4D_Living | C4D_Object 58 | C4D_Background | C4D_Foreground; 59 60 const int32_t C4Plane_Structure = 200; 61 62 const int32_t C4D_Grab_Put = 1, 63 C4D_Grab_Get = 2, 64 65 C4D_Border_Sides = 1, 66 C4D_Border_Top = 2, 67 C4D_Border_Bottom = 4, 68 C4D_Border_Layer = 8, 69 70 C4D_Place_Surface = 0, 71 C4D_Place_Liquid = 1, 72 C4D_Place_Air = 2, 73 C4D_Place_Subsurface = 3, 74 C4D_Place_BothSurface = 4; 75 76 const int32_t C4D_VehicleControl_None = 0, 77 C4D_VehicleControl_Outside = 1, 78 C4D_VehicleControl_Inside = 2; 79 80 const DWORD C4D_Load_None = 0, 81 C4D_Load_Picture = 1, 82 C4D_Load_Bitmap = 2, 83 C4D_Load_Script = 4, 84 85 C4D_Load_Image = 32, 86 C4D_Load_Sounds = 64, 87 C4D_Load_ClonkNames= 128, 88 C4D_Load_RankNames = 256, 89 C4D_Load_RankFaces = 512, 90 C4D_Load_FE = C4D_Load_Image, 91 C4D_Load_RX = C4D_Load_Bitmap | C4D_Load_Script | C4D_Load_ClonkNames | C4D_Load_Sounds | C4D_Load_RankNames | C4D_Load_RankFaces, 92 C4D_Load_Temporary = 1024; 93 94 #define C4D_Blit_Normal 0 95 #define C4D_Blit_Additive 1 96 #define C4D_Blit_ModAdd 2 97 98 class C4Def: public C4PropListStatic 99 { 100 public: 101 C4ID id; 102 int32_t rC4XVer[2]; 103 C4IDList RequireDef; 104 C4Shape Shape; 105 C4Rect Entrance; 106 C4Rect Collection; 107 C4Rect PictureRect; 108 C4TargetRect SolidMask; 109 C4TargetRect TopFace; 110 C4ID BurnTurnTo; 111 int32_t GrowthType; 112 int32_t CrewMember; 113 int32_t NativeCrew; 114 int32_t Mass; 115 int32_t Value; 116 int32_t Exclusive; 117 int32_t Category; 118 int32_t Constructable; 119 int32_t Rotateable; 120 int32_t Float; 121 int32_t ColorByOwner; 122 int32_t NoHorizontalMove; 123 int32_t LiftTop; 124 int32_t GrabPutGet; 125 int32_t UprightAttach; 126 int32_t Line; 127 int32_t LineIntersect; 128 int32_t IncompleteActivity; 129 int32_t Oversize; 130 int32_t Fragile; 131 int32_t Projectile; 132 int32_t NoPushEnter; 133 int32_t VehicleControl; 134 int32_t Pathfinder; 135 int32_t MoveToRange; 136 int32_t NoMassFromContents; 137 int32_t NoStabilize; 138 int32_t ClosedContainer; // if set, contained objects are not damaged by lava/acid etc. 1: Contained objects can't view out; 2: They can 139 int32_t SilentCommands; // if set, no command failure messages are printed 140 int32_t TemporaryCrew; // if set, info objects are not written into regular player files 141 int32_t BlitMode; // special blit mode for objects of this def. C4D_Blit_X 142 int32_t NoBreath; // object does not need to breath, although it's living 143 int32_t ConSizeOff; // number of pixels to be subtracted from the needed height for this building 144 int32_t NoGet; // if set, object can't be taken out of a containers manually (doesn't appear in get/activate-menus) 145 int32_t RotatedEntrance; // 0 entrance not rotateable, 1 entrance always, 2-360 entrance within this rotation 146 int32_t NoTransferZones; 147 int32_t AllowPictureStack; // allow stacking of multiple items in menus even if some attributes do not match. APS_*-values 148 bool HideInCreator; // If true, the definition is not visible in the object creator of the editor 149 public: 150 void DefaultDefCore(); 151 bool LoadDefCore(C4Group &hGroup); 152 bool Save(C4Group &hGroup); 153 void CompileFunc(StdCompiler *pComp); 154 protected: 155 bool Compile(const char *szSource, const char *szName); 156 bool Decompile(StdStrBuf *pOut, const char *szName); 157 private: 158 void LoadMeshMaterials(C4Group &hGroup, C4DefGraphicsPtrBackup *gfx_backup); 159 bool LoadParticleDef(C4Group &hGroup); 160 bool LoadSolidMask(C4Group &hGroup); 161 bool LoadGraphics(C4Group &hGroup, StdMeshSkeletonLoader &loader); 162 void LoadScript(C4Group &hGroup, const char* szLanguage); 163 void LoadClonkNames(C4Group &hGroup, C4ComponentHost* pClonkNames, const char* szLanguage); 164 void LoadRankNames(C4Group &hGroup, const char* szLanguage); 165 void LoadRankFaces(C4Group &hGroup); 166 void LoadSounds(C4Group &hGroup, C4SoundSystem* pSoundSystem); 167 168 std::set<StdCopyStrBuf> mesh_materials; 169 170 // Here begins the C4Def 171 friend class C4DefList; 172 public: 173 C4Def(); 174 ~C4Def() override; 175 public: 176 char Filename[_MAX_FNAME+1]; 177 StdCopyStrBuf ConsoleGroupPath; // file path as used in the definition list viewer in the console. Only initialized in editor mode. 178 int32_t Creation; 179 int32_t Count; // number of instanciations 180 181 C4DefScriptHost Script; 182 C4LangStringTable StringTable; 183 184 // clonknames are simply not needed in frontend 185 C4ComponentHost *pClonkNames; bool fClonkNamesOwned; 186 187 // neither are ranknames nor the symbols...yet! 188 C4RankSystem *pRankNames; bool fRankNamesOwned; 189 C4FacetSurface *pRankSymbols; bool fRankSymbolsOwned; 190 int32_t iNumRankSymbols; // number of rank symbols available, if loaded 191 C4DefGraphics Graphics; // base graphics. points to additional graphics 192 CSurface8 *pSolidMask; // SolidMask-bitmap. Nonzero pixels are solid. 193 194 protected: 195 C4Facet MainFace; 196 197 protected: 198 C4Def *Next; 199 bool Temporary; 200 public: 201 void Clear(); 202 void Default(); 203 bool Load(C4Group &hGroup, 204 StdMeshSkeletonLoader &loader, 205 DWORD dwLoadWhat, const char *szLanguage, 206 class C4SoundSystem *pSoundSystem = nullptr, 207 C4DefGraphicsPtrBackup *gfx_backup = nullptr); 208 void Draw(C4Facet &cgo, bool fSelected=false, DWORD iColor=0, C4Object *pObj=nullptr, int32_t iPhaseX=0, int32_t iPhaseY=0, C4DrawTransform* trans=nullptr, const char * graphicsName=nullptr); 209 210 inline C4Facet &GetMainFace(C4DefGraphics *pGraphics, DWORD dwClr=0) { MainFace.Surface=pGraphics->GetBitmap(dwClr); return MainFace; } GetPlane()211 int32_t GetPlane() { return GetPropertyInt(P_Plane); } 212 int32_t GetValue(C4Object *pInBase, int32_t iBuyPlayer); // get value of def; calling script functions if defined 213 void Synchronize(); GetDef()214 C4Def const * GetDef() const override { return this; } GetDef()215 C4Def * GetDef() override { return this; } Delete()216 bool Delete() override { return false; } 217 protected: 218 bool LoadActMap(C4Group &hGroup); 219 void CrossMapActMap(); 220 public: 221 void IncludeDefinition(C4Def *pIncludeDef); // inherit components from other definition 222 void ResetIncludeDependencies(); // resets all pointers into foreign definitions caused by include chains 223 224 C4PropList *GetActionByName(const char *actname); 225 C4PropList *GetActionByName(C4String *actname); 226 }; 227 228 #endif 229