4 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
6 * This software may be copied and distributed for educational, research,
7 * and not for profit purposes provided that this copyright and statement
8 * are included in all such copies. Other copyrights may also apply.
11 /* Purpose: Code for the object templates */
16 /* Base size of k_info */
17 #define K_INFO_BASE_SIZE 500
19 /* Amount of entries to add when resizing k_info */
20 #define K_INFO_RESIZE 50
22 /* Size of the allocated */
23 static s32b k_info_size = K_INFO_BASE_SIZE;
27 errr k_info_alloc(void)
29 /* Create the storage for the object templates */
30 C_MAKE(k_info, k_info_size, object_kind);
38 errr k_info_free(void)
40 k_info_size = K_INFO_BASE_SIZE;
42 C_KILL(k_info, k_info_size, object_kind);
49 void k_info_reset(void)
53 /* Reset the "objects" */
54 for (i = 1; i < max_k_idx; i++)
56 object_kind *k_ptr = &k_info[i];
67 /* Add a new object template */
68 object_kind *k_info_add(object_kind *k_info_entry)
70 /* Resize if necessary */
71 while (k_info_size <= max_k_idx)
73 k_info_size += K_INFO_RESIZE;
75 /* Reallocate the extra memory */
76 k_info = realloc(k_info, k_info_size * sizeof(object_kind));
80 if (!k_info) quit("¥á¥â¥ê¡¼ÉÔÂ!");
82 if (!k_info) quit("Out of memory!");
86 /* Wipe the new memory */
87 (void)C_WIPE(&k_info[(k_info_size - K_INFO_RESIZE)], K_INFO_RESIZE, object_kind);
90 /* Increase the maximum index of the array */
93 /* Copy the new object_kind */
94 COPY(&k_info[max_k_idx-1], k_info_entry, object_kind);
97 return (&k_info[max_k_idx-1]);
102 * Initialize some other arrays
104 errr init_object_alloc(void)
113 /*** Analyze object allocation info ***/
115 /* Clear the "aux" array */
116 (void)C_WIPE(&aux, MAX_DEPTH, s16b);
118 /* Clear the "num" array */
119 (void)C_WIPE(&num, MAX_DEPTH, s16b);
121 /* Free the old "alloc_kind_table" (if it exists) */
122 if (alloc_kind_table)
124 C_KILL(alloc_kind_table, alloc_kind_size, alloc_entry);
127 /* Size of "alloc_kind_table" */
130 /* Scan the objects */
131 for (i = 1; i < max_k_idx; i++)
135 /* Scan allocation pairs */
136 for (j = 0; j < 4; j++)
138 /* Count the "legal" entries */
139 if (k_ptr->chance[j])
141 /* Count the entries */
145 num[k_ptr->locale[j]]++;
150 /* Collect the level indexes */
151 for (i = 1; i < MAX_DEPTH; i++)
159 if (!num[0]) quit("Ä®¤Î¥¢¥¤¥Æ¥à¤¬¤Ê¤¤¡ª");
161 if (!num[0]) quit("No town objects!");
166 /*** Initialize object allocation info ***/
168 /* Allocate the alloc_kind_table */
169 C_MAKE(alloc_kind_table, alloc_kind_size, alloc_entry);
171 /* Access the table entry */
172 table = alloc_kind_table;
174 /* Scan the objects */
175 for (i = 1; i < max_k_idx; i++)
179 /* Scan allocation pairs */
180 for (j = 0; j < 4; j++)
182 /* Count the "legal" entries */
183 if (k_ptr->chance[j])
187 /* Extract the base level */
188 x = k_ptr->locale[j];
190 /* Extract the base probability */
191 p = (100 / k_ptr->chance[j]);
193 /* Skip entries preceding our locale */
194 y = (x > 0) ? num[x-1] : 0;
196 /* Skip previous entries at this locale */
206 /* Another entry complete for this locale */
217 int get_object_level(object_type *o_ptr)
220 return (byte)get_object_level_callback(o_ptr);
222 return k_info[o_ptr->k_idx].level;
227 s32b get_object_cost(object_type *o_ptr)
230 return get_object_cost_callback(o_ptr);
232 return k_info[o_ptr->k_idx].cost;
237 cptr get_object_name(object_type *o_ptr)
240 return get_object_name_callback(o_ptr);
242 return (k_name + k_info[o_ptr->k_idx].name);
247 /* The player is "aware" of the item's effects */
248 bool get_object_aware(object_type *o_ptr)
251 return get_object_aware_callback(o_ptr);
253 return k_info[o_ptr->k_idx].aware;
258 /* The player has "tried" one of the items */
259 bool get_object_tried(object_type *o_ptr)
262 return get_object_tried_callback(o_ptr);
264 return k_info[o_ptr->k_idx].tried;
269 bool object_is_potion(object_type *o_ptr)
271 return (k_info[o_ptr->k_idx].tval == TV_POTION);
274 bool object_is_shoukinkubi(object_type *o_ptr)
277 if (p_ptr->today_mon > 0 && o_ptr->pval == p_ptr->today_mon) return TRUE;
278 if (o_ptr->pval == MON_TSUCHINOKO) return TRUE;
279 for (i = 0; i < MAX_KUBI; i++)
280 if (o_ptr->pval == kubi_r_idx[i]) break;
281 if (i < MAX_KUBI) return TRUE;