I've written some code that works, but I'm wondering about potential
problems, and alternate coding approaches.

My goal is to create shared resources for multiplayer gaming: the
condition of the resource affects the condition of multiple players.
If the players tend their resources, shared conditions improve;
neglecting or damaging resources hurts everybody.

For starters, I'm working on a Power Spore -- a energy source which
maintains player life support systems. Here's how I've currently got
it working --

In CBasePlayer::Spawn, do a FindEntity for "xen_spore_power".

In player's pev, save an entvars reference to the Spore:
pev->euser1 = pEnt->edict()

In CBasePlayer::CheckTimeBased Damage, get an entity instance of the
entvar, so we can test and modify the spore's values --

CBaseEntity *pEntity ;
if ( pev->euser1 != NULL )
{
   pEntity = CBaseEntity::Instance( pev->euser1 );
   // now test pEntity, tweak with randoms ...
   // maybe change the spore's power level, color of spore sprite
   // maybe cause player pain, etc.
}

The spore's power level is a CBaseEntity integer.  I do this routine
in CheckTimeBasedDamage because --

* it happens at a convenient interval
* the thing I'm checking is "should player take time-based damage
pain?", so this is where I stuck it.

(-- but really the players could be checking this elsewhere, if
needed).

The spore's power level is an integer declared in CBaseEntity.

The spore has a Touch method, where it checks the touched entity or
entities, and, under certain conditions (not yet coded), increment
the spore's power level.

In the spore's Think method, it checks power level -- at certain
threasholds, the spore changes sprite color to indicate state.

The spore code is a modified form of xen_spore_large, with a sprite
and a touchfield, plus the modified Think code.

Okay, that about sums it up.  The above code does work, at least
during my testing.  Now the questions --

* Is the spore's power level value subject to contention failure,
given enough players over enough time?  Players repeatedly creating
instances of the spore, testing the spore's power level, and
*changing* the power level -- this looks sloppy, like the spore is
going to get bad values over time.  Is there some mechanism in the
engine that's going to save me from dirty reads and illegal writes?

* Rather than players checking/setting spore state, should I instead
have the spore::Think do FindEntity for all players, get instances of
the players, do the calcs and random tweaks, then modify suit/health
of affected players?  (But -- all that FindEntity overhead for
however many players ... versus each player making a quick
instantiation to a common entvars reference....)

* Other structural changes?  Alternate approaches?  Cautionary tales?

All comments welcome;  thanks in advance.

- Karl Jones ... the Handy Vandal




_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders

Reply via email to