2020-01-05 02:25:00 +00:00
|
|
|
#include "g_local.h"
|
|
|
|
|
2021-01-26 05:08:08 +00:00
|
|
|
#define KEY_MESSAGE_SIZE 10
|
|
|
|
|
2020-01-05 02:25:00 +00:00
|
|
|
//=====================================================
|
|
|
|
|
|
|
|
void SP_target_lock_digit (edict_t *self)
|
|
|
|
{
|
2020-09-04 07:39:59 +00:00
|
|
|
self->class_id = ENTITY_TARGET_LOCK_DIGIT;
|
|
|
|
|
2020-01-05 02:25:00 +00:00
|
|
|
self->movetype = MOVETYPE_PUSH;
|
|
|
|
gi.setmodel (self, self->model);
|
|
|
|
self->solid = SOLID_BSP;
|
|
|
|
self->s.frame = 12;
|
|
|
|
gi.linkentity (self);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void target_lock_use (edict_t *self, edict_t *other, edict_t *activator)
|
|
|
|
{
|
|
|
|
edict_t *e;
|
|
|
|
int n;
|
|
|
|
char current[16];
|
|
|
|
char *copy_message;
|
|
|
|
|
|
|
|
memset(current,0,16);
|
|
|
|
|
|
|
|
for (e = self->teammaster; e; e = e->teamchain)
|
|
|
|
{
|
|
|
|
if (!e->count)
|
|
|
|
continue;
|
|
|
|
n = e->count - 1;
|
|
|
|
current[n] = '0' + e->s.frame;
|
|
|
|
}
|
2021-01-26 05:08:08 +00:00
|
|
|
if ( strcmp(current, self->key_message) == 0 )
|
2020-01-05 02:25:00 +00:00
|
|
|
{
|
|
|
|
copy_message = self->message;
|
|
|
|
self->message = NULL;
|
|
|
|
G_UseTargets(self,activator);
|
|
|
|
self->message = copy_message;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-09-04 07:39:59 +00:00
|
|
|
if (self->message) gi.centerprintf(activator,self->message);
|
|
|
|
if (self->pathtarget) {
|
2020-01-05 02:25:00 +00:00
|
|
|
e = G_Find(NULL,FOFS(targetname),self->pathtarget);
|
2020-09-04 07:39:59 +00:00
|
|
|
if (e) e->use(e,other,activator);
|
2020-01-05 02:25:00 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
BeepBeep(activator);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void lock_digit_increment (edict_t *digit, edict_t *activator)
|
|
|
|
{
|
2020-09-04 07:39:59 +00:00
|
|
|
if (digit->s.frame == 9)
|
2020-01-05 02:25:00 +00:00
|
|
|
digit->s.frame = 0;
|
|
|
|
else
|
|
|
|
digit->s.frame++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void lock_initialize (edict_t *lock)
|
|
|
|
{
|
|
|
|
edict_t *e;
|
|
|
|
int n, l;
|
|
|
|
int numdigits;
|
|
|
|
char c;
|
2021-01-26 05:08:08 +00:00
|
|
|
size_t msgSize;
|
2020-01-05 02:25:00 +00:00
|
|
|
|
2021-01-26 05:08:08 +00:00
|
|
|
if ( (lock->spawnflags & 1) && (strlen(game.lock_code) != 0) )
|
2020-01-05 02:25:00 +00:00
|
|
|
{
|
2021-01-26 05:08:08 +00:00
|
|
|
// Knightmare- dynamically allocate this to be safe
|
|
|
|
// This will temporarily leak the already allocated key_message
|
|
|
|
// buffer, but that will be freed on the next level change.
|
|
|
|
// strcpy (lock->key_message, game.lock_code);
|
|
|
|
msgSize = KEY_MESSAGE_SIZE;
|
|
|
|
lock->key_message = gi.TagMalloc(msgSize, TAG_LEVEL);
|
|
|
|
Com_strcpy (lock->key_message, msgSize, game.lock_code);
|
2020-01-05 02:25:00 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-01-26 05:08:08 +00:00
|
|
|
|
2020-01-05 02:25:00 +00:00
|
|
|
// Maximum of 8 digits in combination
|
2021-01-26 05:08:08 +00:00
|
|
|
l = min((int)strlen(lock->key_message), 8);
|
2020-01-05 02:25:00 +00:00
|
|
|
numdigits = 0;
|
|
|
|
for (e = lock->teammaster; e; e = e->teamchain)
|
|
|
|
{
|
|
|
|
if (!e->count)
|
|
|
|
continue;
|
2021-01-26 05:08:08 +00:00
|
|
|
numdigits = max(numdigits, e->count);
|
2020-01-05 02:25:00 +00:00
|
|
|
n = e->count - 1;
|
|
|
|
if (n > l)
|
|
|
|
{
|
|
|
|
e->s.frame = 12;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
c = lock->key_message[n];
|
|
|
|
if (c >= '0' && c <= '9')
|
|
|
|
e->s.frame = c - '0';
|
|
|
|
else
|
|
|
|
e->s.frame = 0;
|
|
|
|
}
|
|
|
|
// Now generate a random number as the lock combination
|
|
|
|
srand(time(NULL));
|
|
|
|
n = random();
|
|
|
|
n = random();
|
|
|
|
n = random();
|
2021-01-26 05:08:08 +00:00
|
|
|
for (n=0; n<numdigits; n++)
|
2020-01-05 02:25:00 +00:00
|
|
|
lock->key_message[n] = '0' + (int)(random() * 9.99);
|
|
|
|
lock->key_message[numdigits] = '\0';
|
|
|
|
|
2021-01-26 05:08:08 +00:00
|
|
|
Com_strcpy (game.lock_code, sizeof(game.lock_code), lock->key_message);
|
2020-01-05 02:25:00 +00:00
|
|
|
game.lock_revealed = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SP_target_lock (edict_t *self)
|
|
|
|
{
|
|
|
|
if (game.lock_hud && (self->spawnflags & 2))
|
|
|
|
{
|
|
|
|
gi.dprintf("Map contains multiple target_locks and HUD is set.\n");
|
|
|
|
G_FreeEdict(self);
|
|
|
|
return;
|
|
|
|
}
|
2020-09-04 07:39:59 +00:00
|
|
|
|
|
|
|
self->class_id = ENTITY_TARGET_LOCK;
|
|
|
|
|
2021-01-26 05:08:08 +00:00
|
|
|
if (self->spawnflags & 2)
|
|
|
|
game.lock_hud = true;
|
|
|
|
if (!self->key_message) {
|
|
|
|
// Knightmare- dynamically allocate this to be safe
|
|
|
|
// self->key_message = "000000000";
|
|
|
|
self->key_message = gi.TagMalloc(KEY_MESSAGE_SIZE, TAG_LEVEL);
|
|
|
|
Com_strcpy (self->key_message, KEY_MESSAGE_SIZE, "000000000");
|
|
|
|
}
|
2020-01-05 02:25:00 +00:00
|
|
|
self->use = target_lock_use;
|
|
|
|
self->think = lock_initialize;
|
|
|
|
self->nextthink = level.time + 1.0;
|
|
|
|
gi.linkentity(self);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// target_lock_code reveals the lock combination to the
|
|
|
|
// target_lock specified in it's target field, or in global
|
|
|
|
// game data for crosslevel locks
|
|
|
|
//
|
|
|
|
void lock_code_use (edict_t *self, edict_t *other, edict_t *activator)
|
|
|
|
{
|
|
|
|
int i, L;
|
|
|
|
char message[64];
|
2020-09-04 07:39:59 +00:00
|
|
|
if (self->spawnflags & 1)
|
2020-01-05 02:25:00 +00:00
|
|
|
{
|
2020-09-04 07:39:59 +00:00
|
|
|
if (!strlen(game.lock_code))
|
2020-01-05 02:25:00 +00:00
|
|
|
{
|
|
|
|
gi.dprintf("Lock has not been properly initialized.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Com_sprintf(message, sizeof(message), "Lock combination is %s",game.lock_code);
|
|
|
|
Do_Text_Display(activator, 0, message);
|
|
|
|
L = (int)strlen(game.lock_code);
|
|
|
|
for(i=0; i<L; i++)
|
|
|
|
game.lock_revealed |= 1<<i;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
edict_t *lock;
|
|
|
|
lock = G_Find(NULL,FOFS(targetname),self->target);
|
2020-09-04 07:39:59 +00:00
|
|
|
if (!lock)
|
2020-01-05 02:25:00 +00:00
|
|
|
gi.dprintf("Target of target_lock_code does not exist\n");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Com_sprintf(message, sizeof(message), "Lock combination is %s",game.lock_code);
|
|
|
|
Do_Text_Display(activator, 0, message);
|
|
|
|
L = min(8, (int)strlen(lock->key_message));
|
|
|
|
for(i=0; i<L; i++)
|
|
|
|
game.lock_revealed |= 1<<i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SP_target_lock_code (edict_t *self)
|
|
|
|
{
|
2020-09-04 07:39:59 +00:00
|
|
|
self->class_id = ENTITY_TARGET_LOCK_CODE;
|
|
|
|
|
|
|
|
if (!self->target && !(self->spawnflags & 1))
|
2020-01-05 02:25:00 +00:00
|
|
|
{
|
|
|
|
gi.dprintf("non-crosslevel target_lock_code w/o target\n");
|
|
|
|
G_FreeEdict(self);
|
|
|
|
}
|
|
|
|
self->use = lock_code_use;
|
|
|
|
}
|
|
|
|
|
|
|
|
void lock_clue_use (edict_t *self, edict_t *other, edict_t *activator)
|
|
|
|
{
|
|
|
|
int i, L;
|
2020-09-04 07:39:59 +00:00
|
|
|
if (self->spawnflags & 1)
|
2020-01-05 02:25:00 +00:00
|
|
|
{
|
2020-09-04 07:39:59 +00:00
|
|
|
if (!strlen(game.lock_code))
|
2020-01-05 02:25:00 +00:00
|
|
|
{
|
|
|
|
gi.dprintf("Lock has not been properly initialized.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
L = (int)strlen(game.lock_code);
|
|
|
|
for(i=0; i<L; i++)
|
2020-09-04 07:39:59 +00:00
|
|
|
if (self->message[i] != '?') game.lock_revealed |= 1<<i;
|
2020-01-05 02:25:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
edict_t *lock;
|
|
|
|
lock = G_Find(NULL,FOFS(targetname),self->target);
|
2020-09-04 07:39:59 +00:00
|
|
|
if (!lock)
|
2020-01-05 02:25:00 +00:00
|
|
|
gi.dprintf("Target of target_lock_clue does not exist\n");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
L = min(8, (int)strlen(lock->key_message));
|
|
|
|
for(i=0; i<L; i++)
|
2020-09-04 07:39:59 +00:00
|
|
|
if (self->message[i] != '?') game.lock_revealed |= 1<<i;
|
2020-01-05 02:25:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void lock_clue_think(edict_t *self)
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
int unrevealed_count;
|
|
|
|
edict_t *e;
|
|
|
|
|
2020-09-04 07:39:59 +00:00
|
|
|
if (!self->team)
|
2020-01-05 02:25:00 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
unrevealed_count = 0;
|
|
|
|
for (e = self->teammaster; e; e = e->teamchain)
|
|
|
|
{
|
|
|
|
if (!e->count)
|
|
|
|
continue;
|
|
|
|
n = e->count - 1;
|
2020-09-04 07:39:59 +00:00
|
|
|
if (game.lock_revealed & 1<<n)
|
2020-01-05 02:25:00 +00:00
|
|
|
e->s.frame = game.lock_code[n] - '0';
|
|
|
|
else
|
|
|
|
{
|
|
|
|
e->s.frame++; // spin unknown digits
|
2020-09-04 07:39:59 +00:00
|
|
|
if (e->s.frame > 9) e->s.frame = 0;
|
2020-01-05 02:25:00 +00:00
|
|
|
unrevealed_count++;
|
|
|
|
}
|
|
|
|
}
|
2020-09-04 07:39:59 +00:00
|
|
|
if (unrevealed_count)
|
2020-01-05 02:25:00 +00:00
|
|
|
{
|
|
|
|
self->nextthink = level.time + FRAMETIME;
|
|
|
|
gi.linkentity(self);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void lock_clue_initialize(edict_t *self)
|
|
|
|
{
|
|
|
|
// Randomize the revealed digits so spinning display doesn't
|
|
|
|
// show the same numbers across the board.
|
|
|
|
|
|
|
|
edict_t *e;
|
2020-09-04 07:39:59 +00:00
|
|
|
if (self->team)
|
2020-01-05 02:25:00 +00:00
|
|
|
{
|
|
|
|
for (e = self->teammaster; e; e = e->teamchain)
|
|
|
|
{
|
|
|
|
if (!e->count)
|
|
|
|
continue;
|
|
|
|
e->s.frame = (int)(random() * 9.99);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
self->think = lock_clue_think;
|
|
|
|
self->nextthink = level.time + FRAMETIME;
|
|
|
|
gi.linkentity(self);
|
|
|
|
}
|
2021-01-26 05:08:08 +00:00
|
|
|
|
2020-01-05 02:25:00 +00:00
|
|
|
void SP_target_lock_clue (edict_t *self)
|
|
|
|
{
|
2020-09-04 07:39:59 +00:00
|
|
|
self->class_id = ENTITY_TARGET_LOCK_CLUE;
|
|
|
|
|
|
|
|
if (!self->target && !(self->spawnflags & 1))
|
2020-01-05 02:25:00 +00:00
|
|
|
{
|
|
|
|
gi.dprintf("non-crosslevel target_lock_clue w/o target\n");
|
|
|
|
G_FreeEdict(self);
|
|
|
|
}
|
|
|
|
self->use = lock_clue_use;
|
|
|
|
self->think = lock_clue_initialize;
|
|
|
|
self->nextthink = level.time + 2*FRAMETIME;
|
|
|
|
gi.linkentity(self);
|
|
|
|
}
|