| 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 | // game object lists |
| 19 | |
| 20 | #pragma once |
| 21 | |
| 22 | #include <C4ObjectList.h> |
| 23 | #include <C4FindObject.h> |
| 24 | #include <C4Sector.h> |
| 25 | |
| 26 | class C4ObjResort; |
| 27 | |
| 28 | // main object list class |
| 29 | class C4GameObjects : public C4NotifyingObjectList |
| 30 | { |
| 31 | public: |
| 32 | C4GameObjects(); |
| 33 | ~C4GameObjects(); |
| 34 | void Default(); |
| 35 | void Init(int32_t iWidth, int32_t iHeight); |
| 36 | void Clear(bool fClearInactive = true); // clear objects |
| 37 | |
| 38 | private: |
| 39 | uint32_t LastUsedMarker; // last used value for C4Object::Marker |
| 40 | |
| 41 | public: |
| 42 | C4LSectors Sectors; // section object lists |
| 43 | C4ObjectList InactiveObjects; // inactive objects (Status=2) |
| 44 | C4ObjResort *ResortProc; // current sheduled user resorts |
| 45 | |
| 46 | bool Add(C4Object *nObj); // add object |
| 47 | bool Remove(C4Object *pObj); // clear pointers to object |
| 48 | |
| 49 | C4ObjectList &ObjectsAt(int ix, int iy); // get object list for map pos |
| 50 | |
| 51 | void CrossCheck(); // various collision-checks |
| 52 | C4Object *AtObject(int ctx, int cty, uint32_t &ocf, C4Object *exclude = nullptr); // find object at ctx/cty |
| 53 | void Synchronize(); // network synchronization |
| 54 | uint32_t GetNextMarker(); |
| 55 | |
| 56 | C4Object *FindInternal(C4ID id); // find object in first sector |
| 57 | virtual C4Object *ObjectPointer(int32_t iNumber) override; // object pointer by number |
| 58 | std::int32_t ObjectNumber(C4Object *pObj); // object number by pointer |
| 59 | |
| 60 | C4ObjectList &ObjectsInt(); // return object list containing system objects |
| 61 | |
| 62 | void PutSolidMasks(); |
| 63 | void RemoveSolidMasks(); |
| 64 | |
| 65 | int Load(C4Group &hGroup, bool fKeepInactive); |
| 66 | bool Save(const char *szFilename, bool fSaveGame, bool fSaveInactive); |
| 67 | bool Save(C4Group &hGroup, bool fSaveGame, bool fSaveInactive); |
| 68 | |
| 69 | void UpdateScriptPointers(); // update pointers to C4AulScript * |
| 70 | |
| 71 | void UpdatePos(C4Object *pObj); |
| 72 | void UpdatePosResort(C4Object *pObj); |
| 73 | |
| 74 | bool OrderObjectBefore(C4Object *pObj1, C4Object *pObj2); // order pObj1 before pObj2 |
| 75 | bool OrderObjectAfter(C4Object *pObj1, C4Object *pObj2); // order pObj1 after pObj2 |
| 76 | void FixObjectOrder(); // Called after loading: Resort any objects that are out of order |
| 77 | void ResortUnsorted(); // resort any objects with unsorted-flag set into lists |
| 78 | void ExecuteResorts(); // execute custom resort procs |
| 79 | |
| 80 | void DeleteObjects(); // delete all objects and links |
| 81 | |
| 82 | bool ValidateOwners(); |
| 83 | bool AssignInfo(); |
| 84 | }; |
| 85 | |
| 86 | class C4AulFunc; |
| 87 | |
| 88 | // sheduled resort holder |
| 89 | class C4ObjResort |
| 90 | { |
| 91 | public: |
| 92 | C4ObjResort(); |
| 93 | ~C4ObjResort(); |
| 94 | |
| 95 | void Execute(); // do the resort! |
| 96 | void Sort(C4ObjectLink *pFirst, C4ObjectLink *pLast); // sort list between pFirst and pLast |
| 97 | void SortObject(); // sort single object within its category |
| 98 | |
| 99 | int Category; // object category mask to be sorted |
| 100 | C4AulFunc *OrderFunc; // function determining new sort order |
| 101 | C4ObjResort *Next; // next resort holder |
| 102 | C4Object *pSortObj, *pObjBefore; // objects that are swapped if no OrderFunc is given |
| 103 | bool fSortAfter; // if set, the sort object is sorted |
| 104 | }; |
| 105 | |