示例#1
0
文件: ai.c 项目: NSYXin/cdogs-sdl
void CreateEnemies(void)
{
    if (gCampaign.Setting.characters.baddieIds.size == 0)
    {
        return;
    }

    for (int i = 0;
            i < MAX(1, (gMission.missionData->EnemyDensity * ConfigGetInt(&gConfig, "Game.EnemyDensity")) / 100);
            i++)
    {
        NActorAdd aa = NActorAdd_init_default;
        aa.UID = ActorsGetNextUID();
        aa.CharId = CharacterStoreGetRandomBaddieId(
                        &gCampaign.Setting.characters);
        aa.FullPos = PlaceAwayFromPlayers(&gMap);
        aa.Direction = rand() % DIRECTION_COUNT;
        const Character *c =
            CArrayGet(&gCampaign.Setting.characters.OtherChars, aa.CharId);
        aa.Health = CharacterGetStartingHealth(c, true);
        GameEvent e = GameEventNew(GAME_EVENT_ACTOR_ADD);
        e.u.ActorAdd = aa;
        GameEventsEnqueue(&gGameEvents, e);
        gBaddieCount++;

        // Process the events that actually place the actors
        HandleGameEvents(&gGameEvents, NULL, NULL, NULL);
    }
}
示例#2
0
bool RunGame(const CampaignOptions *co, struct MissionOptions *m, Map *map)
{
	// Clear the background
	DrawRectangle(
		&gGraphicsDevice, Vec2iZero(), gGraphicsDevice.cachedConfig.Res,
		colorBlack, 0);
	SDL_UpdateTexture(
		gGraphicsDevice.bkg, NULL, gGraphicsDevice.buf,
		gGraphicsDevice.cachedConfig.Res.x * sizeof(Uint32));

	MapLoad(map, m, co);

	// Seed random if PVP mode (otherwise players will always spawn in same
	// position)
	if (IsPVP(co->Entry.Mode))
	{
		srand((unsigned int)time(NULL));
	}

	if (!co->IsClient)
	{
		MapLoadDynamic(map, m, &co->Setting.characters);

		// For PVP modes, mark all map as explored
		if (IsPVP(co->Entry.Mode))
		{
			MapMarkAllAsVisited(map);
		}

		// Reset players for the mission
		CA_FOREACH(const PlayerData, p, gPlayerDatas)
			// Only reset for local players; for remote ones wait for the
			// client ready message
			if (!p->IsLocal) continue;
			GameEvent e = GameEventNew(GAME_EVENT_PLAYER_DATA);
			e.u.PlayerData = PlayerDataMissionReset(p);
			GameEventsEnqueue(&gGameEvents, e);
		CA_FOREACH_END()
		// Process the events to force add the players
		HandleGameEvents(&gGameEvents, NULL, NULL, NULL);

		// Note: place players first,
		// as bad guys are placed away from players
		Vec2i firstPos = Vec2iZero();
		CA_FOREACH(const PlayerData, p, gPlayerDatas)
			if (!p->Ready) continue;
			firstPos = PlacePlayer(&gMap, p, firstPos, true);
		CA_FOREACH_END()
		if (!IsPVP(co->Entry.Mode))
		{
			InitializeBadGuys();
			CreateEnemies();
		}
	}
示例#3
0
/***********************************************************
process function
***********************************************************/
void LbaNetEngine::Process(void)
{
    //handle game events
    HandleGameEvents();

    // process model (update display stuff)
    m_lbaNetModel.Process();

    // process GUI
    m_gui_handler.Process();

    //process sound
    MusicHandler::getInstance()->Update();
}
示例#4
0
bool NumPlayersSelection(GraphicsDevice *graphics, EventHandlers *handlers)
{
	MenuSystem ms;
	MenuSystemInit(
		&ms, handlers, graphics,
		Vec2iZero(),
		graphics->cachedConfig.Res);
	ms.allowAborts = true;
	ms.root = ms.current = MenuCreateNormal(
		"",
		"Select number of players",
		MENU_TYPE_NORMAL,
		0);
	MenuAddSubmenu(ms.current, MenuCreateReturn("(No local players)", 0));
	for (int i = 0; i < MAX_LOCAL_PLAYERS; i++)
	{
		char buf[2];
		sprintf(buf, "%d", i + 1);
		MenuAddSubmenu(ms.current, MenuCreateReturn(buf, i + 1));
	}
	MenuAddExitType(&ms, MENU_TYPE_RETURN);
	// Select 1 player default
	ms.current->u.normal.index = 1;

	MenuLoop(&ms);
	const bool ok = !ms.hasAbort;
	if (ok)
	{
		const int numPlayers = ms.current->u.returnCode;
		CA_FOREACH(const PlayerData, p, gPlayerDatas)
			CASSERT(!p->IsLocal, "unexpected local player");
		CA_FOREACH_END()
		// Add the players
		for (int i = 0; i < numPlayers; i++)
		{
			GameEvent e = GameEventNew(GAME_EVENT_PLAYER_DATA);
			e.u.PlayerData = PlayerDataDefault(i);
			e.u.PlayerData.UID = gNetClient.FirstPlayerUID + i;
			GameEventsEnqueue(&gGameEvents, e);
		}
		// Process the events to force add the players
		HandleGameEvents(&gGameEvents, NULL, NULL, NULL);
		// This also causes the client to send player data to the server
	}
	MenuSystemTerminate(&ms);
	return ok;
}
示例#5
0
Vec2i PlacePlayer(
	Map *map, const PlayerData *p, const Vec2i firstPos, const bool pumpEvents)
{
	NetMsgActorAdd aa = NetMsgActorAdd_init_default;
	aa.Id = ActorsGetFreeIndex();
	aa.Health = p->Char.maxHealth;
	aa.PlayerId = p->playerIndex;

	if (IsPVP(gCampaign.Entry.Mode))
	{
		// In a PVP mode, always place players apart
		aa.FullPos = PlaceActor(&gMap);
	}
	else if (gMission.missionData->Type == MAPTYPE_STATIC &&
		!Vec2iIsZero(gMission.missionData->u.Static.Start))
	{
		// place players near the start point
		Vec2i startPoint = Vec2iReal2Full(Vec2iCenterOfTile(
			gMission.missionData->u.Static.Start));
		aa.FullPos = PlaceActorNear(map, startPoint, true);
	}
	else if (gConfig.Interface.Splitscreen == SPLITSCREEN_NEVER &&
		!Vec2iIsZero(firstPos))
	{
		// If never split screen, try to place players near the first player
		aa.FullPos = PlaceActorNear(map, firstPos, true);
	}
	else
	{
		aa.FullPos = PlaceActor(map);
	}

	GameEvent e = GameEventNew(GAME_EVENT_ACTOR_ADD);
	e.u.ActorAdd = aa;
	GameEventsEnqueue(&gGameEvents, e);

	if (pumpEvents)
	{
		// Process the events that actually place the players
		HandleGameEvents(&gGameEvents, NULL, NULL, NULL, &gEventHandlers);
	}

	return Vec2iNew(aa.FullPos.x, aa.FullPos.y);
}
示例#6
0
void GrafxMakeBackground(
	GraphicsDevice *device, DrawBuffer *buffer,
	CampaignOptions *co, struct MissionOptions *mo, Map *map, HSV tint,
	const bool isEditor, struct vec2 pos, GrafxDrawExtra *extra)
{
	CampaignAndMissionSetup(co, mo);
	GameEventsInit(&gGameEvents);
	MapBuild(map, mo->missionData, co);
	InitializeBadGuys();
	CreateEnemies();
	MapMarkAllAsVisited(map);
	if (isEditor)
	{
		MapShowExitArea(map, map->ExitStart, map->ExitEnd);
	}
	else
	{
		pos = Vec2CenterOfTile(svec2i_scale_divide(map->Size, 2));
	}
	// Process the events that place dynamic objects
	HandleGameEvents(&gGameEvents, NULL, NULL, NULL);
	GrafxDrawBackground(device, buffer, tint, pos, extra);
	GameEventsTerminate(&gGameEvents);
}
示例#7
0
文件: ai.c 项目: NSYXin/cdogs-sdl
void InitializeBadGuys(void)
{
    for (int i = 0; i < (int)gMission.missionData->Objectives.size; i++)
    {
        MissionObjective *mobj =
            CArrayGet(&gMission.missionData->Objectives, i);
        ObjectiveDef *obj = CArrayGet(&gMission.Objectives, i);
        if (mobj->Type == OBJECTIVE_KILL &&
                gMission.missionData->SpecialChars.size > 0)
        {
            for (; obj->placed < mobj->Count; obj->placed++)
            {
                NActorAdd aa = NActorAdd_init_default;
                aa.UID = ActorsGetNextUID();
                aa.CharId = CharacterStoreGetRandomSpecialId(
                                &gCampaign.Setting.characters);
                aa.TileItemFlags = ObjectiveToTileItem(i);
                aa.Direction = rand() % DIRECTION_COUNT;
                const Character *c =
                    CArrayGet(&gCampaign.Setting.characters.OtherChars, aa.CharId);
                aa.Health = CharacterGetStartingHealth(c, true);
                aa.FullPos = PlaceAwayFromPlayers(&gMap);
                GameEvent e = GameEventNew(GAME_EVENT_ACTOR_ADD);
                e.u.ActorAdd = aa;
                GameEventsEnqueue(&gGameEvents, e);

                // Process the events that actually place the actors
                HandleGameEvents(&gGameEvents, NULL, NULL, NULL);
            }
        }
        else if (mobj->Type == OBJECTIVE_RESCUE)
        {
            for (; obj->placed < mobj->Count; obj->placed++)
            {
                NActorAdd aa = NActorAdd_init_default;
                aa.UID = ActorsGetNextUID();
                aa.CharId = CharacterStoreGetPrisonerId(
                                &gCampaign.Setting.characters, 0);
                aa.TileItemFlags = ObjectiveToTileItem(i);
                aa.Direction = rand() % DIRECTION_COUNT;
                const Character *c =
                    CArrayGet(&gCampaign.Setting.characters.OtherChars, aa.CharId);
                aa.Health = CharacterGetStartingHealth(c, true);
                if (MapHasLockedRooms(&gMap))
                {
                    aa.FullPos = PlacePrisoner(&gMap);
                }
                else
                {
                    aa.FullPos = PlaceAwayFromPlayers(&gMap);
                }
                GameEvent e = GameEventNew(GAME_EVENT_ACTOR_ADD);
                e.u.ActorAdd = aa;
                GameEventsEnqueue(&gGameEvents, e);

                // Process the events that actually place the actors
                HandleGameEvents(&gGameEvents, NULL, NULL, NULL);
            }
        }
    }

    gBaddieCount = gMission.index * 4;
    gAreGoodGuysPresent = 0;
}