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

Comparing deliantra/server/common/utils.C (file contents):
Revision 1.25 by root, Sun Dec 17 23:10:34 2006 UTC vs.
Revision 1.34 by root, Mon Jan 1 12:28:46 2007 UTC

195 return (min); 195 return (min);
196 196
197 return (RANDOM () % diff + min); 197 return (RANDOM () % diff + min);
198} 198}
199 199
200/* decay and destroy persihable items in a map */ 200/* decay and destroy perishable items in a map */
201
202void 201void
203decay_objects (maptile *m) 202maptile::decay_objects ()
204{ 203{
205 int x, y, destroy; 204 for (int x = 0; x < width; x++)
206 object *op, *otmp; 205 for (int y = 0; y < height; y++)
207 206 for (object *above = 0, *op = at (x, y).bot; op; op = above)
208 if (m->unique)
209 return;
210
211 for (x = 0; x < MAP_WIDTH (m); x++)
212 for (y = 0; y < MAP_HEIGHT (m); y++)
213 for (op = get_map_ob (m, x, y); op; op = otmp)
214 { 207 {
215 destroy = 0; 208 bool destroy = 0;
209
216 otmp = op->above; 210 above = op->above;
211
212 // do not decay anything above unique floor tiles (yet :)
217 if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) 213 if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE))
218 break; 214 break;
215
219 if (QUERY_FLAG (op, FLAG_IS_FLOOR) || 216 if (QUERY_FLAG (op, FLAG_IS_FLOOR)
220 QUERY_FLAG (op, FLAG_OBJ_ORIGINAL) || 217 || QUERY_FLAG (op, FLAG_OBJ_ORIGINAL)
221 QUERY_FLAG (op, FLAG_OBJ_SAVE_ON_OVL) || 218 || QUERY_FLAG (op, FLAG_OBJ_SAVE_ON_OVL)
222 QUERY_FLAG (op, FLAG_UNIQUE) || QUERY_FLAG (op, FLAG_OVERLAY_FLOOR) || QUERY_FLAG (op, FLAG_UNPAID) || IS_LIVE (op)) 219 || QUERY_FLAG (op, FLAG_UNIQUE)
223 continue; 220 || QUERY_FLAG (op, FLAG_OVERLAY_FLOOR)
224 /* otherwise, we decay and destroy */ 221 || QUERY_FLAG (op, FLAG_UNPAID)
225 if (IS_WEAPON (op)) 222 || op->is_alive ())
223 ; // do not decay
224 else if (op->is_weapon ())
226 { 225 {
227 op->stats.dam--; 226 op->stats.dam--;
228 if (op->stats.dam < 0) 227 if (op->stats.dam < 0)
229 destroy = 1; 228 destroy = 1;
230 } 229 }
231 else if (IS_ARMOR (op)) 230 else if (op->is_armor ())
232 { 231 {
233 op->stats.ac--; 232 op->stats.ac--;
234 if (op->stats.ac < 0) 233 if (op->stats.ac < 0)
235 destroy = 1; 234 destroy = 1;
236 } 235 }
240 if (op->stats.food < 0) 239 if (op->stats.food < 0)
241 destroy = 1; 240 destroy = 1;
242 } 241 }
243 else 242 else
244 { 243 {
245 if (op->material & M_PAPER || op->material & M_LEATHER || 244 int mat = op->material;
246 op->material & M_WOOD || op->material & M_ORGANIC || op->material & M_CLOTH || op->material & M_LIQUID) 245
247 destroy = 1; 246 if (mat & M_PAPER
247 || mat & M_LEATHER
248 || mat & M_WOOD
249 || mat & M_ORGANIC
250 || mat & M_CLOTH
251 || mat & M_LIQUID
248 if (op->material & M_IRON && rndm (1, 5) == 1) 252 || (mat & M_IRON && rndm (1, 5) == 1)
249 destroy = 1;
250 if (op->material & M_GLASS && rndm (1, 2) == 1) 253 || (mat & M_GLASS && rndm (1, 2) == 1)
251 destroy = 1;
252 if ((op->material & M_STONE || op->material & M_ADAMANT) && rndm (1, 10) == 1) 254 || ((mat & M_STONE || mat & M_ADAMANT) && rndm (1, 10) == 1)
253 destroy = 1;
254 if ((op->material & M_SOFT_METAL || op->material & M_BONE) && rndm (1, 3) == 1) 255 || ((mat & M_SOFT_METAL || mat & M_BONE) && rndm (1, 3) == 1)
255 destroy = 1; 256 || (mat & M_ICE && temp > 32))
256 if (op->material & M_ICE && MAP_TEMP (m) > 32)
257 destroy = 1; 257 destroy = 1;
258 } 258 }
259
259 /* adjust overall chance below */ 260 /* adjust overall chance below */
260 if (destroy && rndm (0, 1)) 261 if (destroy && rndm (0, 1))
261 op->destroy (); 262 op->destroy ();
262 } 263 }
263} 264}
295 return; 296 return;
296 297
297 if (change->materialname != NULL && strcmp (op->materialname, change->materialname)) 298 if (change->materialname != NULL && strcmp (op->materialname, change->materialname))
298 return; 299 return;
299 300
300 if (!IS_ARMOR (op)) 301 if (!op->is_armor ())
301 return; 302 return;
302 303
303 mt = name_to_material (op->materialname); 304 mt = name_to_material (op->materialname);
304 if (!mt) 305 if (!mt)
305 { 306 {
351 { 352 {
352 if (op->material & mt->material && rndm (1, 100) <= mt->chance && 353 if (op->material & mt->material && rndm (1, 100) <= mt->chance &&
353 difficulty >= mt->difficulty && (op->magic >= mt->magic || mt->magic == 0)) 354 difficulty >= mt->difficulty && (op->magic >= mt->magic || mt->magic == 0))
354 { 355 {
355 lmt = mt; 356 lmt = mt;
356 if (!(IS_WEAPON (op) || IS_ARMOR (op))) 357 if (!(op->is_weapon () || op->is_armor ()))
357 break; 358 break;
358 } 359 }
359 } 360 }
360#endif 361#endif
361 } 362 }
369#ifndef NEW_MATERIAL_CODE 370#ifndef NEW_MATERIAL_CODE
370 op->materialname = lmt->name; 371 op->materialname = lmt->name;
371 return; 372 return;
372#else 373#else
373 374
374 if (op->stats.dam && IS_WEAPON (op)) 375 if (op->stats.dam && op->is_weapon ())
375 { 376 {
376 op->stats.dam += lmt->damage; 377 op->stats.dam += lmt->damage;
377 if (op->stats.dam < 1) 378 if (op->stats.dam < 1)
378 op->stats.dam = 1; 379 op->stats.dam = 1;
379 } 380 }
380 if (op->stats.sp && op->type == BOW) 381 if (op->stats.sp && op->type == BOW)
381 op->stats.sp += lmt->sp; 382 op->stats.sp += lmt->sp;
382 if (op->stats.wc && IS_WEAPON (op)) 383 if (op->stats.wc && op->is_weapon ())
383 op->stats.wc += lmt->wc; 384 op->stats.wc += lmt->wc;
384 if (IS_ARMOR (op)) 385 if (op->is_armor ())
385 { 386 {
386 if (op->stats.ac) 387 if (op->stats.ac)
387 op->stats.ac += lmt->ac; 388 op->stats.ac += lmt->ac;
388 for (j = 0; j < NROFATTACKS; j++) 389 for (j = 0; j < NROFATTACKS; j++)
389 if (op->resist[j] != 0) 390 if (op->resist[j] != 0)
395 op->resist[j] = -100; 396 op->resist[j] = -100;
396 } 397 }
397 } 398 }
398 op->materialname = add_string (lmt->name); 399 op->materialname = add_string (lmt->name);
399 /* dont make it unstackable if it doesn't need to be */ 400 /* dont make it unstackable if it doesn't need to be */
400 if (IS_WEAPON (op) || IS_ARMOR (op)) 401 if (op->is_weapon () || op->is_armor ())
401 { 402 {
402 op->weight = (op->weight * lmt->weight) / 100; 403 op->weight = (op->weight * lmt->weight) / 100;
403 op->value = (op->value * lmt->value) / 100; 404 op->value = (op->value * lmt->value) / 100;
404 } 405 }
405#endif 406#endif
540 return; 541 return;
541} 542}
542 543
543///////////////////////////////////////////////////////////////////////////// 544/////////////////////////////////////////////////////////////////////////////
544 545
545#if 0
546refcounted *refcounted::rc_first;
547
548refcounted::refcounted ()
549{
550 refcnt = 0;
551 rc_next = rc_first;
552 rc_first = this;
553}
554
555refcounted::~refcounted ()
556{
557 assert (!rc_next);
558 assert (!refcnt);
559}
560#endif
561
562void *salloc_ (int n) throw (std::bad_alloc) 546void *salloc_ (int n) throw (std::bad_alloc)
563{ 547{
564 void *ptr = g_slice_alloc (n); 548 void *ptr = g_slice_alloc (n);
565 549
566 if (!ptr) 550 if (!ptr)
611 595
612 gettimeofday (&tv, 0); 596 gettimeofday (&tv, 0);
613 return tstamp (tv.tv_sec) + tstamp (tv.tv_usec) * tstamp (1e-6); 597 return tstamp (tv.tv_sec) + tstamp (tv.tv_usec) * tstamp (1e-6);
614} 598}
615 599
600int
601similar_direction (int a, int b)
602{
603 if (!a || !b)
604 return 0;
605
606 int diff = (b - a) & 7;
607 return diff <= 1 || diff >= 7;
608}
609

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines