Added more comments in DoUse

This commit is contained in:
smallmodel 2023-10-17 17:41:41 +02:00
parent cd2fea5262
commit 844a50dfd8
No known key found for this signature in database
GPG key ID: 9F2D623CEDF08512

View file

@ -3291,72 +3291,59 @@ void Player::DoUse(Event *ev)
int i; int i;
if (g_gametype->integer != GT_SINGLE_PLAYER && IsSpectator()) { if (g_gametype->integer != GT_SINGLE_PLAYER && IsSpectator()) {
// Prevent using stuff while spectating
return; return;
} }
if (IsDead()) { if (IsDead()) {
// Dead players mustn't use
return; return;
} }
if (m_pVehicle || m_pTurret) { if (m_pVehicle || m_pTurret) {
RemoveFromVehiclesAndTurretsInternal(); RemoveFromVehiclesAndTurretsInternal();
} else if (!(buttons & BUTTON_ATTACKLEFT) && !(buttons & BUTTON_ATTACKRIGHT)) { return;
//
// Allow use if the player isn't holding attack buttons
//
num = getUseableEntities(touch, MAX_GENTITIES, true);
for (i = 0; i < num; i++) {
hit = &g_entities[touch[i]];
if (!hit->inuse) {
continue;
}
Event *event = new Event(EV_Use);
event->AddListener(this);
hit->entity->ProcessEvent(event);
if (m_pVehicle || m_pTurret)
{
if (m_pVehicle)
{
//
// transmit the godmode to the vehicle
//
if (flags & FL_GODMODE) {
m_pVehicle->flags |= FL_GODMODE;
} else {
m_pVehicle->flags &= ~FL_GODMODE;
}
}
return;
}
}
} }
// FIXME: special game feature if ((buttons & BUTTON_ATTACKLEFT) || (buttons & BUTTON_ATTACKRIGHT)) {
#if 0 //
// Added in 2.0
// Only allow use if the player isn't holding attack buttons
//
return;
}
// Now retrieve entities that doesn't require to look at num = getUseableEntities(touch, MAX_GENTITIES, true);
num = getUseableEntities( touch, MAX_GENTITIES, false );
for( i = 0; i < num; i++ ) for (i = 0; i < num; i++) {
{ hit = &g_entities[touch[i]];
hit = &g_entities[ touch[ i ] ];
if( !hit->inuse || hit->entity == NULL || hit->entity == this ) { if (!hit->inuse) {
continue; continue;
} }
Event *event = new Event( EV_Use ); Event* event = new Event(EV_Use);
event->AddListener( this ); event->AddListener(this);
hit->entity->ProcessEvent( event ); hit->entity->ProcessEvent(event);
if (m_pVehicle || m_pTurret) {
break;
}
}
if (i < num && m_pVehicle)
{
//
// Added in 2.30
// Make the vehicle also invincible if the player is invincible
//
if (flags & FL_GODMODE) {
m_pVehicle->flags |= FL_GODMODE;
} else {
m_pVehicle->flags &= ~FL_GODMODE;
}
} }
#endif
} }
void Player::TouchStuff(pmove_t *pm) void Player::TouchStuff(pmove_t *pm)
@ -5566,7 +5553,6 @@ void Player::GiveNewWeaponsCheat(Event *ev)
} }
void Player::GodCheat(Event *ev) void Player::GodCheat(Event *ev)
{ {
const char *msg; const char *msg;