#pragma once

#include "..\munga\style.h"

//########################################################################
//########################## RPL4 Local Console ##########################
//########################################################################
//
// The single-player marshal. Hand-fed eggs are a developer shortcut: a
// mission only ends on a console command, so without one the timer hits
// 00:00 and just counts up forever. This is the in-process console for
// front-end-launched games - it watches the mission, dispatches the
// same StopMissionMessage TeslaConsole sent when the selected length
// expires, and when the pod returns to WaitingForEgg it brings the race
// setup back up and feeds the next egg (or quits if the player closes
// the menu).
//
// Installs itself as the application manager's per-frame hook.
//
void
	RPL4LocalConsole_Install(int mission_seconds);

// True when the last mission ended under the console's control (timer
// stop or pilot exit). WinMain's single-binary race loop then cycles
// back to the setup screen for the next race in the same process.
Logical
	RPL4LocalConsole_MissionCompleted();

// Network race: the owner pod meshes like any pod (network mode, egg
// fed locally) while this console marshals the REMOTE pods over the
// NetTransport wire with the arcade protocol - egg chunks + ACK,
// state polling, RunMission when everyone stages, StopMission at
// expiry, EndMission score intake. remote_pod_list is a comma list of
// console channels ("ip[:port]", default CONSOLE_NET_PORT);
// pilot_names is a comma list in [pilots] order for the results
// screen. Connects synchronously (retry, like the arcade console
// redialing a booting pod); False when a pod cannot be reached.
Logical
	RPL4LocalConsole_InstallNetworkRace(
		int mission_seconds,
		const char *egg_path,
		const char *remote_pod_list,
		const char *pilot_names
	);

// The last completed mission's final scores (what each pod reported at
// mission end). Valid until the next mission starts running.
int
	RPL4LocalConsole_ResultCount();

Logical
	RPL4LocalConsole_GetResult(int index, int *host_ID, int *score);

// Pilot name for a host ID ([pilots] order; host 2 = first pilot).
// NULL when unknown - the results screen falls back to pod numbers.
const char *
	RPL4LocalConsole_GetResultName(int host_ID);

// Lobby members do not marshal races - the owner publishes the score
// sheet through lobby data and it is injected here so the same results
// screen shows on every machine.
void
	RPL4LocalConsole_ClearResults();
void
	RPL4LocalConsole_InjectResult(int host_ID, int score, const char *name);
