1/*
2 * LegacyClonk
3 *
4 * Copyright (c) RedWolf Design
5 * Copyright (c) 2001, Sven2
6 * Copyright (c) 2017-2020, The LegacyClonk 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// a set of group files
19// manages system file overwriting by scearios or folders
20
21#pragma once
22
23#include "C4ForwardDeclarations.h"
24
25#include <cstdint>
26
27// group set priorities
28#define C4GSPrio_Base 0 // lowest priority for global system files
29#define C4GSPrio_Definitions 1 // overloads by scenario root definitions
30#define C4GSPrio_ExtraRoot 2 // overloads by Extra.c4g root folder
31#define C4GSPrio_Extra 3 // overloads by Extra.c4g
32#define C4GSPrio_Folder 100 // overloads by local scenario folder - each child folder has higher priority
33#define C4GSPrio_Folder2 199 // highest priority a folder may have
34#define C4GSPrio_Scenario 200 // overloads by scenario: highest priority
35
36// group node contents
37#define C4GSCnt_Graphics 1 // contains Graphics.c4g
38#define C4GSCnt_Loaders 2 // contains loader files
39#define C4GSCnt_Material 4 // contains Material.c4g
40#define C4GSCnt_Music 8 // contains music
41#define C4GSCnt_Definitions 16 // contains definition files
42#define C4GSCnt_FontDefs 32 // contains font definitions
43#define C4GSCnt_Language 64 // contains language files
44#define C4GSCnt_Component 128 // other components
45
46#define C4GSCnt_Folder (C4GSCnt_Graphics | C4GSCnt_Loaders | C4GSCnt_Material | C4GSCnt_Music | C4GSCnt_FontDefs)
47#define C4GSCnt_Directory (C4GSCnt_Loaders | C4GSCnt_Music)
48#define C4GSCnt_Scenario C4GSCnt_Folder
49#define C4GSCnt_Extra (C4GSCnt_Graphics | C4GSCnt_Loaders | C4GSCnt_Material | C4GSCnt_Music | C4GSCnt_FontDefs)
50#define C4GSCnt_ExtraRoot (C4GSCnt_Graphics | C4GSCnt_Loaders | C4GSCnt_Material | C4GSCnt_Music | C4GSCnt_FontDefs)
51#define C4GSCnt_DefinitionRoot (C4GSCnt_Graphics | C4GSCnt_Material | C4GSCnt_Music)
52
53#define C4GSCnt_All ~0
54
55// class predefs
56class C4GroupSet;
57class C4GroupSetNode;
58
59// one node in the group set holds one group
60class C4GroupSetNode
61{
62protected:
63 C4GroupSet *pParent; // owning set
64 C4GroupSetNode *pPrev, *pNext; // linked list - always valid
65
66 C4Group *pGroup; // ptr to group owned by this node
67 bool fGrpOwned; // flag if group ptr is owned
68
69 int32_t id; // group node ID
70
71public:
72 C4GroupSetNode(C4GroupSet &rParent, C4GroupSetNode *pPrev, C4Group &rGroup, bool fGrpOwned, int32_t id);
73 ~C4GroupSetNode();
74
75 int32_t Priority; // group priority
76 int32_t Contents; // content held by this group
77
78 friend class C4GroupSet;
79};
80
81// a group set manages file overloading within several groups
82class C4GroupSet
83{
84protected:
85 C4GroupSetNode *pFirst, *pLast; // linked list
86 int32_t iIndex; // index to keep track of group node IDs
87
88public:
89 void Clear();
90 void Default();
91
92 C4GroupSet();
93 C4GroupSet(C4GroupSet &) = delete;
94 ~C4GroupSet();
95
96 bool RegisterGroup(C4Group &rGroup, bool fOwnGrp, int32_t Priority, int32_t Contents, bool fCheckContent = true); // add group to list
97 bool RegisterGroups(C4GroupSet &rCopy, int32_t Contents, const char *szFilename = nullptr, int32_t iMaxSkipID = 0); // add all matching (child-)groups of the set
98 C4Group *FindGroup(int32_t Contents, C4Group *pAfter = nullptr, bool fSamePrio = false); // search for suitable group in list
99 C4Group *FindEntry(const char *szWildcard, int32_t *pPriority = nullptr, int32_t *pID = nullptr); // find entry in groups; store priority of group if ptr is given
100 C4Group *GetGroup(int32_t iIndex);
101 bool LoadEntryString(const char *szEntryName, StdStrBuf &rBuf);
102 C4Group *RegisterParentFolders(const char *szScenFilename); // register all parent .c4f groups to the given scenario filename and return an open group file of the innermost parent c4f
103
104 static int32_t CheckGroupContents(C4Group &rGroup, int32_t Contents);
105 int32_t GetLastID() { return iIndex; } // return ID assigned to the last added group
106
107 bool CloseFolders(); // remove all groups associated with scenario folders
108
109 friend class C4GroupSetNode;
110};
111