Debian Codegraph @

Descent3/aiambient.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include <stdlib.h>
20 #include "aiambient.h"cxx . . $ `<file>/Descent3/aiambient.h`/
21 #include "string.h"
22 #include "objinfo.h"cxx . . $ `<file>/Descent3/objinfo.h`/
23 #include "game.h"cxx . . $ `<file>/Descent3/game.h`/
24 #include "psrand.h"cxx . . $ `<file>/misc/psrand.h`/
25
26 ambient_lifecxx . . $ ambient_life# a_lifecxx . . $ a_life.;
27
28 #define AL_VERSIONcxx . . $ `Descent3/aiambient.cpp:28:9`! 1
29
30 void ambient_lifecxx . . $ ambient_life#::DoFramecxx . . $ ambient_life#DoFrame(49f6e7a06ebc5aa8).(void) {}
31
32 void ambient_lifecxx . . $ ambient_life#::InitForLevelcxx . . $ ambient_life#InitForLevel(49f6e7a06ebc5aa8).(void) {
33 char i;
34
35 for (i = 0; i < MAX_AL_TYPEScxx . . $ `Descent3/aiambient.h:24:9`!; i++) {
36 ComputeNextSizecxx . . $ ambient_life#ComputeNextSize(44b6ea1973a07080).(i);
37 m_cur_numcxx . . $ ambient_life#m_cur_num.[i] = 0;
38 m_next_do_timecxx . . $ ambient_life#m_next_do_time.[i] = Gametimecxx . . $ Gametime.;
39 }
40
41 DoFramecxx . . $ ambient_life#DoFrame(49f6e7a06ebc5aa8).();
42 }
43
44 void ambient_lifecxx . . $ ambient_life#::GetALValuecxx . . $ ambient_life#GetALValue(dca1de0465141aaf).(char i, char field, void *ptr) {
45 switch (field) {
46 case ALI_TYPEcxx . . $ `Descent3/aiambient.h:29:9`!:
47 *((int *)ptr) = m_typecxx . . $ ambient_life#m_type.[i];
48 break;
49 case ALI_TOTALcxx . . $ `Descent3/aiambient.h:30:9`!:
50 *((uint8_tcxx . . $ uint8_t# *)ptr) = m_totalcxx . . $ ambient_life#m_total.[i];
51 break;
52 case ALI_MAXcxx . . $ `Descent3/aiambient.h:31:9`!:
53 *((uint8_tcxx . . $ uint8_t# *)ptr) = m_maxcxx . . $ ambient_life#m_max.[i];
54 break;
55 case ALI_MINcxx . . $ `Descent3/aiambient.h:32:9`!:
56 *((uint8_tcxx . . $ uint8_t# *)ptr) = m_mincxx . . $ ambient_life#m_min.[i];
57 break;
58 case ALI_FLAGScxx . . $ `Descent3/aiambient.h:33:9`!:
59 *((uint8_tcxx . . $ uint8_t# *)ptr) = m_flagscxx . . $ ambient_life#m_flags.[i];
60 break;
61 }
62 }
63
64 void ambient_lifecxx . . $ ambient_life#::ComputeNextSizecxx . . $ ambient_life#ComputeNextSize(44b6ea1973a07080).(char i) {
65 char diff = m_maxcxx . . $ ambient_life#m_max.[i] - m_mincxx . . $ ambient_life#m_min.[i];
66 if (diff > 0) {
67 char offset = ps_randcxx . . $ ps_rand(b126dc7c1de90089).() % diff;
68 m_next_sizecxx . . $ ambient_life#m_next_size.[i] = m_mincxx . . $ ambient_life#m_min.[i] + offset;
69 } else {
70 m_next_sizecxx . . $ ambient_life#m_next_size.[i] = m_maxcxx . . $ ambient_life#m_max.[i];
71 }
72 }
73
74 void ambient_lifecxx . . $ ambient_life#::SetALValuecxx . . $ ambient_life#SetALValue(dca1de0465141aaf).(char i, char field, void *ptr) {
75 switch (field) {
76 case ALI_TYPEcxx . . $ `Descent3/aiambient.h:29:9`!:
77 m_typecxx . . $ ambient_life#m_type.[i] = *((int *)ptr);
78 break;
79 case ALI_TOTALcxx . . $ `Descent3/aiambient.h:30:9`!:
80 m_totalcxx . . $ ambient_life#m_total.[i] = *((uint8_tcxx . . $ uint8_t# *)ptr);
81 break;
82 case ALI_MAXcxx . . $ `Descent3/aiambient.h:31:9`!:
83 m_maxcxx . . $ ambient_life#m_max.[i] = *((uint8_tcxx . . $ uint8_t# *)ptr);
84 break;
85 case ALI_MINcxx . . $ `Descent3/aiambient.h:32:9`!:
86 m_mincxx . . $ ambient_life#m_min.[i] = *((uint8_tcxx . . $ uint8_t# *)ptr);
87 break;
88 case ALI_FLAGScxx . . $ `Descent3/aiambient.h:33:9`!:
89 m_flagscxx . . $ ambient_life#m_flags.[i] = *((uint8_tcxx . . $ uint8_t# *)ptr);
90 break;
91 }
92
93 // Jeff(Linux): Commented out because m_total[] is unsigned, so never negative
94 // if(m_total[i] < 0)
95 // m_total[i] = 0;
96 if (m_totalcxx . . $ ambient_life#m_total.[i] > MAX_ALS_PER_TYPEcxx . . $ `Descent3/aiambient.h:25:9`!)
97 m_totalcxx . . $ ambient_life#m_total.[i] = MAX_ALS_PER_TYPEcxx . . $ `Descent3/aiambient.h:25:9`!;
98
99 // Jeff(Linux): Commented out because m_max[] is unsigned, so never negative
100 // if(m_max[i] < 0)
101 // m_max[i] = 0;
102 if (m_maxcxx . . $ ambient_life#m_max.[i] > m_totalcxx . . $ ambient_life#m_total.[i])
103 m_maxcxx . . $ ambient_life#m_max.[i] = m_totalcxx . . $ ambient_life#m_total.[i];
104
105 // Jeff(Linux): Commented out because m_min[] is unsigned, so never negative
106 // if(m_min[i] < 0)
107 // m_min[i] = 0;
108 if (m_mincxx . . $ ambient_life#m_min.[i] > m_maxcxx . . $ ambient_life#m_max.[i])
109 m_mincxx . . $ ambient_life#m_min.[i] = m_maxcxx . . $ ambient_life#m_max.[i];
110
111 ComputeNextSizecxx . . $ ambient_life#ComputeNextSize(44b6ea1973a07080).(i);
112 }
113
114 void ambient_lifecxx . . $ ambient_life#::ALResetcxx . . $ ambient_life#ALReset(49f6e7a06ebc5aa8).() {
115 int i;
116 int j;
117
118 for (i = 0; i < MAX_AL_TYPEScxx . . $ `Descent3/aiambient.h:24:9`!; i++) {
119 m_typecxx . . $ ambient_life#m_type.[i] = -1;
120
121 for (j = 0; j < MAX_ALS_PER_TYPEcxx . . $ `Descent3/aiambient.h:25:9`!; j++) {
122 m_handlecxx . . $ ambient_life#m_handle.[i][j] = 0;
123 }
124
125 m_totalcxx . . $ ambient_life#m_total.[i] = 0;
126 m_cur_numcxx . . $ ambient_life#m_cur_num.[i] = 0;
127 m_flagscxx . . $ ambient_life#m_flags.[i] = 0;
128
129 m_mincxx . . $ ambient_life#m_min.[i] = 0;
130 m_maxcxx . . $ ambient_life#m_max.[i] = 0;
131
132 m_next_do_timecxx . . $ ambient_life#m_next_do_time.[i] = 0;
133 m_next_sizecxx . . $ ambient_life#m_next_size.[i] = 0;
134 }
135 }
136
137 void ambient_lifecxx . . $ ambient_life#::SaveDatacxx . . $ ambient_life#SaveData(3639e799710acb68).(CFILEcxx . . $ CFILE# *fp) {
138 int i, j;
139 int16_t len;
140
141 cf_WriteIntcxx . . $ cf_WriteInt(966989f25543eb13).(fp, AL_VERSIONcxx . . $ `Descent3/aiambient.cpp:28:9`!);
142
143 for (i = 0; i < MAX_AL_TYPEScxx . . $ `Descent3/aiambient.h:24:9`!; i++) {
144 int type = m_typecxx . . $ ambient_life#m_type.[i];
145
146 if (type >= 0) {
147 len = strlen(Object_infocxx . . $ Object_info.[type].namecxx . . $ object_info#name.) + 1; // Accounts for NULL charactor
148 cf_WriteShortcxx . . $ cf_WriteShort(d7cf1a05aca96fe5).(fp, len);
149 for (j = 0; j < len; j++) {
150 cf_WriteBytecxx . . $ cf_WriteByte(17377ebd5835367f).(fp, Object_infocxx . . $ Object_info.[type].namecxx . . $ object_info#name.[j]);
151 }
152 } else {
153 cf_WriteShortcxx . . $ cf_WriteShort(d7cf1a05aca96fe5).(fp, 1);
154 cf_WriteBytecxx . . $ cf_WriteByte(17377ebd5835367f).(fp, '\0');
155 }
156
157 cf_WriteBytecxx . . $ cf_WriteByte(17377ebd5835367f).(fp, m_totalcxx . . $ ambient_life#m_total.[i]);
158 cf_WriteBytecxx . . $ cf_WriteByte(17377ebd5835367f).(fp, m_flagscxx . . $ ambient_life#m_flags.[i]);
159 cf_WriteBytecxx . . $ cf_WriteByte(17377ebd5835367f).(fp, m_mincxx . . $ ambient_life#m_min.[i]);
160 cf_WriteBytecxx . . $ cf_WriteByte(17377ebd5835367f).(fp, m_maxcxx . . $ ambient_life#m_max.[i]);
161 cf_WriteBytecxx . . $ cf_WriteByte(17377ebd5835367f).(fp, m_next_sizecxx . . $ ambient_life#m_next_size.[i]);
162 cf_WriteFloatcxx . . $ cf_WriteFloat(c51c6cf5f6d5270c).(fp, m_next_do_timecxx . . $ ambient_life#m_next_do_time.[i]);
163 }
164
165 for (i = 0; i < MAX_AL_TYPEScxx . . $ `Descent3/aiambient.h:24:9`!; i++) {
166 cf_WriteBytecxx . . $ cf_WriteByte(17377ebd5835367f).(fp, m_cur_numcxx . . $ ambient_life#m_cur_num.[i]);
167
168 for (j = 0; j < m_cur_numcxx . . $ ambient_life#m_cur_num.[i]; j++) {
169 cf_WriteIntcxx . . $ cf_WriteInt(966989f25543eb13).(fp, m_handlecxx . . $ ambient_life#m_handle.[i][j]);
170 }
171 }
172 }
173
174 void ambient_lifecxx . . $ ambient_life#::LoadDatacxx . . $ ambient_life#LoadData(3639e799710acb68).(CFILEcxx . . $ CFILE# *fp) {
175 int version = cf_ReadIntcxx . . $ cf_ReadInt(d60d6f5e30f0c96a).(fp);
176 int i, j;
177 int len;
178 char temp_name[256];
179
180 if (version < 1)
181 return;
182
183 for (i = 0; i < MAX_AL_TYPEScxx . . $ `Descent3/aiambient.h:24:9`!; i++) {
184 len = cf_ReadShortcxx . . $ cf_ReadShort(30b00389b433b379).(fp);
185 for (j = 0; j < len; j++) {
186 {
187 temp_name[j] = cf_ReadBytecxx . . $ cf_ReadByte(dcbbf0b0e13758ec).(fp);
188 }
189 }
190
191 m_typecxx . . $ ambient_life#m_type.[i] = FindObjectIDNamecxx . . $ FindObjectIDName(5c4306d8553b3696).(temp_name);
192
193 m_totalcxx . . $ ambient_life#m_total.[i] = cf_ReadBytecxx . . $ cf_ReadByte(dcbbf0b0e13758ec).(fp);
194 m_flagscxx . . $ ambient_life#m_flags.[i] = cf_ReadBytecxx . . $ cf_ReadByte(dcbbf0b0e13758ec).(fp);
195 m_mincxx . . $ ambient_life#m_min.[i] = cf_ReadBytecxx . . $ cf_ReadByte(dcbbf0b0e13758ec).(fp);
196 m_maxcxx . . $ ambient_life#m_max.[i] = cf_ReadBytecxx . . $ cf_ReadByte(dcbbf0b0e13758ec).(fp);
197 m_next_sizecxx . . $ ambient_life#m_next_size.[i] = cf_ReadBytecxx . . $ cf_ReadByte(dcbbf0b0e13758ec).(fp);
198 m_next_do_timecxx . . $ ambient_life#m_next_do_time.[i] = cf_ReadFloatcxx . . $ cf_ReadFloat(9a03a00aead0d542).(fp);
199 }
200
201 for (i = 0; i < MAX_AL_TYPEScxx . . $ `Descent3/aiambient.h:24:9`!; i++) {
202 m_cur_numcxx . . $ ambient_life#m_cur_num.[i] = cf_ReadBytecxx . . $ cf_ReadByte(dcbbf0b0e13758ec).(fp);
203
204 for (j = 0; j < m_cur_numcxx . . $ ambient_life#m_cur_num.[i]; j++) {
205 m_handlecxx . . $ ambient_life#m_handle.[i][j] = cf_ReadIntcxx . . $ cf_ReadInt(d60d6f5e30f0c96a).(fp);
206 }
207 }
208 }