Exemplo n.º 1
0
/**
 * @brief Solve the result of one projectile hitting an aircraft.
 * @param[in] campaign The campaign data structure
 * @param[in] projectile Pointer to the projectile.
 * @note the target loose (base damage - shield of target) hit points
 */
static void AIRFIGHT_ProjectileHits (const campaign_t* campaign, aircraftProjectile_t *projectile)
{
	aircraft_t *target;
	int damage = 0;

	assert(projectile);
	target = projectile->aimedAircraft;
	assert(target);

	/* if the aircraft is not on geoscape anymore, do nothing (returned to base) */
	if (AIR_IsAircraftInBase(target))
		return;

	damage = AIRFIGHT_GetDamage(projectile->aircraftItem, target);

	/* apply resulting damages - but only if damage > 0 - because the target might
	 * already be destroyed, and we don't want to execute the actions after airfight
	 * for every projectile */
	if (damage > 0) {
		assert(target->damage > 0);
		target->damage -= damage;
		if (target->damage <= 0) {
			/* Target is destroyed */
			AIRFIGHT_ActionsAfterAirfight(campaign, projectile->attackingAircraft, target, target->type == AIRCRAFT_UFO);
			S_StartLocalSample("geoscape/combat-explosion", 1.0f);
		} else {
			S_StartLocalSample("geoscape/combat-rocket-exp", 1.0f);
		}
	}
}
Exemplo n.º 2
0
/*
 * S_Play_f
 */
static void S_Play_f(void) {
	int i;

	i = 1;
	while (i < Cmd_Argc()) {
		S_StartLocalSample(Cmd_Argv(i));
		i++;
	}
}
Exemplo n.º 3
0
/**
 * @brief Plays sound fx files via console
 */
static void S_Play_f (void)
{
    int i;

    if (Cmd_Argc() < 2) {
        Com_Printf("Usage: %s <filename> [<filename> ...]\n", Cmd_Argv(0));
        return;
    }

    i = 1;
    while (i < Cmd_Argc()) {
        S_StartLocalSample(Cmd_Argv(i), SND_VOLUME_DEFAULT);
        i++;
    }
}
/**
 * @brief Shoot with weapon but don't bother with animations - actor is hidden.
 * @sa CL_ActorShoot
 */
void CL_ActorShootHidden (const eventRegister_t* self, dbuffer* msg)
{
	int first;
	int objIdx;
	weaponFireDefIndex_t weapFdsIdx;
	fireDefIndex_t fdIdx;

	NET_ReadFormat(msg, self->formatString, &first, &objIdx, &weapFdsIdx, &fdIdx);

	/* get the fire def */
	const objDef_t* obj = INVSH_GetItemByIDX(objIdx);
	const fireDef_t* fd = FIRESH_GetFiredef(obj, weapFdsIdx, fdIdx);

	/* start the sound */
	if ((first || !fd->soundOnce) && fd->fireSound != nullptr)
		S_StartLocalSample(fd->fireSound, SND_VOLUME_WEAPONS);
}
Exemplo n.º 5
0
/**
 * @brief Left click on the basemap
 * @sa UI_BaseMapRightClick
 * @param[in] node Node definition for the base map
 * @param[in] x Absolute X mouse position into the screen
 * @param[in] y Absolute Y mouse position into the screen
 */
static void UI_BaseMapNodeClick (uiNode_t *node, int x, int y)
{
	int row, col;
	base_t *base = B_GetCurrentSelectedBase();

	assert(base);
	assert(node);
	assert(node->root);

	UI_BaseMapGetCellAtPos(node, x, y, &col, &row);
	if (col == -1)
		return;

	if (ccs.baseAction == BA_NEWBUILDING) {
		building_t *building = base->buildingCurrent;
		int y, x;

		assert(building);

		if (col + building->size[0] > BASE_SIZE)
			return;
		if (row + building->size[1] > BASE_SIZE)
			return;
		for (y = row; y < row + building->size[1]; y++)
			for (x = col; x < col + building->size[0]; x++)
				if (B_GetBuildingAt(base, x, y) != NULL || B_IsTileBlocked(base, x, y))
					return;
		B_SetBuildingByClick(base, building, row, col);
		S_StartLocalSample("geoscape/build-place", 1.0f);
		return;
	}

	if (B_GetBuildingAt(base, col, row) != NULL) {
		const building_t *entry = B_GetBuildingAt(base, col, row);

		if (B_IsTileBlocked(base, col, row))
			Com_Error(ERR_DROP, "tile with building is not blocked");

		B_BuildingOpenAfterClick(entry);
		ccs.baseAction = BA_NONE;
		return;
	}
}
Exemplo n.º 6
0
/**
 * @brief Performs end-of-turn processing.
 * @param[in] self Pointer to the event structure that is currently executed
 * @param[in] msg The netchannel message
 * @sa CL_EndRoundAnnounce
 */
