1 /*
2 BStone: A Source port of
3 Blake Stone: Aliens of Gold and Blake Stone: Planet Strike
4 
5 Copyright (c) 1992-2013 Apogee Entertainment, LLC
6 Copyright (c) 2013-2015 Boris I. Bendovsky (bibendovsky@hotmail.com)
7 
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
12 
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the
20 Free Software Foundation, Inc.,
21 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 */
23 
24 
25 #include "3d_def.h"
26 
27 
28 //
29 // Offsets of variables in data segment.
30 //
31 
32 const int OBJLIST_OFFSET = 0xFFFF - MAXACTORS;
33 const int STATOBJLIST_OFFSET = 0xFFFF - MAXSTATS;
34 const int DOOROBJLIST_OFFSET = 0xFFFF - MAXDOORS;
35 
36 
37 void ogl_update_screen();
38 
39 
ui16_to_actor(uint16_t value)40 objtype* ui16_to_actor(
41     uint16_t value)
42 {
43     int index = value - OBJLIST_OFFSET;
44 
45     if (index < 0) {
46         return nullptr;
47     }
48 
49     if (index >= MAXACTORS) {
50         return nullptr;
51     }
52 
53     return &objlist[index];
54 }
55 
actor_to_ui16(const objtype * actor)56 uint16_t actor_to_ui16(
57     const objtype* actor)
58 {
59     auto index = actor - objlist;
60 
61     if (index < 0) {
62         return 0;
63     }
64 
65     if (index >= MAXACTORS) {
66         return 0;
67     }
68 
69     return static_cast<uint16_t>(index + OBJLIST_OFFSET);
70 }
71 
ui16_to_static_object(uint16_t value)72 statobj_t* ui16_to_static_object(
73     uint16_t value)
74 {
75     int index = value - STATOBJLIST_OFFSET;
76 
77     if (index < 0) {
78         return nullptr;
79     }
80 
81     if (index >= MAXSTATS) {
82         return nullptr;
83     }
84 
85     return &statobjlist[index];
86 }
87 
static_object_to_ui16(const statobj_t * static_object)88 uint16_t static_object_to_ui16(
89     const statobj_t* static_object)
90 {
91     auto index = static_object - statobjlist;
92 
93     if (index < 0) {
94         return 0;
95     }
96 
97     if (index >= MAXSTATS) {
98         return 0;
99     }
100 
101     return static_cast<uint16_t>(index + STATOBJLIST_OFFSET);
102 }
103 
ui16_to_door_object(uint16_t value)104 doorobj_t* ui16_to_door_object(
105     uint16_t value)
106 {
107     int index = value - DOOROBJLIST_OFFSET;
108 
109     if (index < 0) {
110         return nullptr;
111     }
112 
113     if (index >= MAXDOORS) {
114         return nullptr;
115     }
116 
117     return &doorobjlist[index];
118 }
119 
door_object_to_ui16(const doorobj_t * door_object)120 uint16_t door_object_to_ui16(
121     const doorobj_t* door_object)
122 {
123     auto index = door_object - doorobjlist;
124 
125     if (index < 0) {
126         return 0;
127     }
128 
129     if (index >= MAXDOORS) {
130         return 0;
131     }
132 
133     return static_cast<uint16_t>(index + DOOROBJLIST_OFFSET);
134 }
135