]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/resources/resources.qh
fa7ce8b73bf448e928a254fb1f62e687d581e0fc
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / resources / resources.qh
1 #pragma once
2
3 #ifdef SVQC
4         #include <common/stats.qh>
5 #endif
6
7 #ifdef CSQC
8 /// \brief Legacy fields for the resources. To be removed.
9 .float health;
10 .float armorvalue;
11 #endif
12
13 #if 1
14 .int ammo_none;
15 .int ammo_shells;
16 .int ammo_nails;
17 .int ammo_rockets;
18 .int ammo_cells;
19 #ifdef SVQC
20 const .int ammo_plasma = _STAT(PLASMA);
21 const .int ammo_fuel = _STAT(FUEL);
22 #else
23 .int ammo_plasma;
24 .int ammo_fuel;
25 #endif
26 #endif
27
28 CLASS(Resource, Object)
29         ATTRIB(Resource, netname, string, "");
30 #ifdef GAMEQC
31         ATTRIB(Resource, m_field, .float, health);
32 #endif
33 ENDCLASS(Resource)
34
35 #define REGISTER_RESOURCE(id, inst) REGISTER(Resources, RES, id, m_id, inst)
36 REGISTRY(Resources, BITS(4));
37 REGISTER_REGISTRY(Resources)
38
39 #ifdef CSQC
40 // Copy Resources registry here before it gets sorted alphabetically by REGISTRY_SORT
41 // so we can keep resources sorted by categories (as they appear in the code)
42 IntrusiveList default_order_resources;
43 STATIC_INIT(default_order_resources)
44 {
45         default_order_resources = IL_NEW();
46         FOREACH(Resources, true, {
47                 IL_PUSH(default_order_resources, it);
48         });
49 }
50 #endif
51
52 REGISTRY_SORT(Resources);
53 REGISTRY_CHECK(Resources);
54
55 REGISTRY_DEFINE_GET(Resources, NULL)
56 STATIC_INIT(Resources_renumber) { FOREACH(Resources, true, it.m_id = i); }
57
58 /// \brief Unconditional maximum amount of resources the entity can have.
59 const int RES_AMOUNT_HARD_LIMIT = 999;
60 const int RES_LIMIT_NONE = -1;
61
62 /// \brief Describes the available resource types.
63 REGISTER_RESOURCE(NONE, NEW(Resource)); ///< Indicates the lack of resource. Use with caution.
64
65 #include "all.inc"
66
67 #ifdef GAMEQC
68 // ===================== Legacy and/or internal API ===========================
69
70 /// \brief Converts an entity field to resource type.
71 /// \param[in] res_field Entity field to convert.
72 /// \return Resource type (a RES_* constant).
73 Resource GetResourceType(.float res_field);
74
75 /// \brief Converts resource type (a RES_* constant) to entity field.
76 /// \param[in] res_type Type of the resource.
77 /// \return Entity field for that resource.
78 .float GetResourceField(Resource res_type);
79 #endif