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.35 by root, Mon Jan 1 13:31: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 if (!spaces)
206 object *op, *otmp;
207
208 if (m->unique)
209 return; 205 return;
210 206
211 for (x = 0; x < MAP_WIDTH (m); x++) 207 for (mapspace *ms = spaces + size (); ms-- > spaces; )
212 for (y = 0; y < MAP_HEIGHT (m); y++) 208 for (object *above, *op = ms->bot; op; op = above)
213 for (op = get_map_ob (m, x, y); op; op = otmp)
214 { 209 {
210 above = op->above;
211
215 destroy = 0; 212 bool destroy = 0;
216 otmp = op->above; 213
214 // do not decay anything above unique floor tiles (yet :)
217 if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) 215 if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE))
218 break; 216 break;
217
219 if (QUERY_FLAG (op, FLAG_IS_FLOOR) || 218 if (QUERY_FLAG (op, FLAG_IS_FLOOR)
220 QUERY_FLAG (op, FLAG_OBJ_ORIGINAL) || 219 || QUERY_FLAG (op, FLAG_OBJ_ORIGINAL)
221 QUERY_FLAG (op, FLAG_OBJ_SAVE_ON_OVL) || 220 || 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)) 221 || QUERY_FLAG (op, FLAG_UNIQUE)
223 continue; 222 || QUERY_FLAG (op, FLAG_OVERLAY_FLOOR)
224 /* otherwise, we decay and destroy */ 223 || QUERY_FLAG (op, FLAG_UNPAID)
225 if (IS_WEAPON (op)) 224 || op->is_alive ())
225 ; // do not decay
226 else if (op->is_weapon ())
226 { 227 {
227 op->stats.dam--; 228 op->stats.dam--;
228 if (op->stats.dam < 0) 229 if (op->stats.dam < 0)
229 destroy = 1; 230 destroy = 1;
230 } 231 }
231 else if (IS_ARMOR (op)) 232 else if (op->is_armor ())
232 { 233 {
233 op->stats.ac--; 234 op->stats.ac--;
234 if (op->stats.ac < 0) 235 if (op->stats.ac < 0)
235 destroy = 1; 236 destroy = 1;
236 } 237 }
237 else if (op->type == FOOD) 238 else if (op->type == FOOD)
238 { 239 {
239 op->stats.food -= rndm (5, 20); 240 op->stats.food -= rndm (5, 20);
240 if (op->stats.food < 0) 241 if (op->stats.food < 0)
241 destroy = 1; 242 destroy = 1;
242 } 243 }
243 else 244 else
244 { 245 {
245 if (op->material & M_PAPER || op->material & M_LEATHER || 246 int mat = op->material;
246 op->material & M_WOOD || op->material & M_ORGANIC || op->material & M_CLOTH || op->material & M_LIQUID) 247
248 if (mat & M_PAPER
249 || mat & M_LEATHER
250 || mat & M_WOOD
251 || mat & M_ORGANIC
252 || mat & M_CLOTH
253 || mat & M_LIQUID
254 || (mat & M_IRON && rndm (1, 5) == 1)
255 || (mat & M_GLASS && rndm (1, 2) == 1)
256 || ((mat & M_STONE || mat & M_ADAMANT) && rndm (1, 10) == 1)
257 || ((mat & M_SOFT_METAL || mat & M_BONE) && rndm (1, 3) == 1)
258 || (mat & M_ICE && temp > 32))
247 destroy = 1; 259 destroy = 1;
248 if (op->material & M_IRON && rndm (1, 5) == 1)
249 destroy = 1;
250 if (op->material & M_GLASS && rndm (1, 2) == 1)
251 destroy = 1;
252 if ((op->material & M_STONE || op->material & 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 destroy = 1;
256 if (op->material & M_ICE && MAP_TEMP (m) > 32)
257 destroy = 1;
258 } 260 }
261
259 /* adjust overall chance below */ 262 /* adjust overall chance below */
260 if (destroy && rndm (0, 1)) 263 if (destroy && rndm (0, 1))
261 op->destroy (); 264 op->destroy ();
262 } 265 }
263} 266}
264 267
265/* convert materialname to materialtype_t */ 268/* convert materialname to materialtype_t */
266 269
267materialtype_t * 270materialtype_t *
295 return; 298 return;
296 299
297 if (change->materialname != NULL && strcmp (op->materialname, change->materialname)) 300 if (change->materialname != NULL && strcmp (op->materialname, change->materialname))
298 return; 301 return;
299 302
300 if (!IS_ARMOR (op)) 303 if (!op->is_armor ())
301 return; 304 return;
302 305
303 mt = name_to_material (op->materialname); 306 mt = name_to_material (op->materialname);
304 if (!mt) 307 if (!mt)
305 { 308 {
351 { 354 {
352 if (op->material & mt->material && rndm (1, 100) <= mt->chance && 355 if (op->material & mt->material && rndm (1, 100) <= mt->chance &&
353 difficulty >= mt->difficulty && (op->magic >= mt->magic || mt->magic == 0)) 356 difficulty >= mt->difficulty && (op->magic >= mt->magic || mt->magic == 0))
354 { 357 {
355 lmt = mt; 358 lmt = mt;
356 if (!(IS_WEAPON (op) || IS_ARMOR (op))) 359 if (!(op->is_weapon () || op->is_armor ()))
357 break; 360 break;
358 } 361 }
359 } 362 }
360#endif 363#endif
361 } 364 }
369#ifndef NEW_MATERIAL_CODE 372#ifndef NEW_MATERIAL_CODE
370 op->materialname = lmt->name; 373 op->materialname = lmt->name;
371 return; 374 return;
372#else 375#else
373 376
374 if (op->stats.dam && IS_WEAPON (op)) 377 if (op->stats.dam && op->is_weapon ())
375 { 378 {
376 op->stats.dam += lmt->damage; 379 op->stats.dam += lmt->damage;
377 if (op->stats.dam < 1) 380 if (op->stats.dam < 1)
378 op->stats.dam = 1; 381 op->stats.dam = 1;
379 } 382 }
380 if (op->stats.sp && op->type == BOW) 383 if (op->stats.sp && op->type == BOW)
381 op->stats.sp += lmt->sp; 384 op->stats.sp += lmt->sp;
382 if (op->stats.wc && IS_WEAPON (op)) 385 if (op->stats.wc && op->is_weapon ())
383 op->stats.wc += lmt->wc; 386 op->stats.wc += lmt->wc;
384 if (IS_ARMOR (op)) 387 if (op->is_armor ())
385 { 388 {
386 if (op->stats.ac) 389 if (op->stats.ac)
387 op->stats.ac += lmt->ac; 390 op->stats.ac += lmt->ac;
388 for (j = 0; j < NROFATTACKS; j++) 391 for (j = 0; j < NROFATTACKS; j++)
389 if (op->resist[j] != 0) 392 if (op->resist[j] != 0)
395 op->resist[j] = -100; 398 op->resist[j] = -100;
396 } 399 }
397 } 400 }
398 op->materialname = add_string (lmt->name); 401 op->materialname = add_string (lmt->name);
399 /* dont make it unstackable if it doesn't need to be */ 402 /* dont make it unstackable if it doesn't need to be */
400 if (IS_WEAPON (op) || IS_ARMOR (op)) 403 if (op->is_weapon () || op->is_armor ())
401 { 404 {
402 op->weight = (op->weight * lmt->weight) / 100; 405 op->weight = (op->weight * lmt->weight) / 100;
403 op->value = (op->value * lmt->value) / 100; 406 op->value = (op->value * lmt->value) / 100;
404 } 407 }
405#endif 408#endif
540 return; 543 return;
541} 544}
542 545
543///////////////////////////////////////////////////////////////////////////// 546/////////////////////////////////////////////////////////////////////////////
544 547
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) 548void *salloc_ (int n) throw (std::bad_alloc)
563{ 549{
564 void *ptr = g_slice_alloc (n); 550 void *ptr = g_slice_alloc (n);
565 551
566 if (!ptr) 552 if (!ptr)
611 597
612 gettimeofday (&tv, 0); 598 gettimeofday (&tv, 0);
613 return tstamp (tv.tv_sec) + tstamp (tv.tv_usec) * tstamp (1e-6); 599 return tstamp (tv.tv_sec) + tstamp (tv.tv_usec) * tstamp (1e-6);
614} 600}
615 601
602int
603similar_direction (int a, int b)
604{
605 if (!a || !b)
606 return 0;
607
608 int diff = (b - a) & 7;
609 return diff <= 1 || diff >= 7;
610}
611

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines