Initialize a generic object (robot, powerup, building, etc.) Returns 1 if ok, 0 if error
| 723 | // Initialize a generic object (robot, powerup, building, etc.) |
| 724 | // Returns 1 if ok, 0 if error |
| 725 | int ObjInitGeneric(object *objp, bool reinit) { |
| 726 | object_info *obj_info; |
| 727 | int ret = 1; |
| 728 | float r_val = (float)ps_rand() / (float)D3_RAND_MAX; |
| 729 | if ((objp->id < 0) || (objp->id >= MAX_OBJECT_IDS)) { |
| 730 | Int3(); |
| 731 | return 0; |
| 732 | } |
| 733 | obj_info = &Object_info[objp->id]; |
| 734 | // Deal with deleted type |
| 735 | if (obj_info->type == OBJ_NONE) { |
| 736 | int i; |
| 737 | for (i = 0, obj_info = Object_info; i < MAX_OBJECT_IDS; i++, obj_info) { // find other object of same type |
| 738 | if (Object_info[i].type == objp->type) |
| 739 | break; |
| 740 | } |
| 741 | ASSERT(i < MAX_OBJECT_IDS); // There should (in real life) always be at least one of each type |
| 742 | #ifdef EDITOR |
| 743 | if (GetFunctionMode() == EDITOR_MODE) |
| 744 | OutrageMessageBox("Object %d (\"%s\") had ID %d which no longer exists. Changing to %d, \"%s\".", OBJNUM(objp), |
| 745 | objp->name ? objp->name : "<no name>", objp->id, i, obj_info->name); |
| 746 | #endif |
| 747 | } |
| 748 | if (obj_info->type != objp->type) { |
| 749 | #ifdef EDITOR |
| 750 | if (GetFunctionMode() == EDITOR_MODE) |
| 751 | OutrageMessageBox("Object %d (\"%s\"), type name \"%s\", changed from type %s to %s", OBJNUM(objp), |
| 752 | objp->name ? objp->name : "<no name>", obj_info->name, Object_type_names[objp->type], |
| 753 | Object_type_names[obj_info->type]); |
| 754 | #endif |
| 755 | objp->type = obj_info->type; |
| 756 | } |
| 757 | // Set size & shields |
| 758 | objp->shields = obj_info->hit_points; |
| 759 | // Set impact stuff for non-weapons |
| 760 | objp->impact_size = obj_info->impact_size; |
| 761 | objp->impact_time = obj_info->impact_time; |
| 762 | objp->impact_player_damage = obj_info->damage; |
| 763 | objp->impact_generic_damage = obj_info->damage; |
| 764 | objp->impact_force = obj_info->damage * 50.0; |
| 765 | // Set flags |
| 766 | if (obj_info->flags & OIF_DESTROYABLE) |
| 767 | objp->flags |= OF_DESTROYABLE; |
| 768 | if (obj_info->flags & OIF_AI_SCRIPTED_DEATH) |
| 769 | objp->flags |= OF_AI_DO_DEATH; |
| 770 | if (obj_info->flags & OIF_DO_CEILING_CHECK) |
| 771 | objp->flags |= OF_FORCE_CEILING_CHECK; |
| 772 | // Set up movement info |
| 773 | if (obj_info->flags & OIF_USES_PHYSICS) { |
| 774 | objp->movement_type = MT_PHYSICS; |
| 775 | // Setup some physics things |
| 776 | objp->mtype.phys_info = obj_info->phys_info; // Set the initial velocity |
| 777 | // Warn about initial velocity & rotvel |
| 778 | if (obj_info->phys_info.velocity.z > 0.0) |
| 779 | Int3(); // Warning: This object has an initial velocity. This is not supported. |
| 780 | // If your object does not need an initial velocity, set it to zero on |
| 781 | // the page. If you do need an initial velocity, someone will have to |
| 782 | // add code to deal with it, perhaps here or perhaps at level start. |
no test coverage detected