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

Comparing deliantra/server/server/time.C (file contents):
Revision 1.126 by root, Sat Nov 17 23:40:05 2018 UTC vs.
Revision 1.127 by root, Sun Nov 18 15:19:48 2018 UTC

238static void 238static void
239move_gate (object *op) 239move_gate (object *op)
240{ /* 1 = going down, 0 = going up */ 240{ /* 1 = going down, 0 = going up */
241 object *tmp; 241 object *tmp;
242 242
243 if (op->stats.wc < 0 || (int) op->stats.wc >= NUM_ANIMATIONS (op)) 243 if (uint32_t (op->stats.wc) >= op->anim_frames ())
244 { 244 {
245 LOG (llevError, "%s: gate error: animation was %d, max=%d\n", op->debug_desc (), op->stats.wc, NUM_ANIMATIONS (op)); 245 LOG (llevError, "%s: gate error: animation was %d, max=%d\n", op->debug_desc (), op->stats.wc, op->anim_frames ());
246 op->stats.wc = 0; 246 op->stats.wc = 0;
247 } 247 }
248 248
249 /* We're going down */
250 if (op->value) 249 if (op->value)
251 { 250 {
251 /* We're going down */
252 if (--op->stats.wc <= 0) 252 if (--op->stats.wc <= 0)
253 { /* Reached bottom, let's stop */ 253 { /* Reached bottom, let's stop */
254 op->stats.wc = 0; 254 op->stats.wc = 0;
255 if (op->arch->has_active_speed ()) 255 if (op->arch->has_active_speed ())
256 op->value = 0; 256 op->value = 0;
257 else 257 else
258 op->set_speed (0); 258 op->set_speed (0);
259 } 259 }
260 260
261 if ((int) op->stats.wc < (NUM_ANIMATIONS (op) / 2 + 1)) 261 if (op->stats.wc < op->anim_frames () / 2 + 1)
262 { 262 {
263 op->move_block = 0; 263 op->move_block = 0;
264 op->clr_flag (FLAG_BLOCKSVIEW); 264 op->clr_flag (FLAG_BLOCKSVIEW);
265 update_all_los (op->map, op->x, op->y); 265 update_all_los (op->map, op->x, op->y);
266 } 266 }
267
268 SET_ANIMATION (op, op->stats.wc);
269 update_object (op, UP_OBJ_CHANGE);
270 return;
271 }
272
273 /* We're going up */
274
275 /* First, lets see if we are already at the top */
276 if ((unsigned char) op->stats.wc == (NUM_ANIMATIONS (op) - 1))
277 {
278 /* Check to make sure that only non pickable and non rollable
279 * objects are above the gate. If so, we finish closing the gate,
280 * otherwise, we fall through to the code below which should lower
281 * the gate slightly.
282 */
283
284 for (tmp = op->above; tmp; tmp = tmp->above)
285 if (!tmp->flag [FLAG_NO_PICK] || tmp->flag [FLAG_CAN_ROLL] || tmp->flag [FLAG_ALIVE])
286 break;
287
288 if (!tmp)
289 {
290 if (op->arch->has_active_speed ())
291 op->value = 1;
292 else
293 op->set_speed (0);
294
295 return;
296 }
297 }
298
299 if (op->stats.food)
300 { /* The gate is going temporarily down */
301 if (--op->stats.wc <= 0)
302 { /* Gone all the way down? */
303 op->stats.food = 0; /* Then let's try again */
304 op->stats.wc = 0;
305 }
306 } 267 }
307 else 268 else
308 { /* The gate is still going up */ 269 {
309 op->stats.wc++; 270 /* We're going up */
310 271
311 if (op->stats.wc >= NUM_ANIMATIONS (op)) 272 /* First, lets see if we are already at the top */
312 op->stats.wc = NUM_ANIMATIONS (op) - 1; 273 if (op->stats.wc == op->anim_frames () - 1)
313
314 /* If there is something on top of the gate, we try to roll it off.
315 * If a player/monster, we don't roll, we just hit them with damage
316 */ 274 {
317 if (op->stats.wc >= NUM_ANIMATIONS (op) / 2) 275 /* Check to make sure that only non pickable and non rollable
318 { 276 * objects are above the gate. If so, we finish closing the gate,
319 /* Halfway or further, check blocks */ 277 * otherwise, we fall through to the code below which should lower
320 /* First, get the top object on the square. */ 278 * the gate slightly.
321 for (tmp = op->above; tmp && tmp->above; tmp = tmp->above)
322 ; 279 */
323 280
324 if (tmp)
325 {
326 if (tmp->flag [FLAG_ALIVE])
327 {
328 hit_player (tmp, random_roll (0, op->stats.dam, tmp, PREFER_LOW), op, AT_PHYSICAL, 1);
329 op->play_sound (sound_find ("blocked_gate"));
330
331 if (tmp->type == PLAYER)
332 new_draw_info_format (NDI_UNIQUE, 0, tmp, "You are crushed by the %s!", &op->name);
333 }
334 /* If the object is not alive, and the object either can
335 * be picked up or the object rolls, move the object
336 * off the gate.
337 */
338 else if (!tmp->flag [FLAG_ALIVE] && (!tmp->flag [FLAG_NO_PICK] || tmp->flag [FLAG_CAN_ROLL]))
339 {
340 /* If it has speed, it should move itself, otherwise: */
341 int i = find_free_spot (tmp, op->map, op->x, op->y, 1, SIZEOFFREE1 + 1);
342
343 /* If there is a free spot, move the object someplace */
344 if (i > 0)
345 {
346 mapxy pos (tmp);
347 pos.move (i);
348 if (pos.normalise ())
349 tmp->move_to (pos);
350 }
351 }
352 }
353
354 /* See if there is still anything blocking the gate */
355 for (tmp = op->above; tmp; tmp = tmp->above) 281 for (tmp = op->above; tmp; tmp = tmp->above)
356 if (!tmp->flag [FLAG_NO_PICK] || tmp->flag [FLAG_CAN_ROLL] || tmp->flag [FLAG_ALIVE]) 282 if (!tmp->flag [FLAG_NO_PICK] || tmp->flag [FLAG_CAN_ROLL] || tmp->flag [FLAG_ALIVE])
357 break; 283 break;
358 284
359 /* IF there is, start putting the gate down */
360 if (tmp) 285 if (!tmp)
286 {
287 if (op->arch->has_active_speed ())
288 op->value = 1;
289 else
290 op->set_speed (0);
291
292 return;
293 }
294 }
295
296 if (op->stats.food)
297 { /* The gate is going temporarily down */
298 if (--op->stats.wc <= 0)
299 { /* Gone all the way down? */
300 op->stats.food = 0; /* Then let's try again */
301 op->stats.wc = 0;
302 }
303 }
304 else
305 { /* The gate is still going up */
306 op->stats.wc++;
307 min_it (op->stats.wc, op->anim_frames () - 1);
308
309 /* If there is something on top of the gate, we try to roll it off.
310 * If a player/monster, we don't roll, we just hit them with damage
311 */
312 if (op->stats.wc >= op->anim_frames () / 2)
313 {
314 /* Halfway or further, check blocks */
315 /* First, get the top object on the square. */
316 for (tmp = op->above; tmp && tmp->above; tmp = tmp->above)
317 ;
318
319 if (tmp)
320 {
321 if (tmp->flag [FLAG_ALIVE])
322 {
323 hit_player (tmp, random_roll (0, op->stats.dam, tmp, PREFER_LOW), op, AT_PHYSICAL, 1);
324 op->play_sound (sound_find ("blocked_gate"));
325
326 if (tmp->type == PLAYER)
327 new_draw_info_format (NDI_UNIQUE, 0, tmp, "You are crushed by the %s!", &op->name);
328 }
329 /* If the object is not alive, and the object either can
330 * be picked up or the object rolls, move the object
331 * off the gate.
332 */
333 else if (!tmp->flag [FLAG_ALIVE] && (!tmp->flag [FLAG_NO_PICK] || tmp->flag [FLAG_CAN_ROLL]))
334 {
335 /* If it has speed, it should move itself, otherwise: */
336 int i = find_free_spot (tmp, op->map, op->x, op->y, 1, SIZEOFFREE1 + 1);
337
338 /* If there is a free spot, move the object someplace */
339 if (i > 0)
340 {
341 mapxy pos (tmp);
342 pos.move (i);
343 if (pos.normalise ())
344 tmp->move_to (pos);
345 }
346 }
347 }
348
349 /* See if there is still anything blocking the gate */
350 for (tmp = op->above; tmp; tmp = tmp->above)
351 if (!tmp->flag [FLAG_NO_PICK] || tmp->flag [FLAG_CAN_ROLL] || tmp->flag [FLAG_ALIVE])
352 break;
353
354 /* IF there is, start putting the gate down */
355 if (tmp)
361 op->stats.food = 1; 356 op->stats.food = 1;
362 else 357 else
363 { 358 {
364 op->move_block = MOVE_ALL; 359 op->move_block = MOVE_ALL;
365 360
366 if (!op->arch->stats.ac) 361 if (!op->arch->stats.ac)
367 op->set_flag (FLAG_BLOCKSVIEW); 362 op->set_flag (FLAG_BLOCKSVIEW);
363
368 update_all_los (op->map, op->x, op->y); 364 update_all_los (op->map, op->x, op->y);
369 } 365 }
370 } /* gate is halfway up */ 366 } /* gate is halfway up */
371
372 SET_ANIMATION (op, op->stats.wc);
373 update_object (op, UP_OBJ_CHANGE);
374 } /* gate is going up */ 367 } /* gate is going up */
368 }
369
370 op->update_anim_frame (op->stats.wc);
375} 371}
376 372
377/* hp : how long door is open/closed 373/* hp : how long door is open/closed
378 * maxhp : initial value for hp 374 * maxhp : initial value for hp
379 * sp : 1 = open, 0 = close 375 * sp : 1 = open, 0 = close
470} 466}
471 467
472void 468void
473animate_trigger (object *op) 469animate_trigger (object *op)
474{ 470{
475 if ((unsigned char) ++op->stats.wc >= NUM_ANIMATIONS (op)) 471 if (uint32_t (++op->stats.wc) >= op->anim_frames ())
476 { 472 {
477 op->stats.wc = 0; 473 op->stats.wc = 0;
478 check_trigger (op, NULL); 474 check_trigger (op, NULL);
479 } 475 }
480 else 476 else
481 { 477 op->update_anim_frame (op->stats.wc);
482 SET_ANIMATION (op, op->stats.wc);
483 update_object (op, UP_OBJ_FACE);
484 }
485} 478}
486 479
487static void 480static void
488move_hole (object *op) 481move_hole (object *op)
489{ /* 1 = opening, 0 = closing */ 482{ /* 1 = opening, 0 = closing */
490 if (op->value) 483 if (op->value)
491 { /* We're opening */ 484 {
485 /* We're opening */
486 op->stats.wc--;
492 if (--op->stats.wc <= 0) 487 if (op->stats.wc <= 0)
493 { /* Opened, let's stop */ 488 { /* Opened, let's stop */
494 op->stats.wc = 0; 489 op->stats.wc = 0;
495 op->set_speed (0); 490 op->set_speed (0);
496 491
497 /* Hard coding this makes sense for holes I suppose */ 492 /* Hard coding this makes sense for holes I suppose */
500 { 495 {
501 next = tmp->above; 496 next = tmp->above;
502 move_apply (op, tmp, tmp); 497 move_apply (op, tmp, tmp);
503 } 498 }
504 } 499 }
505 500 }
506 SET_ANIMATION (op, op->stats.wc); 501 else
507 update_object (op, UP_OBJ_CHANGE);
508 return;
509 } 502 {
510
511 /* We're closing */ 503 /* We're closing */
512 op->move_on = 0; 504 op->move_on = 0;
513 505
514 op->stats.wc++; 506 op->stats.wc++;
515 if (op->stats.wc >= NUM_ANIMATIONS (op)) 507 if (op->stats.wc >= op->anim_frames ())
516 op->stats.wc = NUM_ANIMATIONS (op) - 1; 508 {
517 509 op->stats.wc = op->anim_frames () - 1;
518 SET_ANIMATION (op, op->stats.wc);
519 update_object (op, UP_OBJ_CHANGE);
520 if (op->stats.wc == (NUM_ANIMATIONS (op) - 1))
521 op->set_speed (0); /* closed, let's stop */ 510 op->set_speed (0); /* closed, let's stop */
511 }
512 }
513
514 op->update_anim_frame (op->stats.wc);
522} 515}
523 516
524 517
525/* stop_item() returns a pointer to the stopped object. The stopped object 518/* stop_item() returns a pointer to the stopped object. The stopped object
526 * may or may not have been removed from maps or inventories. It will not 519 * may or may not have been removed from maps or inventories. It will not

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines