static void MissionChangeObjectiveRequired(void *vData, int d)
{
	MissionIndexData *data = vData;
	Objective *o = GetMissionObjective(
		CampaignGetCurrentMission(data->co), data->index);
	o->Required = CLAMP_OPPOSITE(o->Required + d, 0, MIN(100, o->Count));
}
Esempio n. 2
0
static void AdjustYC(int *yc)
{
	Mission *mission = CampaignGetCurrentMission(&gCampaign);
	if (mission)
	{
		if (mission->Objectives.size)
		{
			*yc = CLAMP_OPPOSITE(
				*yc, 0, YC_OBJECTIVES + (int)mission->Objectives.size - 1);
		}
		else
		{
			*yc = CLAMP_OPPOSITE(*yc, 0, YC_OBJECTIVES);
		}
	}
	else
	{
		*yc = CLAMP_OPPOSITE(*yc, 0, YC_MISSIONINDEX);
	}
}
Esempio n. 3
0
void CameraInput(Camera *camera, const int cmd, const int lastCmd)
{
	// Control the camera
	if (camera->spectateMode == SPECTATE_NONE)
	{
		return;
	}
	// Arrows: pan camera
	// CMD1/2: choose next player to follow
	if (CMD_HAS_DIRECTION(cmd))
	{
		camera->spectateMode = SPECTATE_FREE;
		const int pan = PAN_SPEED;
		if (cmd & CMD_LEFT)	camera->lastPosition.x -= pan;
		else if (cmd & CMD_RIGHT)	camera->lastPosition.x += pan;
		if (cmd & CMD_UP)		camera->lastPosition.y -= pan;
		else if (cmd & CMD_DOWN)	camera->lastPosition.y += pan;
	}
	else if ((AnyButton(cmd) && !AnyButton(lastCmd)) ||
		camera->FollowNextPlayer)
	{
		// Can't follow if there are no players
		if (GetNumPlayers(PLAYER_ALIVE_OR_DYING, false, false) == 0)
		{
			return;
		}
		camera->spectateMode = SPECTATE_FOLLOW;
		// Find index of player
		int playerIndex = -1;
		CA_FOREACH(const PlayerData, p, gPlayerDatas)
			if (p->UID == camera->FollowPlayerUID)
			{
				playerIndex = _ca_index;
				break;
			}
		CA_FOREACH_END()
		// Get the next player by index that has an actor in the game
		const int d = (cmd & CMD_BUTTON1) ? 1 : -1;
		for (int i = playerIndex + d;; i += d)
		{
			i = CLAMP_OPPOSITE(i, 0, (int)gPlayerDatas.size - 1);
			// Check if clamping made us hit the termination condition
			if (i == playerIndex) break;
			const PlayerData *p = CArrayGet(&gPlayerDatas, i);
			if (IsPlayerAliveOrDying(p))
			{
				// Follow this player
				camera->FollowPlayerUID = p->UID;
				camera->FollowNextPlayer = false;
				break;
			}
		}
	}
}
Esempio n. 4
0
static void AdjustXC(int yc, int *xc)
{
	Mission *mission = CampaignGetCurrentMission(&gCampaign);
	switch (yc)
	{
	case YC_CAMPAIGNTITLE:
		*xc = CLAMP_OPPOSITE(*xc, 0, XC_CAMPAIGNDESC);
		break;

	case YC_MISSIONTITLE:
		*xc = CLAMP_OPPOSITE(*xc, 0, XC_MUSICFILE);
		break;

	case YC_MISSIONLOOKS:
		*xc = CLAMP_OPPOSITE(*xc, 0, XC_COLOR4);
		break;

	case YC_CHARACTERS:
		if (mission && mission->Enemies.size > 0)
		{
			*xc = CLAMP_OPPOSITE(*xc, 0, (int)mission->Enemies.size - 1);
		}
		break;

	case YC_SPECIALS:
		if (mission && mission->SpecialChars.size > 0)
		{
			*xc = CLAMP_OPPOSITE(*xc, 0, (int)mission->SpecialChars.size - 1);
		}
		break;

	case YC_ITEMS:
		if (mission && mission->Items.size > 0)
		{
			*xc = CLAMP_OPPOSITE(*xc, 0, (int)mission->Items.size - 1);
		}
		break;

	case YC_WEAPONS:
		*xc = CLAMP_OPPOSITE(*xc, 0, XC_MAXWEAPONS);
		break;

	default:
		if (yc >= YC_OBJECTIVES)
		{
			*xc = CLAMP_OPPOSITE(*xc, 0, XC_FLAGS);
		}
		break;
	}
}
Esempio n. 5
0
void InputSwitchJoystick(const int inc)
{
#ifdef __GCW0__
	JoystickIndex = CLAMP_OPPOSITE(JoystickIndex + inc, -1, 1);
	if (JoystickIndex == 1 && gSensor)
	{
		// Recalibrate G sensor
		gZero = (int16_t)SDL_JoystickGetAxis(gSensor, 0);
	}
#else
	UNUSED(inc);
#endif
}
static void BrushChangeType(EditorBrush *b, int d, int isMain)
{
	unsigned short brushType = isMain ? b->MainType : b->SecondaryType;
	brushType = (unsigned short)CLAMP_OPPOSITE(
		(int)brushType + d, MAP_FLOOR, MAP_NOTHING);
	if (isMain)
	{
		b->MainType = brushType;
	}
	else
	{
		b->SecondaryType = brushType;
	}
}
static void MissionChangeObjectiveTotal(void *vData, int d)
{
	MissionIndexData *data = vData;
	const Mission *m = CampaignGetCurrentMission(data->co);
	Objective *o = GetMissionObjective(m, data->index);
	o->Count = CLAMP_OPPOSITE(o->Count + d, o->Required, 100);
	// Don't let the total reduce to less than static ones we've placed
	if (m->Type == MAPTYPE_STATIC)
	{
		CA_FOREACH(const ObjectivePositions, op, m->u.Static.Objectives)
			if (op->Index == data->index)
			{
				o->Count = MAX(o->Count, (int)op->Positions.size);
				break;
			}
		CA_FOREACH_END()
	}
Esempio n. 8
0
int UIObjectChange(UIObject *o, int d)
{
	switch (o->Type)
	{
	case UITYPE_TAB:
		// switch child
		o->u.Tab.Index = CLAMP_OPPOSITE(
			o->u.Tab.Index + d, 0, (int)o->u.Tab.Labels.size - 1);
		break;
	default:
		// do nothing
		break;
	}
	if (o->ChangeFunc)
	{
		o->ChangeFunc(o->Data, d);
		DisableContextMenuParents(o);
		return o->ChangesData;
	}
	return 0;
}
Esempio n. 9
0
static int PlayerListInput(int cmd, void *data)
{
	// Input: up/down scrolls list
	// CMD 1/2: exit
	PlayerList *pl = data;

	// Note: players can leave due to network disconnection
	// Update our lists
	CA_FOREACH(const int, playerUID, pl->playerUIDs)
		const PlayerData *p = PlayerDataGetByUID(*playerUID);
		if (p == NULL)
		{
			CArrayDelete(&pl->playerUIDs, _ca_index);
			_ca_index--;
		}
	CA_FOREACH_END()

	if (cmd == CMD_DOWN)
	{
		SoundPlay(&gSoundDevice, StrSound("door"));
		pl->scroll++;
	}
	else if (cmd == CMD_UP)
	{
		SoundPlay(&gSoundDevice, StrSound("door"));
		pl->scroll--;
	}
	else if (AnyButton(cmd))
	{
		SoundPlay(&gSoundDevice, StrSound("pickup"));
		return 1;
	}
	// Scroll wrap-around
	pl->scroll = CLAMP_OPPOSITE(pl->scroll, 0, PlayerListMaxScroll(pl));
	return 0;
}