void CL_DoEndRound (const eventRegister_t* self, dbuffer* msg)
{
	/* hud changes */
	if (cls.isOurRound())
		UI_ExecuteConfunc("endround");

	refdef.rendererFlags &= ~RDF_IRGOGGLES;

	/* change active player */
	Com_Printf("Team %i ended round\n", cl.actTeam);
	cl.actTeam = NET_ReadByte(msg);
	Com_Printf("Team %i's round started!\n", cl.actTeam);

	/* hud changes */
	if (cls.isOurRound()) {
		/* check whether a particle has to go */
		CL_ParticleCheckRounds();
		UI_ExecuteConfunc("startround");
		HUD_DisplayMessage(_("Your round started!"));
		S_StartLocalSample("misc/roundstart", SND_VOLUME_DEFAULT);
		CL_ActorConditionalMoveCalc(selActor);
	}
}
Exemplo n.º 7
0
/**
 * @brief Plays a sound in a sequence
 * @return 1 - increase the command position of the sequence by one
 */
static int SEQ_ExecuteSound (sequenceContext_t *context, const char *name, const char *data)
{
	S_StartLocalSample(name, SND_VOLUME_DEFAULT);
	return 1;
}
Exemplo n.º 8
0
/**
 * @brief Add a projectile in ccs.projectiles
 * @param[in] attackingBase the attacking base in ccs.bases[]. NULL is the attacker is an aircraft or a samsite.
 * @param[in] attackingInstallation the attacking samsite in ccs.installations[]. NULL is the attacker is an aircraft or a base.
 * @param[in] attacker Pointer to the attacking aircraft
 * @param[in] target Pointer to the target aircraft
 * @param[in] weaponSlot Pointer to the weapon slot that fires the projectile.
 * @note we already checked in AIRFIGHT_ChooseWeapon that the weapon has still ammo
 * @sa AIRFIGHT_RemoveProjectile
 * @sa AII_ReloadWeapon for the aircraft item reload code
 */
static qboolean AIRFIGHT_AddProjectile (const base_t* attackingBase, const installation_t* attackingInstallation, aircraft_t *attacker, aircraft_t *target, aircraftSlot_t *weaponSlot)
{
	aircraftProjectile_t *projectile;

	if (ccs.numProjectiles >= MAX_PROJECTILESONGEOSCAPE) {
		Com_DPrintf(DEBUG_CLIENT, "Too many projectiles on map\n");
		return qfalse;
	}

	projectile = &ccs.projectiles[ccs.numProjectiles];

	if (!weaponSlot->ammo) {
		Com_Printf("AIRFIGHT_AddProjectile: Error - no ammo assigned\n");
		return qfalse;
	}

	assert(weaponSlot->item);

	projectile->aircraftItem = weaponSlot->ammo;
	if (attackingBase) {
		projectile->attackingAircraft = NULL;
		VectorSet(projectile->pos[0], attackingBase->pos[0], attackingBase->pos[1], 0);
		VectorSet(projectile->attackerPos, attackingBase->pos[0], attackingBase->pos[1], 0);
	} else if (attackingInstallation) {
		projectile->attackingAircraft = NULL;
		VectorSet(projectile->pos[0], attackingInstallation->pos[0], attackingInstallation->pos[1], 0);
		VectorSet(projectile->attackerPos, attackingInstallation->pos[0], attackingInstallation->pos[1], 0);
	} else {
		assert(attacker);
		projectile->attackingAircraft = attacker;
		VectorSet(projectile->pos[0], attacker->pos[0], attacker->pos[1], 0);
		/* attacker may move, use attackingAircraft->pos */
		VectorSet(projectile->attackerPos, 0, 0, 0);
	}

	projectile->numProjectiles++;

	assert(target);
	projectile->aimedAircraft = target;
	VectorSet(projectile->idleTarget, 0, 0, 0);

	projectile->time = 0;
	projectile->angle = 0.0f;

	projectile->bullets = (weaponSlot->item->craftitem.bullets) ? qtrue : qfalse;
	projectile->beam = (weaponSlot->item->craftitem.beam) ? qtrue : qfalse;

	weaponSlot->ammoLeft--;
	if (weaponSlot->ammoLeft <= 0)
		AII_ReloadWeapon(weaponSlot);

	ccs.numProjectiles++;

	const char *sound;
	if (projectile->bullets) {
		sound = "geoscape/combat-gun";
	} else if (projectile->beam) {
		sound = "geoscape/combat-airlaser";
	} else {
		sound = "geoscape/combat-rocket";
	}

	if (sound != NULL)
		S_StartLocalSample(sound, 1.0f);

	return qtrue;
}
Exemplo n.º 9
0
/**
 * @brief Plays a ui sound
 * @param soundFile Sound file relative to sound/gui
 */
