void SP_func_clock (edict_t *self) { if (!self->target) { gi.dprintf("%s with no target at %s\n", self->classname, vtos(self->s.origin)); G_FreeEdict (self); return; } if ((self->spawnflags & 2) && (!self->count)) { gi.dprintf("%s with no count at %s\n", self->classname, vtos(self->s.origin)); G_FreeEdict (self); return; } if ((self->spawnflags & 1) && (!self->count)) self->count = 60*60;; func_clock_reset (self); self->message = gi.TagMalloc (CLOCK_MESSAGE_SIZE, TAG_LEVEL); self->think = func_clock_think; if (self->spawnflags & 4) self->use = func_clock_use; else self->nextthink = level.time + 1; }
void func_clock_think(edict_t *self) { if (!self->enemy) { self->enemy = G_Find(NULL, FOFS(targetname), self->target); if (!self->enemy) return; } if (self->spawnflags & 1) { func_clock_format_countdown(self); self->health++; } else if (self->spawnflags & 2) { func_clock_format_countdown(self); self->health--; } else { struct tm *ltime; time_t gmtime; gmtime = time(NULL); ltime = localtime(&gmtime); if (ltime) Q_snprintf(self->message, CLOCK_MESSAGE_SIZE, "%2i:%2i:%2i", ltime->tm_hour, ltime->tm_min, ltime->tm_sec); else strcpy(self->message, "00:00:00"); if (self->message[3] == ' ') self->message[3] = '0'; if (self->message[6] == ' ') self->message[6] = '0'; } self->enemy->message = self->message; self->enemy->use(self->enemy, self, self); if (((self->spawnflags & 1) && (self->health > self->wait)) || ((self->spawnflags & 2) && (self->health < self->wait))) { if (self->pathtarget) { char *savetarget; char *savemessage; savetarget = self->target; savemessage = self->message; self->target = self->pathtarget; self->message = NULL; G_UseTargets(self, self->activator); self->target = savetarget; self->message = savemessage; } if (!(self->spawnflags & 8)) return; func_clock_reset(self); if (self->spawnflags & 4) return; } self->nextthink = level.time + 1; }