| 1 | /* |
| 2 | * LegacyClonk |
| 3 | * |
| 4 | * Copyright (c) RedWolf Design |
| 5 | * Copyright (c) 2001, Sven2 |
| 6 | * Copyright (c) 2017-2021, 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 | // user-customizable multimedia package Extra.c4g |
| 19 | |
| 20 | #include <C4Include.h> |
| 21 | #include <C4Extra.h> |
| 22 | |
| 23 | #include <C4Config.h> |
| 24 | #include <C4Components.h> |
| 25 | #include <C4Game.h> |
| 26 | #include <C4Log.h> |
| 27 | |
| 28 | void C4Extra::() |
| 29 | { |
| 30 | // zero fields |
| 31 | } |
| 32 | |
| 33 | void C4Extra::() |
| 34 | { |
| 35 | // free class members |
| 36 | ExtraGrp.Close(); |
| 37 | } |
| 38 | |
| 39 | bool C4Extra::() |
| 40 | { |
| 41 | // exists? |
| 42 | if (!ItemExists(szItemName: Config.AtExePath(C4CFN_Extra))) return false; |
| 43 | // open extra group |
| 44 | if (!ExtraGrp.Open(szGroupName: Config.AtExePath(C4CFN_Extra))) return false; |
| 45 | // register extra root into game group set |
| 46 | Game.GroupSet.RegisterGroup(rGroup&: ExtraGrp, fOwnGrp: false, C4GSPrio_ExtraRoot, C4GSCnt_ExtraRoot); |
| 47 | // done, success |
| 48 | return true; |
| 49 | } |
| 50 | |
| 51 | void C4Extra::() |
| 52 | { |
| 53 | // no group: OK |
| 54 | if (!ExtraGrp.IsOpen()) return; |
| 55 | // load from all definitions that are activated |
| 56 | // add first definition first, so the priority will be lowest |
| 57 | // (according to definition load/overload order) |
| 58 | bool fAnythingLoaded = false; |
| 59 | for (const auto &def : Game.DefinitionFilenames) |
| 60 | { |
| 61 | if (LoadDef(hGroup&: ExtraGrp, szName: GetFilename(path: def.c_str()))) |
| 62 | { |
| 63 | fAnythingLoaded = true; |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | bool C4Extra::(C4Group &hGroup, const char *szName) |
| 69 | { |
| 70 | // check if file exists |
| 71 | if (!hGroup.FindEntry(szWildCard: szName)) return false; |
| 72 | // log that extra group is loaded |
| 73 | Log(id: C4ResStrTableKey::IDS_PRC_LOADEXTRA, args: ExtraGrp.GetName(), args&: szName); |
| 74 | // open and add group to set |
| 75 | C4Group *pGrp = new C4Group; |
| 76 | if (!pGrp->OpenAsChild(pMother: &hGroup, szEntryName: szName)) { Log(id: C4ResStrTableKey::IDS_ERR_FAILURE); delete pGrp; return false; } |
| 77 | Game.GroupSet.RegisterGroup(rGroup&: *pGrp, fOwnGrp: true, C4GSPrio_Extra, C4GSCnt_Extra); |
| 78 | // done, success |
| 79 | return true; |
| 80 | } |
| 81 | |