1/*
2 * LegacyClonk
3 *
4 * Copyright (c) 2020, The LegacyClonk Team and contributors
5 *
6 * Distributed under the terms of the ISC license; see accompanying file
7 * "COPYING" for details.
8 *
9 * "Clonk" is a registered trademark of Matthes Bender, used with permission.
10 * See accompanying file "TRADEMARK" for details.
11 *
12 * To redistribute this file separately, substitute the full license texts
13 * for the above references.
14 */
15
16#include "C4EnumeratedObjectPtr.h"
17
18#include "C4Game.h"
19#include "C4Object.h"
20#include "StdAdaptors.h"
21#include "StdCompiler.h"
22
23#include <type_traits>
24
25static_assert(std::is_same_v<C4EnumeratedObjectPtr::Enumerated, decltype(C4Object::Number)>, "C4EnumeratedObjectPtr::Enumerated must match the type of C4Object::Number");
26
27void C4EnumeratedObjectPtr::Enumerate()
28{
29 number = Game.Objects.ObjectNumber(pObj: object);
30}
31
32void C4EnumeratedObjectPtr::Denumerate()
33{
34 // only for compatibility with old savegames where Game.Objects.Enumerated() has been used -.-
35 if (Inside(ival: number, lbound: C4EnumPointer1, rbound: C4EnumPointer2))
36 {
37 object = Game.Objects.ObjectPointer(iNumber: number - C4EnumPointer1);
38 }
39 else
40 {
41 object = Game.Objects.ObjectPointer(iNumber: number);
42 }
43}
44
45void C4EnumeratedObjectPtr::CompileFunc(StdCompiler *compiler, bool intPack)
46{
47 if (intPack)
48 {
49 compiler->Value(rStruct: mkIntPackAdapt(rVal&: number));
50 }
51 else
52 {
53 compiler->Value(rInt&: number);
54 }
55}
56