-
Notifications
You must be signed in to change notification settings - Fork 5
/
info_rnd.pas
197 lines (168 loc) · 5.74 KB
/
info_rnd.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
//------------------------------------------------------------------------------
//
// FPCDoom - Port of Doom to Free Pascal Compiler
// Copyright (C) 1993-1996 by id Software, Inc.
// Copyright (C) 2004-2007 by Jim Valavanis
// Copyright (C) 2017-2022 by Jim Valavanis
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
//------------------------------------------------------------------------------
// E-Mail: jimmyvalavanis@yahoo.gr
// Site : https://sourceforge.net/projects/fpcdoom/
//------------------------------------------------------------------------------
{$I FPCDoom.inc}
unit info_rnd;
// JVAL: Random items
interface
//==============================================================================
//
// Info_SelectRandomMonster
//
//==============================================================================
function Info_SelectRandomMonster(_type: integer): integer;
//==============================================================================
//
// Info_InitRandom
//
//==============================================================================
procedure Info_InitRandom;
//==============================================================================
//
// Info_ShutDownRandom
//
//==============================================================================
procedure Info_ShutDownRandom;
//==============================================================================
//
// Info_IsMonster
//
//==============================================================================
function Info_IsMonster(_type: integer): boolean;
var
rnd_monster_seed: integer = 0;
implementation
uses
d_fpc,
doomdef,
info,
m_rnd,
p_setup,
p_mobj_h;
type
randompool_t = record
check: integer;
list: TDNumberList;
end;
const
NUMMONSTERSCATEGORIES = 5;
var
rnd_monsters: array[0..NUMMONSTERSCATEGORIES - 1] of randompool_t;
rnd_monstersinitialized: boolean = false;
//==============================================================================
//
// Info_InitRandomMonsters
//
//==============================================================================
procedure Info_InitRandomMonsters;
var
i: integer;
idx: integer;
check: integer;
begin
if rnd_monstersinitialized then
exit;
rnd_monsters[0].check := 80;
rnd_monsters[1].check := 400;
rnd_monsters[2].check := 1200;
rnd_monsters[3].check := 2500;
rnd_monsters[4].check := MAXINT;
for i := 0 to NUMMONSTERSCATEGORIES - 1 do
rnd_monsters[i].list := TDNumberList.Create;
rnd_monstersinitialized := true;
for i := 0 to nummobjtypes - 1 do
if Info_IsMonster(i) and P_GameValidThing(mobjinfo[i].doomednum) then
begin
check := mobjinfo[i].spawnhealth;
idx := 0;
while (idx < NUMMONSTERSCATEGORIES) and (check >= rnd_monsters[idx].check) do
inc(idx);
rnd_monsters[idx].list.Add(i);
end;
end;
//==============================================================================
//
// Info_ShutDownRandomMonsters
//
//==============================================================================
procedure Info_ShutDownRandomMonsters;
var
i: integer;
begin
if not rnd_monstersinitialized then
exit;
for i := 0 to NUMMONSTERSCATEGORIES - 1 do
FreeAndNil(rnd_monsters[i].list);
rnd_monstersinitialized := false;
end;
//==============================================================================
//
// Info_SelectRandomMonster
//
//==============================================================================
function Info_SelectRandomMonster(_type: integer): integer;
var
i, idx: integer;
check: integer;
begin
check := mobjinfo[_type].spawnhealth;
idx := 0;
while (idx < NUMMONSTERSCATEGORIES) and (check >= rnd_monsters[idx].check) do
inc(idx);
for i := 0 to rnd_monster_seed - 1 do
N_Random;
result := rnd_monsters[idx].list[N_Random mod rnd_monsters[idx].list.Count];
end;
//==============================================================================
//
// Info_InitRandom
//
//==============================================================================
procedure Info_InitRandom;
begin
Info_InitRandomMonsters
end;
//==============================================================================
//
// Info_ShutDownRandom
//
//==============================================================================
procedure Info_ShutDownRandom;
begin
Info_ShutDownRandomMonsters
end;
//==============================================================================
//
// Info_IsMonster
//
//==============================================================================
function Info_IsMonster(_type: integer): boolean;
begin
result := (mobjinfo[_type].doomednum > MAXPLAYERS) and // Not player
(mobjinfo[_type].flags and MF_SHOOTABLE <> 0) and // Shootable
((mobjinfo[_type].flags and MF_COUNTKILL <> 0) or (mobjinfo[_type].missilestate <> 0) or (mobjinfo[_type].meleestate <> 0)); // Count kill or can attack
end;
end.