void UI_PlaySound (const char* soundFile)
{
	if (ui_sounds->integer)
		S_StartLocalSample(va("ui/%s", soundFile), SND_VOLUME_DEFAULT);
}
Exemplo n.º 10
0
/*
 * @brief
 */
void Cl_ParseServerMessage(void) {
	int32_t cmd, old_cmd;
	char *s;
	int32_t i;

	if (cl_show_net_messages->integer == 1)
		Com_Print("%u ", (uint32_t) net_message.size);
	else if (cl_show_net_messages->integer >= 2)
		Com_Print("------------------\n");

	cl.byte_counter += net_message.size;
	cmd = 0;

	// parse the message
	while (true) {
		if (net_message.read > net_message.size) {
			Com_Error(ERR_DROP, "Bad server message\n");
		}

		old_cmd = cmd;
		cmd = Net_ReadByte(&net_message);

		if (cmd == -1) {
			Cl_ShowNet("END OF MESSAGE");
			break;
		}

		if (cl_show_net_messages->integer >= 2 && sv_cmd_names[cmd])
			Cl_ShowNet(sv_cmd_names[cmd]);

		switch (cmd) {

			case SV_CMD_BASELINE:
				Cl_ParseBaseline();
				break;

			case SV_CMD_CBUF_TEXT:
				s = Net_ReadString(&net_message);
				Cbuf_AddText(s);
				break;

			case SV_CMD_CONFIG_STRING:
				Cl_ParseConfigString();
				break;

			case SV_CMD_DISCONNECT:
				Com_Error(ERR_DROP, "Server disconnected\n");
				break;

			case SV_CMD_DOWNLOAD:
				Cl_ParseDownload();
				break;

			case SV_CMD_FRAME:
				Cl_ParseFrame();
				break;

			case SV_CMD_PRINT:
				i = Net_ReadByte(&net_message);
				s = Net_ReadString(&net_message);
				if (i == PRINT_CHAT) {
					if (Cl_IgnoreChatMessage(s)) // filter /ignore'd chatters
						break;
					if (*cl_chat_sound->string) // trigger chat sound
						S_StartLocalSample(cl_chat_sound->string);
				} else if (i == PRINT_TEAMCHAT) {
					if (Cl_IgnoreChatMessage(s)) // filter /ignore'd chatters
						break;
					if (*cl_team_chat_sound->string) // trigger chat sound
						S_StartLocalSample(cl_team_chat_sound->string);
				}
				Com_Print("%s", s);
				break;

			case SV_CMD_RECONNECT:
				Com_Print("Server disconnected, reconnecting...\n");
				// stop download
				if (cls.download.file) {
					if (cls.download.http) // clean up http downloads
						Cl_HttpDownload_Complete();
					else
						// or just stop legacy ones
						Fs_Close(cls.download.file);
					cls.download.name[0] = '\0';
					cls.download.file = NULL;
				}
				cls.state = CL_CONNECTING;
				cls.connect_time = 0; // fire immediately
				break;

			case SV_CMD_SERVER_DATA:
				Cl_ParseServerData();
				break;

			case SV_CMD_SOUND:
				Cl_ParseSound();
				break;

			default:
				// delegate to the client game module before failing
				if (!cls.cgame->ParseMessage(cmd)) {
					Com_Error(ERR_DROP, "Illegible server message:\n"
							" %d: last command was %s\n", cmd, sv_cmd_names[old_cmd]);
				}
				break;
		}
	}

	Cl_AddNetGraph();

	Cl_WriteDemoMessage();
}