void CFeature::Initialize(const FeatureLoadParams& params) { id = params.featureID; defID = (params.featureDef)->id; def = params.featureDef; udef = params.unitDef; objectDef = params.featureDef; team = params.teamID; allyteam = params.allyTeamID; heading = params.heading; buildFacing = params.facing; smokeTime = params.smokeTime; mass = def->mass; health = def->health; crushResistance = def->crushResistance; xsize = ((buildFacing & 1) == 0) ? def->xsize : def->zsize; zsize = ((buildFacing & 1) == 1) ? def->xsize : def->zsize; noSelect = !def->selectable; // set position before mid-position Move((params.pos).cClampInMap(), false); // use base-class version, AddFeature() below // will already insert us in the update-queue CWorldObject::SetVelocity(params.speed); if (def->drawType == DRAWTYPE_MODEL) { if ((model = def->LoadModel()) == NULL) { LOG_L(L_ERROR, "[%s] couldn't load model for %s", __FUNCTION__, def->name.c_str()); } else { SetMidAndAimPos(model->relMidPos, model->relMidPos, true); SetRadiusAndHeight(model); } } else if (def->drawType >= DRAWTYPE_TREE) { // LoadFeaturesFromMap() doesn't set a scale for trees SetMidAndAimPos(UpVector * TREE_RADIUS, UpVector * TREE_RADIUS, true); SetRadiusAndHeight(TREE_RADIUS, TREE_RADIUS * 2.0f); } UpdateMidAndAimPos(); CalculateTransform(); // note: gets deleted in ~CSolidObject collisionVolume = new CollisionVolume(def->collisionVolume); if (collisionVolume->DefaultToSphere()) collisionVolume->InitSphere(radius); if (collisionVolume->DefaultToFootPrint()) collisionVolume->InitBox(float3(xsize * SQUARE_SIZE, height, zsize * SQUARE_SIZE)); // feature does not have an assigned ID yet // this MUST be done before the Block() call featureHandler->AddFeature(this); quadField->AddFeature(this); ChangeTeam(team); UpdateCollidableStateBit(CSolidObject::CSTATE_BIT_SOLIDOBJECTS, def->collidable); Block(); // allow Spring.SetFeatureBlocking to be called from gadget:FeatureCreated eventHandler.FeatureCreated(this); if (def->floating) { finalHeight = ground->GetHeightAboveWater(pos.x, pos.z); } else { finalHeight = ground->GetHeightReal(pos.x, pos.z); } UpdatePhysicalStateBit(CSolidObject::PSTATE_BIT_MOVING, ((SetSpeed(params.speed) != 0.0f) || (std::fabs(pos.y - finalHeight) >= 0.01f))); }
void CFeature::Initialize(const FeatureLoadParams& params) { def = params.featureDef; udef = params.unitDef; id = params.featureID; team = params.teamID; allyteam = params.allyTeamID; heading = params.heading; buildFacing = params.facing; smokeTime = params.smokeTime; mass = def->mass; health = def->health; maxHealth = def->health; resources = SResourcePack(def->metal, def->energy); crushResistance = def->crushResistance; xsize = ((buildFacing & 1) == 0) ? def->xsize : def->zsize; zsize = ((buildFacing & 1) == 1) ? def->xsize : def->zsize; noSelect = !def->selectable; // by default, any feature that is a dead unit can move // in all dimensions; all others (trees, rocks, ...) can // only move vertically and also do not allow velocity to // build in XZ // (movementMask exists mostly for trees, which depend on // speed for falling animations but should never actually // *move* in XZ, so their velocityMask *does* include XZ) moveCtrl.SetMovementMask(mix(OnesVector, UpVector, udef == nullptr )); moveCtrl.SetVelocityMask(mix(OnesVector, UpVector, udef == nullptr && def->drawType < DRAWTYPE_TREE)); // set position before mid-position Move((params.pos).cClampInMap(), false); // use base-class version, AddFeature() below // will already insert us in the update-queue CWorldObject::SetVelocity(params.speed); switch (def->drawType) { case DRAWTYPE_NONE: { } break; case DRAWTYPE_MODEL: { if ((model = def->LoadModel()) != NULL) { SetMidAndAimPos(model->relMidPos, model->relMidPos, true); SetRadiusAndHeight(model); // only initialize the LM for modelled features // (this is still never animated but allows for // custom piece display-lists, etc) localModel.SetModel(model); } else { LOG_L(L_ERROR, "[%s] couldn't load model for %s", __FUNCTION__, def->name.c_str()); } } break; default: { // always >= DRAWTYPE_TREE here // LoadFeaturesFromMap() doesn't set a scale for trees SetMidAndAimPos(UpVector * TREE_RADIUS, UpVector * TREE_RADIUS, true); SetRadiusAndHeight(TREE_RADIUS, TREE_RADIUS * 2.0f); drawPos = pos; drawMidPos = midPos; } break; } UpdateMidAndAimPos(); UpdateTransformAndPhysState(); collisionVolume = def->collisionVolume; if (collisionVolume.DefaultToSphere()) collisionVolume.InitSphere(radius); if (collisionVolume.DefaultToFootPrint()) collisionVolume.InitBox(float3(xsize * SQUARE_SIZE, height, zsize * SQUARE_SIZE)); // feature does not have an assigned ID yet // this MUST be done before the Block() call featureHandler->AddFeature(this); quadField->AddFeature(this); ChangeTeam(team); UpdateCollidableStateBit(CSolidObject::CSTATE_BIT_SOLIDOBJECTS, def->collidable); Block(); // allow Spring.SetFeatureBlocking to be called from gadget:FeatureCreated // (callin sees the complete default state, but can change any part of it) eventHandler.FeatureCreated(this); eventHandler.RenderFeatureCreated(this); }