/**
 * @brief Creates console command to change the name of an aircraft.
 * Copies the value of the cvar mn_aircraftname over as the name of the
 * current selected aircraft
 * @note empty name will reset aircraft's name to the default
 * @note renaming to name with only non printable characters (eg. space) is denied
 * @todo make it not using cvar and default aircraft but get them from parameterlist
 */
static void AIR_ChangeAircraftName_f (void)
{
	const base_t* base = B_GetCurrentSelectedBase();
	if (!base)
		return;

	aircraft_t* aircraft = base->aircraftCurrent;
	if (!aircraft)
		return;

	/* set default name on empty new name*/
	const char* newName = cgi->Cvar_GetString("mn_aircraftname");
	if (Q_strnull(newName)) {
		Q_strncpyz(aircraft->name, _(aircraft->defaultName), sizeof(aircraft->name));
		return;
	}

	/* refuse to set name contains only non-printable characters */
	int i;
	for (i = 0; newName[i] != '\0'; i++) {
		if (newName[i] > 0x20)
			break;
	}
	if (newName[i] == '\0')
		return;

	/* aircraft name should not contain " */
	if (!Com_IsValidName(newName))
		return;

	Q_strncpyz(aircraft->name, newName, sizeof(aircraft->name));
}
/**
 * @brief Change the name of the selected actor.
 * @note called via "employee_changename"
 */
static void E_ChangeName_f (void)
{
	Employee* employee = E_GetEmployeeFromChrUCN(cgi->Cvar_GetInteger("mn_ucn"));
	if (!employee)
		return;

	/* employee name should not contain " */
	if (!Com_IsValidName(cgi->Cvar_GetString("mn_name"))) {
		cgi->Cvar_ForceSet("mn_name", employee->chr.name);
		return;
	}

	Q_strncpyz(employee->chr.name, cgi->Cvar_GetString("mn_name"), sizeof(employee->chr.name));
}
Esempio n. 3
0
/**
 * @brief Creates console command to change the name of a base.
 * Copies the value of the cvar mn_base_title over as the name of the
 * current selected base
 */
static void B_ChangeBaseName_f (void)
{
	base_t* base = B_GetCurrentSelectedBase();

	/* maybe called without base initialized or active */
	if (!base)
		return;

	/* basename should not contain " */
	if (!Com_IsValidName(cgi->Cvar_GetString("mn_base_title"))) {
		cgi->Cvar_Set("mn_base_title", "%s", base->name);
		return;
	}

	Q_strncpyz(base->name, cgi->Cvar_GetString("mn_base_title"), sizeof(base->name));
}
Esempio n. 4
0
/**
 * @brief Constructs a new base.
 * @sa B_NewBase
 */
static void B_BuildBase_f (void)
{
	const campaign_t* campaign = ccs.curCampaign;

	if (ccs.mapAction == MA_NEWBASE)
		ccs.mapAction = MA_NONE;

	if (ccs.credits - campaign->basecost > 0) {
		const nation_t* nation;
		const char* baseName = mn_base_title->string;
		base_t* base;
		/* there may be no " in the base name */
		if (!Com_IsValidName(baseName))
			baseName = _("Base");

		base = B_Build(campaign, ccs.newBasePos, baseName);
		if (!base)
			cgi->Com_Error(ERR_DROP, "Cannot build base");

		CP_UpdateCredits(ccs.credits - campaign->basecost);
		nation = GEO_GetNation(base->pos);
		if (nation)
			Com_sprintf(cp_messageBuffer, sizeof(cp_messageBuffer), _("A new base has been built: %s (nation: %s)"), mn_base_title->string, _(nation->name));
		else
			Com_sprintf(cp_messageBuffer, sizeof(cp_messageBuffer), _("A new base has been built: %s"), mn_base_title->string);
		MS_AddNewMessage(_("Base built"), cp_messageBuffer, MSG_CONSTRUCTION);

		/* First base */
		if (ccs.campaignStats.basesBuilt == 1)
			B_SetUpFirstBase(campaign, base);

		cgi->Cvar_SetValue("mn_base_count", B_GetCount());
		B_SelectBase(base);
	} else {
		/** @todo Why is this needed? Also see bug #5401 */
		if (GEO_IsRadarOverlayActivated())
			GEO_SetOverlay("radar", 0);

		CP_PopupList(_("Notice"), _("Not enough credits to set up a new base."));
	}
}