ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/treasure.C
(Generate patch)

Comparing deliantra/server/common/treasure.C (file contents):
Revision 1.24 by root, Tue Dec 12 21:39:56 2006 UTC vs.
Revision 1.30 by elmex, Wed Jan 3 02:30:51 2007 UTC

156 * so that the treasure name can be printed out 156 * so that the treasure name can be printed out
157 */ 157 */
158static void 158static void
159check_treasurelist (const treasure *t, const treasurelist * tl) 159check_treasurelist (const treasure *t, const treasurelist * tl)
160{ 160{
161 if (t->item == NULL && t->name == NULL)
162 LOG (llevError, "Treasurelist %s has element with no name or archetype\n", &tl->name);
163 if (t->chance >= 100 && t->next_yes && (t->next || t->next_no)) 161 if (t->chance >= 100 && t->next_yes && (t->next || t->next_no))
164 LOG (llevError, "Treasurelist %s has element that has 100%% generation, next_yes field as well as next or next_no\n", &tl->name); 162 LOG (llevError, "Treasurelist %s has element that has 100%% generation, next_yes field as well as next or next_no\n", &tl->name);
165 /* find_treasurelist will print out its own error message */ 163 /* find_treasurelist will print out its own error message */
166 if (t->name && *t->name) 164 if (t->name && *t->name)
167 (void) find_treasurelist (t->name); 165 find_treasurelist (t->name);
168 if (t->next) 166 if (t->next)
169 check_treasurelist (t->next, tl); 167 check_treasurelist (t->next, tl);
170 if (t->next_yes) 168 if (t->next_yes)
171 check_treasurelist (t->next_yes, tl); 169 check_treasurelist (t->next_yes, tl);
172 if (t->next_no) 170 if (t->next_no)
258 shstr_cmp name_ (name); 256 shstr_cmp name_ (name);
259 257
260 if (!name_) 258 if (!name_)
261 return 0; 259 return 0;
262 260
263 for (treasurelist * tl = first_treasurelist; tl != 0; tl = tl->next) 261 for (treasurelist *tl = first_treasurelist; tl != 0; tl = tl->next)
264 if (name_ == tl->name) 262 if (name_ == tl->name)
265 return tl; 263 return tl;
266 264
267 if (first_treasurelist) 265 if (first_treasurelist)
268 LOG (llevError, "Couldn't find treasurelist %s\n", name); 266 LOG (llevError, "Couldn't find treasurelist %s\n", name);
280 * being generated. 278 * being generated.
281 * If flag is GT_INVISIBLE, only invisible objects are generated (ie, only 279 * If flag is GT_INVISIBLE, only invisible objects are generated (ie, only
282 * abilities. This is used by summon spells, thus no summoned monsters 280 * abilities. This is used by summon spells, thus no summoned monsters
283 * start with equipment, but only their abilities). 281 * start with equipment, but only their abilities).
284 */ 282 */
285
286
287static void 283static void
288put_treasure (object *op, object *creator, int flags) 284put_treasure (object *op, object *creator, int flags)
289{ 285{
290 object *tmp; 286 object *tmp;
291 287
294 * this is the original object, or if this is an object that should be created 290 * this is the original object, or if this is an object that should be created
295 * by another object. 291 * by another object.
296 */ 292 */
297 if (flags & GT_ENVIRONMENT && op->type != SPELL) 293 if (flags & GT_ENVIRONMENT && op->type != SPELL)
298 { 294 {
299 op->x = creator->x;
300 op->y = creator->y;
301 SET_FLAG (op, FLAG_OBJ_ORIGINAL); 295 SET_FLAG (op, FLAG_OBJ_ORIGINAL);
302 insert_ob_in_map (op, creator->map, op, INS_NO_MERGE | INS_NO_WALK_ON); 296 op->insert_at (creator, creator, INS_NO_MERGE | INS_NO_WALK_ON);
303 } 297 }
304 else 298 else
305 { 299 {
306 op = insert_ob_in_ob (op, creator); 300 op = creator->insert (op);
301
307 if ((flags & GT_APPLY) && QUERY_FLAG (creator, FLAG_MONSTER)) 302 if ((flags & GT_APPLY) && QUERY_FLAG (creator, FLAG_MONSTER))
308 monster_check_apply (creator, op); 303 monster_check_apply (creator, op);
304
309 if ((flags & GT_UPDATE_INV) && (tmp = is_player_inv (creator)) != NULL) 305 if ((flags & GT_UPDATE_INV) && (tmp = creator->in_player ()))
310 esrv_send_item (tmp, op); 306 esrv_send_item (tmp, op);
311 } 307 }
312} 308}
313 309
314/* if there are change_xxx commands in the treasure, we include the changes 310/* if there are change_xxx commands in the treasure, we include the changes
338 334
339 if ((int) t->chance >= 100 || (RANDOM () % 100 + 1) < (int) t->chance) 335 if ((int) t->chance >= 100 || (RANDOM () % 100 + 1) < (int) t->chance)
340 { 336 {
341 if (t->name) 337 if (t->name)
342 { 338 {
343 if (strcmp (t->name, "NONE") && difficulty >= t->magic) 339 if (difficulty >= t->magic)
340 {
341 treasurelist *tl = find_treasurelist (t->name);
342 if (tl)
344 create_treasure (find_treasurelist (t->name), op, flag, difficulty, tries); 343 create_treasure (tl, op, flag, difficulty, tries);
344 }
345 } 345 }
346 else 346 else
347 { 347 {
348 if (t->item->clone.invisible != 0 || !(flag & GT_INVISIBLE)) 348 if (t->item && (t->item->clone.invisible != 0 || !(flag & GT_INVISIBLE)))
349 { 349 {
350 tmp = arch_to_object (t->item); 350 tmp = arch_to_object (t->item);
351 if (t->nrof && tmp->nrof <= 1) 351 if (t->nrof && tmp->nrof <= 1)
352 tmp->nrof = RANDOM () % ((int) t->nrof) + 1; 352 tmp->nrof = RANDOM () % ((int) t->nrof) + 1;
353 fix_generated_item (tmp, op, difficulty, t->magic, flag); 353 fix_generated_item (tmp, op, difficulty, t->magic, flag);
393 return; 393 return;
394 } 394 }
395 395
396 if (t->name) 396 if (t->name)
397 { 397 {
398 if (!strcmp (t->name, "NONE"))
399 return;
400
401 if (difficulty >= t->magic) 398 if (difficulty >= t->magic)
399 {
400 treasurelist *tl = find_treasurelist (t->name);
401 if (tl)
402 create_treasure (find_treasurelist (t->name), op, flag, difficulty, tries); 402 create_treasure (tl, op, flag, difficulty, tries);
403 }
403 else if (t->nrof) 404 else if (t->nrof)
404 create_one_treasure (tl, op, flag, difficulty, tries); 405 create_one_treasure (tl, op, flag, difficulty, tries);
405 406
406 return; 407 return;
407 } 408 }
408 409
409 if ((t->item && t->item->clone.invisible != 0) || flag != GT_INVISIBLE) 410 if (t->item && (t->item->clone.invisible != 0 || flag != GT_INVISIBLE))
410 { 411 {
411 object *tmp = arch_to_object (t->item); 412 object *tmp = arch_to_object (t->item);
412 413
413 if (!tmp) 414 if (!tmp)
414 return; 415 return;
428 * list transitions, or so that excessively good treasure will not be 429 * list transitions, or so that excessively good treasure will not be
429 * created on weak maps, because it will exceed the number of allowed tries 430 * created on weak maps, because it will exceed the number of allowed tries
430 * to do that. 431 * to do that.
431 */ 432 */
432void 433void
433create_treasure (treasurelist * t, object *op, int flag, int difficulty, int tries) 434create_treasure (treasurelist *tl, object *op, int flag, int difficulty, int tries)
434{ 435{
435 436
436 if (tries++ > 100) 437 if (tries++ > 100)
437 { 438 {
438 LOG (llevDebug, "createtreasure: tries exceeded 100, returning without making treasure\n"); 439 LOG (llevDebug, "createtreasure: tries exceeded 100, returning without making treasure\n");
439 return; 440 return;
440 } 441 }
441 if (t->total_chance) 442 if (tl->total_chance)
442 create_one_treasure (t, op, flag, difficulty, tries); 443 create_one_treasure (tl, op, flag, difficulty, tries);
443 else 444 else
444 create_all_treasures (t->items, op, flag, difficulty, tries); 445 create_all_treasures (tl->items, op, flag, difficulty, tries);
445} 446}
446 447
447/* This is similar to the old generate treasure function. However, 448/* This is similar to the old generate treasure function. However,
448 * it instead takes a treasurelist. It is really just a wrapper around 449 * it instead takes a treasurelist. It is really just a wrapper around
449 * create_treasure. We create a dummy object that the treasure gets 450 * create_treasure. We create a dummy object that the treasure gets
450 * inserted into, and then return that treausre 451 * inserted into, and then return that treausre
451 */ 452 */
452object * 453object *
453generate_treasure (treasurelist * t, int difficulty) 454generate_treasure (treasurelist *tl, int difficulty)
454{ 455{
456 difficulty = clamp (difficulty, 1, settings.max_level);
457
455 object *ob = object::create (), *tmp; 458 object *ob = object::create (), *tmp;
456 459
457 create_treasure (t, ob, 0, difficulty, 0); 460 create_treasure (tl, ob, 0, difficulty, 0);
458 461
459 /* Don't want to free the object we are about to return */ 462 /* Don't want to free the object we are about to return */
460 tmp = ob->inv; 463 tmp = ob->inv;
461 if (tmp != NULL) 464 if (tmp != NULL)
462 tmp->remove (); 465 tmp->remove ();
1168 */ 1171 */
1169 1172
1170static artifactlist * 1173static artifactlist *
1171get_empty_artifactlist (void) 1174get_empty_artifactlist (void)
1172{ 1175{
1173 artifactlist *tl = (artifactlist *) malloc (sizeof (artifactlist)); 1176 artifactlist *al = (artifactlist *) malloc (sizeof (artifactlist));
1174 1177
1175 if (tl == NULL) 1178 if (al == NULL)
1176 fatal (OUT_OF_MEMORY); 1179 fatal (OUT_OF_MEMORY);
1177 tl->next = NULL; 1180 al->next = NULL;
1178 tl->items = NULL; 1181 al->items = NULL;
1179 tl->total_chance = 0; 1182 al->total_chance = 0;
1180 return tl; 1183 return al;
1181} 1184}
1182 1185
1183/* 1186/*
1184 * Allocate and return the pointer to an empty artifact structure. 1187 * Allocate and return the pointer to an empty artifact structure.
1185 */ 1188 */
1186 1189
1187static artifact * 1190static artifact *
1188get_empty_artifact (void) 1191get_empty_artifact (void)
1189{ 1192{
1190 artifact *t = (artifact *) malloc (sizeof (artifact)); 1193 artifact *a = (artifact *) malloc (sizeof (artifact));
1191 1194
1192 if (t == NULL) 1195 if (a == NULL)
1193 fatal (OUT_OF_MEMORY); 1196 fatal (OUT_OF_MEMORY);
1194 t->item = NULL; 1197 a->item = NULL;
1195 t->next = NULL; 1198 a->next = NULL;
1196 t->chance = 0; 1199 a->chance = 0;
1197 t->difficulty = 0; 1200 a->difficulty = 0;
1198 t->allowed = NULL; 1201 a->allowed = NULL;
1199 return t; 1202 return a;
1200} 1203}
1201 1204
1202/* 1205/*
1203 * Searches the artifact lists and returns one that has the same type 1206 * Searches the artifact lists and returns one that has the same type
1204 * of objects on it. 1207 * of objects on it.
1254 treasurelist *tl; 1257 treasurelist *tl;
1255 int i; 1258 int i;
1256 1259
1257 if (depth > 100) 1260 if (depth > 100)
1258 return; 1261 return;
1259 while (t != NULL) 1262 while (t)
1260 { 1263 {
1261 if (t->name != NULL) 1264 if (t->name)
1262 { 1265 {
1263 for (i = 0; i < depth; i++) 1266 for (i = 0; i < depth; i++)
1264 fprintf (logfile, " "); 1267 fprintf (logfile, " ");
1265 fprintf (logfile, "{ (list: %s)\n", &t->name); 1268 fprintf (logfile, "{ (list: %s)\n", &t->name);
1266 tl = find_treasurelist (t->name); 1269 tl = find_treasurelist (t->name);
1270 if (tl)
1267 dump_monster_treasure_rec (name, tl->items, depth + 2); 1271 dump_monster_treasure_rec (name, tl->items, depth + 2);
1268 for (i = 0; i < depth; i++) 1272 for (i = 0; i < depth; i++)
1269 fprintf (logfile, " "); 1273 fprintf (logfile, " ");
1270 fprintf (logfile, "} (end of list: %s)\n", &t->name); 1274 fprintf (logfile, "} (end of list: %s)\n", &t->name);
1271 } 1275 }
1272 else 1276 else
1273 { 1277 {
1274 for (i = 0; i < depth; i++) 1278 for (i = 0; i < depth; i++)
1275 fprintf (logfile, " "); 1279 fprintf (logfile, " ");
1276 if (t->item->clone.type == FLESH) 1280 if (t->item && t->item->clone.type == FLESH)
1277 fprintf (logfile, "%s's %s\n", name, &t->item->clone.name); 1281 fprintf (logfile, "%s's %s\n", name, &t->item->clone.name);
1278 else 1282 else
1279 fprintf (logfile, "%s\n", &t->item->clone.name); 1283 fprintf (logfile, "%s\n", &t->item->clone.name);
1280 } 1284 }
1285
1281 if (t->next_yes != NULL) 1286 if (t->next_yes)
1282 { 1287 {
1283 for (i = 0; i < depth; i++) 1288 for (i = 0; i < depth; i++)
1284 fprintf (logfile, " "); 1289 fprintf (logfile, " ");
1285 fprintf (logfile, " (if yes)\n"); 1290 fprintf (logfile, " (if yes)\n");
1286 dump_monster_treasure_rec (name, t->next_yes, depth + 1); 1291 dump_monster_treasure_rec (name, t->next_yes, depth + 1);
1287 } 1292 }
1293
1288 if (t->next_no != NULL) 1294 if (t->next_no)
1289 { 1295 {
1290 for (i = 0; i < depth; i++) 1296 for (i = 0; i < depth; i++)
1291 fprintf (logfile, " "); 1297 fprintf (logfile, " ");
1292 fprintf (logfile, " (if no)\n"); 1298 fprintf (logfile, " (if no)\n");
1293 dump_monster_treasure_rec (name, t->next_no, depth + 1); 1299 dump_monster_treasure_rec (name, t->next_no, depth + 1);
1294 } 1300 }
1301
1295 t = t->next; 1302 t = t->next;
1296 } 1303 }
1297} 1304}
1298 1305
1299/* 1306/*
1488 CLEAR_FLAG (op, FLAG_ANIMATE); 1495 CLEAR_FLAG (op, FLAG_ANIMATE);
1489 /* so artifacts will join */ 1496 /* so artifacts will join */
1490 if (!QUERY_FLAG (op, FLAG_ALIVE)) 1497 if (!QUERY_FLAG (op, FLAG_ALIVE))
1491 op->speed = 0.0; 1498 op->speed = 0.0;
1492 1499
1493 update_ob_speed (op); 1500 op->set_speed (op->speed);
1494 } 1501 }
1495 1502
1496 if (change->nrof) 1503 if (change->nrof)
1497 op->nrof = RANDOM () % ((int) change->nrof) + 1; 1504 op->nrof = RANDOM () % ((int) change->nrof) + 1;
1498 1505
1799/* special_potion() - so that old potion code is still done right. */ 1806/* special_potion() - so that old potion code is still done right. */
1800 1807
1801int 1808int
1802special_potion (object *op) 1809special_potion (object *op)
1803{ 1810{
1804
1805 int i;
1806
1807 if (op->attacktype) 1811 if (op->attacktype)
1808 return 1; 1812 return 1;
1809 1813
1810 if (op->stats.Str || op->stats.Dex || op->stats.Con || op->stats.Pow || op->stats.Wis || op->stats.Int || op->stats.Cha) 1814 if (op->stats.Str || op->stats.Dex || op->stats.Con || op->stats.Pow || op->stats.Wis || op->stats.Int || op->stats.Cha)
1811 return 1; 1815 return 1;
1812 1816
1813 for (i = 0; i < NROFATTACKS; i++) 1817 for (int i = 0; i < NROFATTACKS; i++)
1814 if (op->resist[i]) 1818 if (op->resist[i])
1815 return 1; 1819 return 1;
1816 1820
1817 return 0; 1821 return 0;
1818} 1822}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines