/** * Adds momentum for building a buildable. * * Will save the reward with the buildable. */ float G_AddMomentumForBuilding(gentity_t* buildable) { float value, reward; team_t team; gentity_t* builder; if (!buildable || buildable->s.eType != ET_BUILDABLE) { return 0.0f; } value = BG_Buildable(buildable->s.modelindex)->buildPoints; team = BG_Buildable(buildable->s.modelindex)->team; if (buildable->builtBy->slot != -1) { builder = &g_entities[buildable->builtBy->slot]; } else { builder = nullptr; } reward = AddMomentum(CONF_BUILDING, team, value, builder, false); // Save reward with buildable so it can be reverted buildable->momentumEarned = reward; return reward; }
/** * Removes momentum for deconstructing a buildable. */ float G_RemoveMomentumForDecon( gentity_t *buildable, gentity_t *deconner ) { float value; team_t team; // sanity check buildable if ( !buildable || buildable->s.eType != entityType_t::ET_BUILDABLE ) { return 0.0f; } team = BG_Buildable( buildable->s.modelindex )->team; if ( buildable->momentumEarned ) { value = buildable->momentumEarned; } else { // assume the buildable has just been placed value = G_PredictMomentumForBuilding( buildable ); } // Remove only partial momentum as the lost health fraction awards momentum to the enemy. value *= buildable->entity->Get<HealthComponent>()->HealthFraction(); return AddMomentum( CONF_DECONSTRUCTING, team, -value, deconner, false ); }
/** * Adds momentum for destroying a buildable. * * G_AddMomentumEnd has to be called after all G_AddMomentum*Step steps are *done. */ float G_AddMomentumForDestroyingStep(gentity_t* buildable, gentity_t* attacker, float amount) { team_t team; // sanity check buildable if (!buildable || buildable->s.eType != ET_BUILDABLE) { return 0.0f; } // sanity check attacker if (!attacker || !attacker->client) { return 0.0f; } team = (team_t) attacker->client->pers.team; return AddMomentum(CONF_DESTROYING, team, amount, attacker, true); }
/** * Adds momentum for killing a player. * * G_AddMomentumEnd has to be called after all G_AddMomentum*Step steps are *done. */ float G_AddMomentumForKillingStep(gentity_t* victim, gentity_t* attacker, float share) { float value; team_t team; // sanity check victim if (!victim || !victim->client) { return 0.0f; } // sanity check attacker if (!attacker || !attacker->client) { return 0.0f; } value = BG_GetValueOfPlayer(&victim->client->ps) * MOMENTUM_PER_CREDIT * share; team = (team_t) attacker->client->pers.team; return AddMomentum(CONF_KILLING, team, value, attacker, true); }
/** * Removes momentum for deconstructing a buildable. */ float G_RemoveMomentumForDecon(gentity_t* buildable, gentity_t* deconner) { float value; team_t team; // sanity check buildable if (!buildable || buildable->s.eType != ET_BUILDABLE) { return 0.0f; } team = BG_Buildable(buildable->s.modelindex)->team; if (buildable->momentumEarned) { value = buildable->momentumEarned; } else { // assume the buildable has just been placed value = G_PredictMomentumForBuilding(buildable); } value *= buildable->deconHealthFrac; return AddMomentum(CONF_DECONSTRUCTING, team, -value, deconner, false); }
/** * Adds momentum. * * G_AddMomentumEnd has to be called after all G_AddMomentum*Step steps are *done. */ float G_AddMomentumGenericStep(team_t team, float amount) { AddMomentum(CONF_GENERIC, team, amount, nullptr, true); return amount; }