annotate src/things.cc @ 85:dd99c66ed169

More cosmetics.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 26 Sep 2011 18:19:59 +0300
parents a68786b9c74b
children 20aa5a515896
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
2 * things.cc
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
3 * Misc things routines.
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
4 * BW & RQ sometime in 1993 or 1994.
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 */
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 /*
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 This file is part of Yadex.
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 Yadex incorporates code from DEU 5.21 that was put in the public domain in
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 1994 by Raphaël Quinet and Brendon Wyber.
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 The rest of Yadex is Copyright © 1997-2003 André Majorel and others.
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 This program is free software; you can redistribute it and/or modify it under
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 the terms of the GNU General Public License as published by the Free Software
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 Foundation; either version 2 of the License, or (at your option) any later
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 version.
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 This program is distributed in the hope that it will be useful, but WITHOUT
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 You should have received a copy of the GNU General Public License along with
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 Place, Suite 330, Boston, MA 02111-1307, USA.
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 */
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 #define YC_THINGS
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 #include "yadex.h"
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35 #include "game.h"
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 #include "things.h"
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 // This is the structure of a table of things attributes.
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 // In this table, things are sorted by increasing number.
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 // It is searched in a dichotomic fashion by get_thing_*().
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 // This table is only here for speed.
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 typedef struct
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
44 {
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
45 wad_ttype_t type;
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
46 char flags;
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
47 short radius;
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
48 acolour_t colour;
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
49 const char *desc;
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
50 const char *sprite;
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
51 } thing_attributes_t;
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 static thing_attributes_t *things_table;
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 static size_t nthings;
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 int _max_radius;
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
56 static size_t last_table_idx = (size_t) - 1;
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
59 static int things_table_cmp(const void *a, const void *b);
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 static const int default_radius = 16;
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 /*
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
66 * create_things_table
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
67 * Build things_table, a table of things attributes
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
68 * that's used by get_thing_*() to speed things up.
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
69 * Call delete_things_table to delete that table.
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 */
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
71 void create_things_table()
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72 {
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
73 size_t n;
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
75 _max_radius = default_radius;
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
76 nthings = al_lcount(thingdef);
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
77 if (nthings == 0)
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
78 {
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
79 things_table = NULL;
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
80 return;
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
81 }
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
82 things_table =
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
83 (thing_attributes_t *) malloc(nthings * sizeof *things_table);
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
84 if (!things_table)
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
85 fatal_error("Not enough memory");
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
86 for (al_lrewind(thingdef), n = 0; n < nthings; al_lstep(thingdef), n++)
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
87 {
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
88 things_table[n].type = CUR_THINGDEF->number;
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
89 things_table[n].flags = CUR_THINGDEF->flags;
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
90 things_table[n].radius = CUR_THINGDEF->radius;
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
91 _max_radius = y_max(_max_radius, CUR_THINGDEF->radius);
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
93 // Fetch the app colour no. for the thinggroup
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
94 for (al_lrewind(thinggroup); !al_leol(thinggroup);
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
95 al_lstep(thinggroup))
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
96 {
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
97 if (CUR_THINGGROUP /* don't segfault if zero thinggroup ! */
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
98 && CUR_THINGGROUP->thinggroup == CUR_THINGDEF->thinggroup)
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
99 {
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
100 things_table[n].colour = CUR_THINGGROUP->acn;
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
101 break;
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
102 }
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
103 }
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
105 things_table[n].desc = CUR_THINGDEF->desc;
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
106 things_table[n].sprite = CUR_THINGDEF->sprite;
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
107 }
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108
85
dd99c66ed169 More cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 33
diff changeset
109 // Sort the table by increasing thing type
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
110 qsort(things_table, nthings, sizeof *things_table, things_table_cmp);
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112 #if 0
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
113 printf("Type Colour Radius Desc\n");
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
114 for (n = 0; n < nthings; n++)
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
115 printf("%5d %-6d %3d %s\n",
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
116 things_table[n].type,
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
117 things_table[n].colour,
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
118 things_table[n].radius, things_table[n].desc);
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119 #endif
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120 }
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123 /*
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
124 * delete_things_table
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
125 * Free what create_things_table() allocated.
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126 */
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
127 void delete_things_table(void)
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128 {
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
129 if (things_table)
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
130 {
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
131 free(things_table);
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
132 nthings = 0;
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
133 }
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134 }
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137 /*
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
138 * things_table_cmp
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
139 * Used by create_things_table() to sort the table
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
140 * by increasing THING type.
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
141 */
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
142 static int things_table_cmp(const void *a, const void *b)
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143 {
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
144 return ((const thing_attributes_t *) a)->type
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
145 - ((const thing_attributes_t *) b)->type;
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146 }
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
147
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
149 /*
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
150 * lookup_thing
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
151 * Does a binary search in things_table for the thing of type <type>.
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
152 * If succeeds, returns the index of the thing.
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
153 * If fails, returns ((size_t) -1).
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
154 * To further speed things up, the last index found is kept
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
155 * between invocations in a static variable. Thus, if several
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
156 * attributes of the same thing type are queried in a row,
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
157 * the table search is done only once.
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158 */
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
159 inline int lookup_thing(wad_ttype_t type)
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160 {
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
161 if (last_table_idx < nthings && things_table[last_table_idx].type == type)
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
162 return last_table_idx;
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
164 if (things_table == NULL)
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
165 return (size_t) - 1;
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
166
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
167 size_t nmin = 0;
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
168 size_t nmax = nthings - 1;
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
169 for (;;)
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
170 {
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
171 last_table_idx = (nmin + nmax) / 2;
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
172 if (type > things_table[last_table_idx].type)
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
173 {
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
174 if (nmin >= nmax)
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
175 break;
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
176 nmin = last_table_idx + 1;
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
177 }
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
178 else if (type < things_table[last_table_idx].type)
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
179 {
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
180 if (nmin >= nmax)
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
181 break;
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
182 if (last_table_idx < 1)
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
183 break;
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
184 nmax = last_table_idx - 1;
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
185 }
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
186 else
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
187 return last_table_idx;
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
188 }
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
189 return (size_t) - 1;
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
190 }
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
193 /*
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
194 * is_thing_type - is given type valid (i.e. defined in the ygd)
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
195 *
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
196 * Return true if the thing is defined, false otherwise.
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
197 */
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
198 bool is_thing_type(wad_ttype_t type)
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
199 {
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
200 size_t table_idx = lookup_thing(type);
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
201 return table_idx < nthings;
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202 }
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
203
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
204
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
205 /*
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
206 * get_thing_colour - return the colour of the thing of given type.
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
207 *
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
208 * Return the colour. If the
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
209 */
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
210 acolour_t get_thing_colour(wad_ttype_t type)
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
211 {
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
212 size_t table_idx = lookup_thing(type);
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
213 if (table_idx == (size_t) - 1)
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
214 return LIGHTCYAN; // Not found.
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
215 else
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
216 return things_table[table_idx].colour;
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
217 }
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
218
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
219
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
220 /*
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
221 * get_thing_name - return the description of the thing of given type.
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
222 */
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
223 const char *get_thing_name(wad_ttype_t type)
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
224 {
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
225 size_t table_idx = lookup_thing(type);
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
226 if (table_idx == (size_t) - 1)
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
227 {
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
228 static char buf[20];
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
229 sprintf(buf, "UNKNOWN (%d)", type); // Not found.
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
230 return buf;
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
231 }
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
232 else
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
233 return things_table[table_idx].desc;
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
234 }
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
235
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
236
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
237 /*
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
238 * get_thing_sprite
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
239 * Return the root of the sprite name for the thing of given type.
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
240 */
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
241 const char *get_thing_sprite(wad_ttype_t type)
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
242 {
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
243 size_t table_idx = lookup_thing(type);
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
244 if (table_idx == (size_t) - 1)
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
245 return NULL; // Not found
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
246 else
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
247 return things_table[table_idx].sprite;
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
248 }
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
249
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
250
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
251 /*
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
252 * get_thing_flags
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
253 * Return the flags for the thing of given type.
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
254 */
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
255 char get_thing_flags(wad_ttype_t type)
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
256 {
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
257 size_t table_idx = lookup_thing(type);
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
258 if (table_idx == (size_t) - 1)
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
259 return 0; // Not found
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
260 else
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
261 return things_table[table_idx].flags;
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
262 }
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
263
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
264
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
265 /*
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
266 * get_thing_radius
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
267 * Return the radius of the thing of given type.
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
268 */
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
269 int get_thing_radius(wad_ttype_t type)
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
270 {
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
271 size_t table_idx = lookup_thing(type);
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
272 if (table_idx == (size_t) - 1)
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
273 return default_radius; // Not found.
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
274 else
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
275 return things_table[table_idx].radius;
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
276 }
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
277
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
278
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
279 /*
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
280 * get_max_thing_radius
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
281 * Return the radius of the largest thing that exists.
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
282 * This is a speedup function, used by GetCurObject()
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
283 * to avoid calculating the distance for the things
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
284 * that are obviously too far away.
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
285 */
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
286
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
287 /* It's now inlined in things.h
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
288 int get_max_thing_radius ()
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
289 {
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
290 return _max_radius;
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
291 }
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
292 */
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
293
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
294
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
295 /*
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
296 * GetAngleName
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
297 * Get the name of the angle
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
298 */
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
299 const char *GetAngleName(int angle)
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
300 {
85
dd99c66ed169 More cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 33
diff changeset
301 static char buf[32];
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
302
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
303 switch (angle)
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
304 {
85
dd99c66ed169 More cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 33
diff changeset
305 case 0: return "East";
dd99c66ed169 More cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 33
diff changeset
306 case 45: return "North-east";
dd99c66ed169 More cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 33
diff changeset
307 case 90: return "North";
dd99c66ed169 More cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 33
diff changeset
308 case 135: return "North-west";
dd99c66ed169 More cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 33
diff changeset
309 case 180: return "West";
dd99c66ed169 More cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 33
diff changeset
310 case 225: return "South-west";
dd99c66ed169 More cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 33
diff changeset
311 case 270: return "South";
dd99c66ed169 More cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 33
diff changeset
312 case 315: return "South-east";
dd99c66ed169 More cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 33
diff changeset
313 default:
dd99c66ed169 More cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 33
diff changeset
314 sprintf(buf, "ILLEGAL (%d)", angle);
dd99c66ed169 More cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 33
diff changeset
315 return buf;
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
316 }
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
317 }
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
318
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
319
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
320 /*
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
321 * GetWhenName
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
322 * get string of when something will appear
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
323 */
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
324 const char *GetWhenName(int when)
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
325 {
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
326 static char buf[16 + 3 + 1];
85
dd99c66ed169 More cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 33
diff changeset
327 // "N" is a Boom extension ("not in deathmatch")
dd99c66ed169 More cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 33
diff changeset
328 // "C" is a Boom extension ("not in cooperative")
dd99c66ed169 More cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 33
diff changeset
329 // "F" is an MBF extension ("friendly")
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
330 const char *flag_chars = "????" "????" "FCNM" "D431";
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
331 int n;
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
332
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
333 char *b = buf;
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
334 for (n = 0; n < 16; n++)
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
335 {
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
336 if (n != 0 && n % 4 == 0)
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
337 *b++ = ' ';
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
338 if (when & (0x8000u >> n))
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
339 *b++ = flag_chars[n];
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
340 else
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
341 *b++ = '-';
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
342 }
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
343 *b = '\0';
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
344 return buf;
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
345
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
346 #if 0
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
347 static char buf[30];
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
348 char *ptr = buf;
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
349 *ptr = '\0';
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
350 if (when & 0x01)
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
351 {
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
352 strcpy(ptr, "D12");
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
353 ptr += 3;
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
354 }
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
355 if (when & 0x02)
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
356 {
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
357 if (ptr != buf)
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
358 *ptr++ = ' ';
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
359 strcpy(ptr, "D3");
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
360 ptr += 2;
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
361 }
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
362 if (when & 0x04)
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
363 {
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
364 if (ptr != buf)
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
365 *ptr++ = ' ';
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
366 strcpy(ptr, "D45");
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
367 ptr += 3;
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
368 }
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
369 if (when & 0x08)
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
370 {
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
371 if (ptr != buf)
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
372 *ptr++ = ' ';
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
373 strcpy(ptr, "Deaf");
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
374 ptr += 4;
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
375 }
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
376 if (when & 0x10)
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
377 {
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
378 if (ptr != buf)
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
379 *ptr++ = ' ';
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
380 strcpy(ptr, "Multi");
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
381 ptr += 5;
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
382 }
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
383 return buf;
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
384 #endif
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
385 }