Attempt to set new object position. May only move part of the way, or maybe not at all. Use FVI to find new object position Return: TRUE if moved, FALSE if can't move
| 572 | // Use FVI to find new object position |
| 573 | // Return: TRUE if moved, FALSE if can't move |
| 574 | bool MoveObject(object *obj, vector *newpos) { |
| 575 | fvi_query fq; |
| 576 | fvi_info hit_info; |
| 577 | int fate; |
| 578 | |
| 579 | // Use radius if this is a physics object |
| 580 | bool use_radius = (obj->movement_type == MT_PHYSICS) ? true : false; |
| 581 | |
| 582 | // Follow vector from start position to desired end position, & move as far as we can |
| 583 | fq.p0 = &obj->pos; |
| 584 | fq.startroom = obj->roomnum; |
| 585 | fq.p1 = newpos; |
| 586 | fq.thisobjnum = OBJNUM(obj); |
| 587 | fq.ignore_obj_list = NULL; |
| 588 | fq.flags = FQ_IGNORE_RENDER_THROUGH_PORTALS; |
| 589 | fq.rad = use_radius ? obj->size : 0.0f; |
| 590 | |
| 591 | if (f_allow_objects_to_be_pushed_through_walls) { |
| 592 | fq.flags |= (FQ_IGNORE_WALLS | FQ_IGNORE_TERRAIN | FQ_IGNORE_EXTERNAL_ROOMS); |
| 593 | } |
| 594 | |
| 595 | fate = fvi_FindIntersection(&fq, &hit_info); |
| 596 | |
| 597 | mprintf(0, "fate = %d\n", fate); |
| 598 | |
| 599 | // Check for object can't move, meaning it's stuck in the wall |
| 600 | if (fate == HIT_WALL) |
| 601 | if (vm_VectorDistance(&obj->pos, &hit_info.hit_pnt) < MOVE_EPSILON) |
| 602 | return 0; // didn't move |
| 603 | |
| 604 | // Set object position on where FVI told us we are |
| 605 | ObjSetPos(obj, &hit_info.hit_pnt, hit_info.hit_room, NULL, false); |
| 606 | |
| 607 | // Say object moved |
| 608 | return 1; |
| 609 | } |
| 610 | |
| 611 | bool RotateObject(int objnum, angle p, angle h, angle b) { |
| 612 | object *obj = &Objects[objnum]; |
no test coverage detected