Ejemplo n.º 1
0
/*
 *  Stocks client's inventory with specified item.  Weapons receive
 *  specified quantity of ammo, while health and armor are set to
 *  the specified quantity.
 */
static void G_Give(g_client_t *client, char *it, int quantity) {
	g_item_t *item;
	int index;

	if (!strcasecmp(it, "Health")) {
		client->persistent.health = quantity;
		return;
	}

	if (!strcasecmp(it, "Armor")) {
		client->persistent.armor = quantity;
		return;
	}

	item = G_FindItem(it);

	if (!item)
		return;

	index = ITEM_INDEX(item);

	if (item->type == ITEM_WEAPON) { // weapons receive quantity as ammo
		client->persistent.inventory[index] = 1;

		item = G_FindItem(item->ammo);
		index = ITEM_INDEX(item);

		if (quantity > -1)
			client->persistent.inventory[index] = quantity;
		else
			client->persistent.inventory[index] = item->quantity;
	} else { // while other items receive quantity directly
		if (quantity > -1)
			client->persistent.inventory[index] = quantity;
		else
			client->persistent.inventory[index] = item->quantity;
	}
}
Ejemplo n.º 2
0
/*QUAKED worldspawn(0 0 0) ?

 Only used for the world.
 "message"			"Stress Fractures by Jester"
 "sky"				unit1_
 "weather"			none, rain, snow, fog 0.5 0.8 0.7
 "gravity"			800
 "gameplay"			deathmatch, instagib, rocket arena
 "teams"			0 off, 1 on, 2 balanced
 "ctf"				0 off, 1 on, 2 balanced
 "match"			0 off, 1 on
 "round"			0 off, 1 on
 "frag_limit" 		20 frags
 "round_limit" 		20 rounds
 "capture_limit" 	8 captures
 "time_limit"		20 minutes
 "give"				comma-delimited items list
 "music"			comma-delimited track list
 */
static void G_worldspawn(g_edict_t *ent) {
	uint32_t i;
	g_map_list_elt_t *map;

	ent->locals.move_type = MOVE_TYPE_PUSH;
	ent->solid = SOLID_BSP;
	ent->in_use = true; // since the world doesn't use G_Spawn()
	ent->s.model1 = 0; // world model is always index 1

	map = NULL; // resolve the maps.lst entry for this level
	for (i = 0; i < g_map_list.count; i++) {
		if (!g_strcmp0(g_level.name, g_map_list.maps[i].name)) {
			map = &g_map_list.maps[i];
			break;
		}
	}

	if (ent->locals.message && *ent->locals.message)
		g_strlcpy(g_level.title, ent->locals.message, sizeof(g_level.title));
	else
		// or just the level name
		g_strlcpy(g_level.title, g_level.name, sizeof(g_level.title));
	gi.ConfigString(CS_NAME, g_level.title);

	if (map && *map->sky) // prefer maps.lst sky
		gi.ConfigString(CS_SKY, map->sky);
	else { // or fall back on worldspawn
		if (g_game.spawn.sky && *g_game.spawn.sky)
			gi.ConfigString(CS_SKY, g_game.spawn.sky);
		else
			// or default to unit1_
			gi.ConfigString(CS_SKY, "unit1_");
	}

	if (map && *map->weather) // prefer maps.lst weather
		gi.ConfigString(CS_WEATHER, map->weather);
	else { // or fall back on worldspawn
		if (g_game.spawn.weather && *g_game.spawn.weather)
			gi.ConfigString(CS_WEATHER, g_game.spawn.weather);
		else
			// or default to none
			gi.ConfigString(CS_WEATHER, "none");
	}

	if (map && map->gravity > 0) // prefer maps.lst gravity
		g_level.gravity = map->gravity;
	else { // or fall back on worldspawn
		if (g_game.spawn.gravity && *g_game.spawn.gravity)
			g_level.gravity = atoi(g_game.spawn.gravity);
		else
			// or default to 800
			g_level.gravity = 800;
	}

	if (g_strcmp0(g_gameplay->string, "default")) { // perfer g_gameplay
		g_level.gameplay = G_GameplayByName(g_gameplay->string);
	} else if (map && map->gameplay > -1) { // then maps.lst gameplay
		g_level.gameplay = map->gameplay;
	} else { // or fall back on worldspawn
		if (g_game.spawn.gameplay && *g_game.spawn.gameplay)
			g_level.gameplay = G_GameplayByName(g_game.spawn.gameplay);
		else
			// or default to deathmatch
			g_level.gameplay = DEATHMATCH;
	}
	if (g_level.gameplay == DEFAULT)
		g_level.gameplay = DEATHMATCH;
	gi.ConfigString(CS_GAMEPLAY, va("%d", g_level.gameplay));

	if (map && map->teams > -1) // prefer maps.lst teams
		g_level.teams = map->teams;
	else { // or fall back on worldspawn
		if (g_game.spawn.teams && *g_game.spawn.teams)
			g_level.teams = atoi(g_game.spawn.teams);
		else
			// or default to cvar
			g_level.teams = g_teams->integer;
	}

	if (map && map->ctf > -1) // prefer maps.lst ctf
		g_level.ctf = map->ctf;
	else { // or fall back on worldspawn
		if (g_game.spawn.ctf && *g_game.spawn.ctf)
			g_level.ctf = atoi(g_game.spawn.ctf);
		else
			// or default to cvar
			g_level.ctf = g_ctf->integer;
	}

	if (g_level.teams && g_level.ctf) // ctf overrides teams
		g_level.teams = 0;

	gi.ConfigString(CS_TEAMS, va("%d", g_level.teams));
	gi.ConfigString(CS_CTF, va("%d", g_level.ctf));

	if (map && map->match > -1) // prefer maps.lst match
		g_level.match = map->match;
	else { // or fall back on worldspawn
		if (g_game.spawn.match && *g_game.spawn.match)
			g_level.match = atoi(g_game.spawn.match);
		else
			// or default to cvar
			g_level.match = g_match->integer;
	}

	if (map && map->rounds > -1) // prefer maps.lst rounds
		g_level.rounds = map->rounds;
	else { // or fall back on worldspawn
		if (g_game.spawn.rounds && *g_game.spawn.rounds)
			g_level.rounds = atoi(g_game.spawn.rounds);
		else
			// or default to cvar
			g_level.rounds = g_rounds->integer;
	}

	if (g_level.match && g_level.rounds) // rounds overrides match
		g_level.match = 0;

	gi.ConfigString(CS_MATCH, va("%d", g_level.match));
	gi.ConfigString(CS_ROUNDS, va("%d", g_level.rounds));

	if (map && map->frag_limit > -1) // prefer maps.lst frag_limit
		g_level.frag_limit = map->frag_limit;
	else { // or fall back on worldspawn
		if (g_game.spawn.frag_limit && *g_game.spawn.frag_limit)
			g_level.frag_limit = atoi(g_game.spawn.frag_limit);
		else
			// or default to cvar
			g_level.frag_limit = g_frag_limit->integer;
	}

	if (map && map->round_limit > -1) // prefer maps.lst round_limit
		g_level.round_limit = map->round_limit;
	else { // or fall back on worldspawn
		if (g_game.spawn.round_limit && *g_game.spawn.round_limit)
			g_level.round_limit = atoi(g_game.spawn.round_limit);
		else
			// or default to cvar
			g_level.round_limit = g_round_limit->integer;
	}

	if (map && map->capture_limit > -1) // prefer maps.lst capture_limit
		g_level.capture_limit = map->capture_limit;
	else { // or fall back on worldspawn
		if (g_game.spawn.capture_limit && *g_game.spawn.capture_limit)
			g_level.capture_limit = atoi(g_game.spawn.capture_limit);
		else
			// or default to cvar
			g_level.capture_limit = g_capture_limit->integer;
	}

	vec_t time_limit;
	if (map && map->time_limit > -1) // prefer maps.lst time_limit
		time_limit = map->time_limit;
	else { // or fall back on worldspawn
		if (g_game.spawn.time_limit && *g_game.spawn.time_limit)
			time_limit = atof(g_game.spawn.time_limit);
		else
			// or default to cvar
			time_limit = g_time_limit->value;
	}
	g_level.time_limit = time_limit * 60 * 1000;

	if (map && *map->give) // prefer maps.lst give
		g_strlcpy(g_level.give, map->give, sizeof(g_level.give));
	else { // or fall back on worldspawn
		if (g_game.spawn.give && *g_game.spawn.give)
			g_strlcpy(g_level.give, g_game.spawn.give, sizeof(g_level.give));
		else
			// or clean it
			g_level.give[0] = '\0';
	}

	if (map && *map->music) // prefer maps.lst music
		g_strlcpy(g_level.music, map->music, sizeof(g_level.music));
	else { // or fall back on worldspawn
		if (g_game.spawn.music && *g_game.spawn.music)
			g_strlcpy(g_level.music, g_game.spawn.music, sizeof(g_level.music));
		else
			g_level.music[0] = '\0';
	}

	G_WorldspawnMusic();

	G_PrecacheItem(G_FindItem("Blaster"));
	G_PrecacheItem(G_FindItem("Shotgun"));
	G_PrecacheItem(G_FindItem("Shuper Shotgun"));
	G_PrecacheItem(G_FindItem("Machinegun"));
	G_PrecacheItem(G_FindItem("Grenade Launcher"));
	G_PrecacheItem(G_FindItem("Rocket Launcher"));
	G_PrecacheItem(G_FindItem("Hyperblaster"));
	G_PrecacheItem(G_FindItem("Lightning"));
	G_PrecacheItem(G_FindItem("Railgun"));
	G_PrecacheItem(G_FindItem("BFG10K"));

	gi.SoundIndex("world/water_in");
	gi.SoundIndex("world/water_out");

	gi.SoundIndex("weapons/common/no_ammo");
	gi.SoundIndex("weapons/common/pickup");
	gi.SoundIndex("weapons/common/switch");

	gi.ConfigString(CS_VOTE, "");
	gi.ConfigString(CS_TEAM_GOOD, g_team_good.name);
	gi.ConfigString(CS_TEAM_EVIL, g_team_evil.name);
}