/* After 20 seconds have passed */ local int TimeUp(void *p) { Player *host = p; Arena *arena = host->arena; Adata *adata = P_ARENA_DATA(arena, arenaKey); if (adata->started == 0) return 0; /* Open the Doors and prize the players */ Player *g; Link *link; cs->ArenaOverride(arena, ok_Doors, 0); pd->Lock(); FOR_EACH_PLAYER(g) { if (g->arena == arena) { cs->SendClientSettings(g); if (g->p_ship != SHIP_SPEC) { Target target; target.type = T_PLAYER; target.u.p = g; game->ShipReset(&target); game->GivePrize(&target, PRIZE_ROCKET, 1); if (adata->mystery) { game->GivePrize(&target, PRIZE_CLOAK, 1); game->GivePrize(&target, PRIZE_STEALTH, 1); } Pdata *pdata = PPDATA(g, playerKey); pdata->won = 0; } } } pd->Unlock(); CheckLegalShip(arena); chat->SendArenaSoundMessage(arena, 104, "Race started."); adata->starttime = current_millis(); adata->started = 2; mm->RegCallback(CB_PLAYERACTION, PlayerAction, arena); mm->RegCallback(CB_SHIPFREQCHANGE, ShipFreqChange, arena); mm->RegCallback(CB_REGION, EnterRegion, arena); ml->SetTimer(RocketArea, 200, 200, host, arena); return 0; }
/* Get the current time. */ local void GetWintime(Arena *arena, int action) { if ((action == AA_CREATE) && (wintime == 0)) //Make sure we don't redeclare wintime when arena is recreated. { wintime = current_millis(); } }
/* List stats. */ local void FlagReset(Arena *arena, int freq, int points, int stat, int interval, Player *p, Target *target) { gametime = current_millis(); if ((gametime - wintime) < 0) wintime = gametime; int ctsecs = (gametime - wintime) / 1000; int ctmins = ctsecs / 60; int chours = ctmins / 60; int csecs = ctsecs - (ctmins * 60); int cmins = ctmins - (chours * 60); Link *link; Player *g; int kills = 0, deaths = 0, tks = 0, fkills = 0, fdeaths = 0, goals = 0, flagdrops = 0, flagtime = 0, shipchanges = 0, killpoints = 0; int reward = jp->GetJP(arena) + 10; chat->SendArenaMessage(arena,"|-------------------------------------------------------------------------------|"); chat->SendArenaMessage(arena,"| Reward: %-12d Game Time: %03i:%02i:%02i |", reward, chours, cmins, csecs); chat->SendArenaMessage(arena,"|-------------------------------------------------------------------------------|"); chat->SendArenaMessage(arena,"| Player W L TK FW FL G FD FT SC KP |"); chat->SendArenaMessage(arena,"|-------------------------------------------------------------------------------|"); pd->Lock(); FOR_EACH_PLAYER(g) { Pdata *data = PPDATA(g, playerKey); /* Only list players who've played. */ if ((data->played == 1 && g->arena == arena) || (g->p_ship != SHIP_SPEC && g->arena == arena)) { kills = stats->GetStat(g, STAT_KILLS, INTERVAL_GAME); deaths = stats->GetStat(g, STAT_DEATHS, INTERVAL_GAME); tks = stats->GetStat(g, STAT_TEAM_KILLS, INTERVAL_GAME); fkills = stats->GetStat(g, STAT_FLAG_KILLS, INTERVAL_GAME); fdeaths = stats->GetStat(g, STAT_FLAG_DEATHS, INTERVAL_GAME); goals = stats->GetStat(g, STAT_BALL_GOALS, INTERVAL_GAME); flagdrops = stats->GetStat(g, STAT_FLAG_DROPS, INTERVAL_GAME); flagtime = stats->GetStat(g, STAT_FLAG_CARRY_TIME, INTERVAL_GAME); shipchanges = data->shipchanges; killpoints = stats->GetStat(g, STAT_KILL_POINTS, INTERVAL_GAME); chat->SendArenaMessage(arena,"| %-24s %-4d %-4d %-4d %-4d %-4d %-3d %-3d %-4d %-3d %-10d |", g->name, kills, deaths, tks, fkills, fdeaths, goals, flagdrops, flagtime, shipchanges, killpoints); } } pd->Unlock(); chat->SendArenaMessage(arena,"|-------------------------------------------------------------------------------|"); wintime = current_millis(); /* Reset Shipchanges and check if they've played (i.e. unspecced) */ pd->Lock(); FOR_EACH_PLAYER(g) { Pdata *data = PPDATA(g, playerKey); data->shipchanges = 0; data->played = 0; } pd->Unlock(); }
int transmit(void) { // Hide the cursor, and make sure it comes back before exiting. set_cursor(false); signal(SIGINT, sigint_handler); // Set up the keyboard listener. long time_unit = calibrate_listener(); if (time_unit == EOF) { return 0; } if (!spawn_listener()) { print_error("error creating thread"); return 1; } // Set up the circular buffers. int buf_size = number_of_columns(); char code_buf[buf_size]; char text_buf[buf_size]; struct Circle code_circ, text_circ; init_empty(&code_circ, code_buf, buf_size); init_empty(&text_circ, text_buf, buf_size); append(&code_circ, '*'); // Begin the main loop. Code code = 0; int code_size = 0; bool done = false; long time = current_millis(); enum { NONE, CHAR, WORD } wait_mode = NONE; while (!done) { // Check the state of the keyboard listener. long time_now = current_millis(); enum ListenerState state = get_listener_state(time_now); switch (state) { case LS_EOF: done = true; continue; case LS_NONE: break; case LS_DOWN: insert(&code_circ, '.'); wait_mode = NONE; code <<= 1; code_size++; break; case LS_REPEAT: insert(&code_circ, '-'); code |= 1; break; case LS_HOLD: case LS_HOLD_R: break; case LS_UP: append(&code_circ, '*'); time = time_now; wait_mode = CHAR; break; } // Check if enough time has passed to start a new character or word. long elapsed = time_now - time; switch (wait_mode) { case NONE: break; case CHAR: if (elapsed > TIME_BETWEEN_CHARS) { insert(&code_circ, ' '); append(&code_circ, '*'); wait_mode = WORD; char ch = INVALID_CODE; if (code_size <= MAX_SIZE) { code = add_size(code, code_size); char decoded = code_to_char(code); if (decoded) { ch = decoded; } } append(&text_circ, ch); code = 0; code_size = 0; } break; case WORD: if (elapsed > TIME_BETWEEN_WORDS) { insert(&code_circ, '/'); append(&code_circ, ' '); append(&code_circ, '*'); wait_mode = NONE; append(&text_circ, ' '); } break; } // Print the contents of both buffers. putchar('\r'); print_circle(&code_circ); fputs(" \n", stdout); print_circle(&text_circ); fputs(" \x1B[F", stdout); fflush(stdout); usleep(SLEEP_TIME_US); } cleanup(); return 0; }