Exemplo n.º 1
0
/**
 * @brief Triggers a campaign event with a special type
 * @param[in] type the event type
 * @param[in] userdata Any userdata that is passed to the bep checker function
 */
void CP_TriggerEvent (campaignTriggerEventType_t type, const void* userdata)
{
	int i;

	for (i = 0; i < ccs.numCampaignTriggerEvents; i++) {
		campaignTriggerEvent_t *event = &ccs.campaignTriggerEvents[i];
		if (event->type != type || (!event->active && event->reactivate == NULL))
			continue;

		if (event->active) {
			if (BEP_Evaluate(event->require, CP_CheckTriggerEvent, userdata)) {
				if (Q_strvalid(event->command)) {
					CP_CampaignTriggerFunctions(true);
					cgi->Cbuf_AddText(event->command);
					cgi->Cbuf_Execute();
					CP_CampaignTriggerFunctions(false);
				}

				if (event->once) {
					event->active = false;
				}
			}
		} else {
			event->active = BEP_Evaluate(event->reactivate, CP_CheckTriggerEvent, userdata);
		}
	}
}
Exemplo n.º 2
0
/**
 * @brief Executes console commands after a mission
 *
 * @param[in] mission Pointer to the mission to execute the triggers for
 * @param[in] won Int value that is one when you've won the game, and zero when the game was lost
 * Can execute console commands (triggers) on win and lose
 * This can be used for story dependent missions
 */
void CP_ExecuteMissionTrigger (const mission_t* mission, bool won)
{
	Com_DPrintf(DEBUG_CLIENT, "Execute mission triggers\n");

	if (mission == nullptr)
		return;

	/* we add them only here - and remove them afterwards to prevent cheating */
	CP_CampaignTriggerFunctions(true);

	if (won) {
		if (Q_strvalid(mission->onwin)) {
			Com_DPrintf(DEBUG_CLIENT, "...won - executing '%s'\n", mission->onwin);
			cgi->Cmd_ExecuteString("%s", mission->onwin);
		}
		if (mission->mapDef && Q_strvalid(mission->mapDef->onwin)) {
			Com_DPrintf(DEBUG_CLIENT, "...won - executing '%s'\n", mission->mapDef->onwin);
			cgi->Cmd_ExecuteString("%s", mission->mapDef->onwin);
		}
	} else {
		if (Q_strvalid(mission->onlose)) {
			Com_DPrintf(DEBUG_CLIENT, "...lost - executing '%s'\n", mission->onlose);
			cgi->Cmd_ExecuteString("%s", mission->onlose);
		}
		if (mission->mapDef && Q_strvalid(mission->mapDef->onlose)) {
			Com_DPrintf(DEBUG_CLIENT, "...lost - executing '%s'\n", mission->mapDef->onlose);
			cgi->Cmd_ExecuteString("%s", mission->mapDef->onlose);
		}
	}

	CP_CampaignTriggerFunctions(false);
}