MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / ObjInitPlayer

Function ObjInitPlayer

Descent3/ObjInit.cpp:665–722  ·  view source on GitHub ↗

Initialize a player object Returns 1 if ok, 0 if error

Source from the content-addressed store, hash-verified

663// Initialize a player object
664// Returns 1 if ok, 0 if error
665int ObjInitPlayer(object *objp) {
666 ship *ship;
667 int ret = 1;
668 ASSERT(objp->type == OBJ_PLAYER);
669 objp->shields = INITIAL_SHIELDS;
670 ship = &Ships[Players[objp->id].ship_index];
671 if (!ship->used) { // this ship doesn't exist
672 int new_ship;
673 Int3();
674 ret = 0;
675 new_ship = GetNextShip(0);
676 ASSERT(new_ship != -1);
677 Players[objp->id].ship_index = new_ship;
678 ship = &Ships[Players[objp->id].ship_index];
679 }
680 // Set up render info
681 ObjSetRenderPolyobj(objp, ship->model_handle, ship->dying_model_handle);
682 ASSERT(Poly_models[ship->model_handle].n_attach >= 3);
683 objp->lighting_render_type = LRT_GOURAUD;
684 objp->lm_object.used = 0;
685 // Page in those models
686 PageInPolymodel(ship->model_handle, OBJ_PLAYER, &ship->size);
687 if (ship->dying_model_handle >= 0)
688 PageInPolymodel(ship->dying_model_handle);
689 if (ship->lo_render_handle >= 0)
690 PageInPolymodel(ship->lo_render_handle);
691 if (ship->med_render_handle >= 0)
692 PageInPolymodel(ship->med_render_handle);
693 // Set size
694 objp->size = ship->size;
695 // Set up control info. The player flies, other players do nothing
696 // MUST be after paging in polymodel cause SetObjectControlType does some
697 // stuff with the object's polymodel.
698 if (objp->id == Player_num) {
699 SetObjectControlType(objp, CT_FLYING);
700 objp->movement_type = MT_PHYSICS;
701 objp->mtype.phys_info = ship->phys_info;
702 Player_object = objp;
703 } else {
704 SetObjectControlType(objp, CT_NONE);
705 objp->movement_type = MT_NONE;
706 objp->mtype.phys_info = ship->phys_info;
707 objp->mtype.phys_info.flags = PF_FIXED_VELOCITY;
708 }
709 // Set up physics info
710 // These are always set for a player
711 objp->mtype.phys_info.num_bounces = PHYSICS_UNLIMITED_BOUNCE;
712 if (objp->dynamic_wb == NULL) {
713 objp->dynamic_wb = (dynamic_wb_info *)mem_malloc(sizeof(dynamic_wb_info) * MAX_WBS_PER_OBJ);
714 }
715 WBClearInfo(objp);
716 // Set a few misc things
717 Players[objp->id].team = objp->id % 2;
718 ObjCreateEffectInfo(objp);
719 objp->effect_info->type_flags = EF_VOLUME_LIT;
720
721 return ret;
722}

Callers 1

ObjInitTypeSpecificFunction · 0.85

Calls 6

GetNextShipFunction · 0.85
ObjSetRenderPolyobjFunction · 0.85
PageInPolymodelFunction · 0.85
SetObjectControlTypeFunction · 0.85
ObjCreateEffectInfoFunction · 0.85
WBClearInfoFunction · 0.70

Tested by

no test coverage detected