Exemplo n.º 1
0
void GameSessionClient::updateGameLogic(int elapsedTime)
{
    if(!localFaction) return;
    gameTimer += elapsedTime;

    //First purge units that have to be deleted
    for(auto fIter : getFactionMap())
    {
        Faction* faction = fIter.second;
        for(auto it = faction->getUnits().begin(); it != faction->getUnits().end(); )
        {
            if ((*it)->readyToDelete()) {
                delete *it;
                it = faction->getUnits().erase(it);
            } else {
                ++it;
            }
        }
    }

    //Update all units
    //mat4 vpMatrix = Arya::Locator::getRoot().getGraphics()->getCamera()->getVPMatrix();
    for(auto unitIter : getUnitMap())
    {
        Unit* unit = unitIter.second;
        //vec4 onScreen(unit->getEntity()->getPosition(), 1.0);
        //onScreen = vpMatrix * onScreen;
        //onScreen.x /= onScreen.w;
        //onScreen.y /= onScreen.w;
        //unit->setScreenPosition(vec2(onScreen.x, onScreen.y));
        unit->update(gameTimer);
    }
    for(auto unit : localFaction->getUnits())
        unit->checkForEnemies();
}
Exemplo n.º 2
0
void GameSessionInput::selectUnit()
{
    if(!leftShiftPressed)
        unselectAll();

    vec3 clickPos = Root::shared().getDepthResult();
    vec2 clickPos2(clickPos.x, clickPos.z);

    Faction* lf = session->getLocalFaction();
    if(!lf) return;

    Unit* best_unit = 0;
    float best_distance = 100.0;

    float dist;

    for(list<Unit*>::iterator it = lf->getUnits().begin();
            it != lf->getUnits().end(); ++it)
    {
        dist = glm::distance((*it)->getPosition2(), clickPos2);
        if(dist < 2.0 * (*it)->getInfo()->radius
                && dist < best_distance) {
            best_distance = dist; 
            best_unit = (*it);
        }
    }

    if(best_unit)
    {
        SoundManager::shared().play(best_unit->getInfo()->selectionSound);
        best_unit->setSelected(true);
		if(leftControlPressed) best_unit->getDebugText();
    }
}
Exemplo n.º 3
0
void GameSessionInput::selectUnits(float x_min, float x_max, float y_min, float y_max)
{
    if(!leftShiftPressed)
        unselectAll();

    Faction* lf = session->getLocalFaction();

    bool firstUnitSelected = false;
    if(!lf) return;
    for(list<Unit*>::iterator it = lf->getUnits().begin();
            it != lf->getUnits().end(); ++it)
    {
        vec2 onScreen = (*it)->getScreenPosition();

        if((onScreen.x > x_min && onScreen.x < x_max) && (onScreen.y > y_min && onScreen.y < y_max))
	   	{
            (*it)->setSelected(true);
            if(!firstUnitSelected) 
			{
				SoundManager::shared().play((*it)->getInfo()->selectionSound);
			}
            firstUnitSelected = true;
			if(leftControlPressed) (*it)->getDebugText();
        }
    }
}
Exemplo n.º 4
0
void FactionManager::awardFactionStanding(CreatureObject* player, const String& factionName) {
	if (player == NULL)
		return;

	ManagedReference<PlayerObject*> ghost = player->getPlayerObject();

	if (!factionMap.contains(factionName))
		return;

	float lose = floor((float)75); //TODO: Find the equation for this.
	float gain = floor((float)lose / 2); //you gain half of what you lose

	Faction faction = factionMap.get(factionName);
	SortedVector<String>* enemies = faction.getEnemies();
	SortedVector<String>* allies = faction.getAllies();

	ghost->decreaseFactionStanding(factionName, lose);

	//Lose faction standing to allies of the creature.
	for (int i = 0; i < allies->size(); ++i) {
		String ally = allies->get(i);
		ghost->decreaseFactionStanding(ally, lose);
	}

	//Gain faction standing to enemies of the creature.
	for (int i = 0; i < enemies->size(); ++i) {
		String enemy = enemies->get(i);
		ghost->increaseFactionStanding(enemy, gain);
	}
}
Exemplo n.º 5
0
void GameSessionInput::selectAll()
{
    Faction* lf = session->getLocalFaction();
    if(!lf) return;
    for(list<Unit*>::iterator it = lf->getUnits().begin();
            it != lf->getUnits().end(); ++it)
        (*it)->setSelected(true);
}
Exemplo n.º 6
0
		Unit(
			Id const& id,
			UnitType const& type,
			Faction const& faction
		):
			id(id),
			type(&type),
			control(faction.get_control()),
			space_left(type.get_space())
		{}
Exemplo n.º 7
0
// sector(x,y,x) + system index + body index = location in a (custom?) system of homeworld
static int l_fac_homeworld (lua_State *L)
{
	FactionBuilder *facbld = l_fac_check_builder(L, 1);
	Faction *fac = facbld->fac;
	Sint32 x = luaL_checkinteger(L, 2);
	Sint32 y = luaL_checkinteger(L, 3);
	Sint32 z = luaL_checkinteger(L, 4);
	Sint32 si = luaL_checkinteger(L, 5);
	Uint32 bi = luaL_checkinteger(L, 6);

	// search for home systems, first moving outward from the axes, then
	// if that didn't work moving inward toward them
	fac->hasHomeworld = true;
	fac->SetBestFitHomeworld(x, y, z, si, bi, +1);
	if (!fac->homeworld.HasValidSystem()) fac->SetBestFitHomeworld(x, y, z, si, bi, -1);

	facbld->skip      = !fac->homeworld.HasValidSystem();	// wasn't a valid system
	lua_settop(L, 1);
	return 1;
}
Exemplo n.º 8
0
void FormationTacticsApp::eventHandling ( const SDL_Event& event  ){
    //printf( "NBodyWorldApp::eventHandling() \n" );
    switch( event.type ){
        case SDL_KEYDOWN :
            switch( event.key.keysym.sym ){
                case SDLK_0:  formation_view_mode = 0;            printf( "view : default\n" ); break;
                case SDLK_1:  formation_view_mode = VIEW_INJURY;  printf( "view : injury\n"  ); break;
                case SDLK_2:  formation_view_mode = VIEW_STAMINA; printf( "view : stamina\n" ); break;
                case SDLK_3:  formation_view_mode = VIEW_CHARGE;  printf( "view : charge\n"  ); break;
                case SDLK_4:  formation_view_mode = VIEW_MORAL;   printf( "view : moral\n"   ); break;
            }
            break;
        case SDL_MOUSEBUTTONDOWN:
            switch( event.button.button ){
                case SDL_BUTTON_LEFT:
                    //printf( "left button pressed !!!! " );
                    if( currentFaction != NULL ) currentFormation = currentFaction->getFormationAt( { mouse_begin_x, mouse_begin_y } );
                break;
                case SDL_BUTTON_RIGHT:
                    //printf( "left button pressed !!!! " );
                    if( currentFormation != NULL ) currentFormation->setTarget( { mouse_begin_x, mouse_begin_y } );
                break;
            }
            break;
            /*
        case SDL_MOUSEBUTTONUP:
            switch( event.button.button ){
                case SDL_BUTTON_LEFT:
                    //printf( "left button pressed !!!! " );
                    world.picked = NULL;
                    break;
            }
            break;
            */
    };
    AppSDL2OGL::eventHandling( event );
    camStep = zoom*0.05;
}
Exemplo n.º 9
0
void GameSessionInput::moveSelectedUnits()
{
    vec3 clickPos = Root::shared().getDepthResult();
    vec2 clickPos2(clickPos.x, clickPos.z);

    Faction* lf = session->getLocalFaction();
    if(!lf) return;

    // did we click on an enemy unit
    Unit* best_unit = 0;
    float best_distance = 100.0;
    //Faction* from_faction = 0;

    float dist;
    for(unsigned int j = 0; j < session->getFactions().size(); ++j) {
        if(session->getFactions()[j] == lf) continue;

        for(list<Unit*>::iterator it = session->getFactions()[j]->getUnits().begin();
                it != session->getFactions()[j]->getUnits().end(); ++it)
        {
            dist = glm::distance((*it)->getPosition2(), clickPos2);
            if(dist < (*it)->getInfo()->radius && dist < best_distance)
            {
                best_distance = dist; 
                best_unit = (*it);
            }
        }
    }

    vec2 centerPos(0,0); //average position of selected units
    vector<int> unitIds;
    vector<vec2> unitPositions;
    for(list<Unit*>::iterator it = lf->getUnits().begin(); it != lf->getUnits().end(); ++it)
        if((*it)->isSelected())
        {
            centerPos += (*it)->getPosition2();
            unitPositions.push_back((*it)->getPosition2());
            unitIds.push_back((*it)->getId());
        }

    int numSelected = unitIds.size();

    if(!numSelected) return;

    centerPos /= (float)numSelected;

    //FOR NOW: we only use pathfinding for normal walking, not for attacking
	if(best_unit)
	{
		Event& ev = Game::shared().getEventManager()->createEvent(EVENT_ATTACK_MOVE_UNIT_REQUEST);
		ev << numSelected;
		for(unsigned int i = 0; i < unitIds.size(); ++i)
			ev << unitIds[i] << best_unit->getId();

		ev.send();
	}
    else
    {
        //Movement from centerPos to clickPos
        vec2 target(clickPos.x, clickPos.z);

        //Find a path
        std::vector<vec2> pathNodes;
        //session->findPath(centerPos,target,pathNodes);
        if(pathNodes.empty()) pathNodes.push_back(target);

        //Now calculate the position of each unit relative to each other
        vector<vec2> relativePositions(unitIds.size());

        vec2 direction = glm::normalize(target - centerPos);
		vec2 perpendicular(-direction.y, direction.x); //right hand rule

		float spread = 20.0f;
		int perRow = (int)(glm::sqrt((float)numSelected) + 0.99);

		direction *= spread;
		perpendicular *= spread;

        vector<bool> unitTaken(unitIds.size(),false);
		for(int i = 0; i < numSelected; ++i)
		{
			//This loops over the target spots in such a way that it first loops the points that are furthest away.
			//When the units are coming from the BOTTOM the order is like this:
			//1 2 3
			//4 5 6
			//7 8 9
			vec2 targetSpot = target + float(perRow/2 - i/perRow)*direction + float(i%perRow - perRow/2)*perpendicular;
			//Select closest unit
			int bestIndex = -1;
			float bestDistance = 0;
			for(int j = 0; j < numSelected; ++j)
			{
                if(unitTaken[j]) continue;
				float dist = glm::distance(unitPositions[j],targetSpot);
				if(bestIndex == -1 || dist < bestDistance)
				{
					bestIndex = j;
					bestDistance = dist;
				}
			}
            relativePositions[bestIndex] = targetSpot - target;
            unitTaken[bestIndex] = true;
		}

        //Relative positions to center have been calculated. Now send the packet
        Event& ev = Game::shared().getEventManager()->createEvent(EVENT_MOVE_UNIT_REQUEST);
        ev << numSelected;
        for(int i = 0; i < numSelected; ++i)
        {
            ev << unitIds[i];
            ev << (int)pathNodes.size();
            for(unsigned int j = 0; j < pathNodes.size(); ++j)
            {
                ev << pathNodes[j] + relativePositions[i];
            }
        }
		ev.send();
	}
}
Exemplo n.º 10
0
bool GameSession::init()
{
    Game::shared().getEventManager()->addEventHandler(EVENT_GAME_FULLSTATE, this);

    input = new GameSessionInput(this);
    input->init();

    if(!initShaders()) return false;
    if(!initVertices()) return false;

    Root::shared().addInputListener(input);
    Root::shared().addFrameListener(input);
    Root::shared().addFrameListener(this);

    // init factions
    localFaction = new Faction;
    localFaction->setColor(0);
    factions.push_back(localFaction);

    Faction* otherFaction = new Faction;
    otherFaction->setColor(1);
    factions.push_back(otherFaction);

    Scene* scene = Root::shared().makeDefaultScene();
    if(!scene)
        return false;

    Camera* cam = scene->getCamera();

    cam->setPosition(vec3(0.0f, 150.0f, 0.0f));
    cam->setCameraAngle(0.0f, -60.0f);
    cam->setZoom(300.0f);

    Object* obj;

    // init map
    vector<Arya::Material*> tileSet;
    tileSet.push_back(Arya::MaterialManager::shared().getMaterial("grass.tga"));
    tileSet.push_back(Arya::MaterialManager::shared().getMaterial("rock.tga"));
    tileSet.push_back(Arya::MaterialManager::shared().getMaterial("snow.tga"));
    tileSet.push_back(Arya::MaterialManager::shared().getMaterial("dirt.tga"));
	vector<Arya::Texture*> skyset;
	skyset.push_back(Arya::TextureManager::shared().getTexture("transparentClouds.png"));
	skyset.push_back(Arya::TextureManager::shared().getTexture("stars.jpg"));
    if(!scene->setMap("heightmap.raw", "watermap.raw", tileSet, skyset, Arya::TextureManager::shared().getTexture("splatmap.tga")))
        return false;

    for(int i = 0; i < 30; ++ i) 
    {
        Unit* unit = new Unit(0);
        float heightModel = Root::shared().getScene()->getMap()->getTerrain()->heightAtGroundPosition(20.0f * (i / 10), -50.0f+20.0f*(i % 10));
        obj = scene->createObject();
        obj->setModel(ModelManager::shared().getModel("ogros.aryamodel"));
        obj->setAnimation("stand");
        unit->setObject(obj);
        unit->setPosition(vec3(20 * (i / 10), heightModel, -50 + 20 * (i % 10)));

        localFaction->addUnit(unit);
    }

    for(int i = 0; i < 30; ++ i) 
    {
        Unit* unit = new Unit(0);
        float heightModel = Root::shared().getScene()->getMap()->getTerrain()->heightAtGroundPosition(-100.0f + 20.0f * (i / 10), -100.0f+20.0f*(i % 10));
        obj = scene->createObject();
        obj->setModel(ModelManager::shared().getModel("ogros.aryamodel"));
        obj->setAnimation("stand");
        unit->setObject(obj);
        unit->setPosition(vec3(-100.0 + 20 * (i / 10), heightModel, -100.0 + 20 * (i % 10)));

        otherFaction->addUnit(unit);
    }

    for(int i = 0; i < 10; ++ i) 
    {
        Unit* unit = new Unit(1);
        float heightModel = Root::shared().getScene()->getMap()->getTerrain()->heightAtGroundPosition(-200.0f + 20.0f * (i / 10), -50.0f+20.0f*(i % 10));
        obj = scene->createObject();
        obj->setModel(ModelManager::shared().getModel("hep.aryamodel"));
        obj->setAnimation("stand");
        unit->setObject(obj);
        unit->setPosition(vec3(-200.0f + 20 * (i / 10), heightModel, -50 + 20 * (i % 10)));

        localFaction->addUnit(unit);
    }

    selectionDecalHandle = 0;
    Texture* selectionTex = TextureManager::shared().getTexture("selection.png");
    if(selectionTex) selectionDecalHandle = selectionTex->handle;

    return true;
}
Exemplo n.º 11
0
void Server::handlePacket(ServerClientHandler* clienthandler, Packet& packet)
{
    clientIterator iter = clientList.find(clienthandler);
    if(iter == clientList.end())
    {
        LOG_WARNING("Received packet from unkown client!");
        return;
    }
    ServerClient* client = iter->second;

    switch(packet.getId()){
        case EVENT_JOIN_GAME:
            {
                client->setClientId(clientIdFactory++); Packet* pak = createPacket(EVENT_CLIENT_ID); *pak << client->getClientId(); clienthandler->sendPacket(pak); 
                //Create faction 
                client->createFaction();
                client->createStartUnits();

                int joinedCount = 0;
                for(clientIterator iter = clientList.begin(); iter != clientList.end(); ++iter)
                {
                    if( iter->second->getClientId() != -1 ) ++joinedCount;
                }

                LOG_INFO("Clients joined: " << joinedCount);
                if(joinedCount >= 1)
                {
                    pak = createPacket(EVENT_GAME_READY);
                    //Send to all clients
                    sendToAllClients(pak);

                    pak = createPacket(EVENT_GAME_FULLSTATE);

                    //------------------------------------
                    // Package structure:
                    // + joinedCount
                    //   - clientID
                    //   - Serialized faction
                    //      + UnitCount
                    //      - Serialized unit 
                    //------------------------------------

                    *pak << joinedCount; //player count

                    //for each player:
                    for(clientIterator iter = clientList.begin(); iter != clientList.end(); ++iter)
                    {
                        if(iter->second->getClientId() == -1) continue;

                        *pak << iter->second->getClientId();

                        Faction* faction = iter->second->getFaction();
                        faction->serialize(*pak);

                        int unitCount = (int)faction->getUnits().size();

                        *pak << unitCount;
                        for(std::list<Unit*>::iterator iter = faction->getUnits().begin(); iter != faction->getUnits().end(); ++iter)
                            (*iter)->serialize(*pak);
                    }

                    sendToAllClients(pak);
                }
                break;
            }

        default:
            LOG_INFO("Unknown package received..");
            break;
    }

    return;
}
Exemplo n.º 12
0
void GameManager :: Init(bool setCreativeModeOn)
{
	isCreativeModeOn = setCreativeModeOn;
    time = 800;
	PPlanner->Init();
    InstanceMgr->Init();
    MapMgr->LoadInitialChunks();
    FactionMgr->Init();

    CharacterInstance* character;
    Faction* faction;

    faction = FactionMgr->CreateFaction(FACTION_TYPE_PLAYER_CONTROL);

	// Create Soldier:
    character = InstanceMgr->CreateCharacterInstanceSoldier(CHARACTER_INSTANCE_TEMPLATE_SOLDIER, vector3df(160,22,65));
    character->SetFactionID(FACTION_ID_PLAYER);
    character->SetBrain(new BrainSoldier(character));
    character->AddToInventory(ItemMgr->CreateItem(ITEM_SHOTGUN), 1);
    character->AddToInventory(ItemMgr->CreateItem(ITEM_SHOTGUN_SHELL), 30);
    character->AddToInventory(ItemMgr->CreateItem(ITEM_MACHINE_GUN), 1);
    character->AddToInventory(ItemMgr->CreateItem(ITEM_762_BULLET), 100);
	character->AddToInventory(ItemMgr->CreateItem(ITEM_SCRAP_PICK), 1);
	character->AddToInventory(ItemMgr->CreateItem(ITEM_MEDICAL_KIT), 1);
	character->AddToInventory(ItemMgr->CreateItem(ITEM_TIRE_ARMOUR_CHEST), 1);
	faction->AddSoldier((CharacterInstanceSoldier*)character);

	// Create Worker:
	character = InstanceMgr->CreateCharacterInstanceWorker(vector3df(160,22,67));
    character->SetFactionID(FACTION_ID_PLAYER);
    character->SetBrain(new BrainWorker(character));
	faction->AddWorker((CharacterInstanceWorker*)character);

	// Make a Hostile:
	character = InstanceMgr->CreateCharacterInstanceSoldier(CHARACTER_INSTANCE_TEMPLATE_ZOMBIE, vector3df(180,22,65));
	character->SetFactionID(FACTION_ID_ZOMBIE);
	character->SetBrain(new BrainNonFactionHostile((CharacterInstanceSoldier*)character));
	character->AddToInventory(ItemMgr->CreateItem(ITEM_PISTOL), 1);
	character->AddToInventory(ItemMgr->CreateItem(ITEM_9_MM_BULLET), 100);
	character->AddToInventory(ItemMgr->CreateItem(ITEM_SCRAP_PICK), 1);

/*
	// Make a Cow:
	character = InstanceMgr->CreateCharacterInstanceSoldier(CHARACTER_INSTANCE_TEMPLATE_COW, vector3df(150,22,65));
	character->SetFactionID(FACTION_ID_COW);
	character->SetBrain(new AnimalBrain(character));

	// Make a Cow:
	character = InstanceMgr->CreateCharacterInstanceSoldier(CHARACTER_INSTANCE_TEMPLATE_COW, vector3df(155,22,65));
	character->SetFactionID(FACTION_ID_COW);
	character->SetBrain(new AnimalBrain(character));

	// Make a Cow:
	character = InstanceMgr->CreateCharacterInstanceSoldier(CHARACTER_INSTANCE_TEMPLATE_COW, vector3df(155,22,60));
	character->SetFactionID(FACTION_ID_COW);
	character->SetBrain(new AnimalBrain(character));


	character = InstanceMgr->CreateCharacterInstanceSoldier(CHARACTER_INSTANCE_TEMPLATE_ZOMBIE, vector3df(180,22,70));
	character->SetFactionID(FACTION_ID_ZOMBIE);
	character->SetBrain(new ZombieBrain(character));

	character = InstanceMgr->CreateCharacterInstanceSoldier(CHARACTER_INSTANCE_TEMPLATE_ZOMBIE, vector3df(180,22,60));
	character->SetFactionID(FACTION_ID_ZOMBIE);
	character->SetBrain(new ZombieBrain(character));
*/

/*
	// Recipe
	for(int i = 0; i < MAX_RECIPES; i++)
		recipeData[i].resultID = -1;

	// Split wood block to planks:
	recipeData[0].itemIDs.push_back(ITEM_WOOD_BLOCK);
	recipeData[0].itemAmounts.push_back(1);
	recipeData[0].toolIDs.push_back(ITEM_SCRAP_SAW);
	recipeData[0].resultID = ITEM_WOOD_PLANK;
	recipeData[0].resultAmount = 4;

	// Split planks to sticks:
	recipeData[1].itemIDs.push_back(ITEM_WOOD_PLANK);
	recipeData[1].itemAmounts.push_back(1);
	recipeData[1].toolIDs.push_back(ITEM_SCRAP_SAW);
	recipeData[1].resultID = ITEM_WOOD_STICK;
	recipeData[1].resultAmount = 4;

	// Split tires into rubber:
	recipeData[2].itemIDs.push_back(ITEM_TIRE);
	recipeData[2].itemAmounts.push_back(1);
	recipeData[2].toolIDs.push_back(ITEM_SCRAP_SAW);
	recipeData[2].resultID = ITEM_RUBBER;
	recipeData[2].resultAmount = 4;

	// Craft Scrap Shovel:
	recipeData[3].itemIDs.push_back(ITEM_WOOD_STICK);
	recipeData[3].itemAmounts.push_back(4);
	recipeData[3].itemIDs.push_back(ITEM_SCRAP_METAL);
	recipeData[3].itemAmounts.push_back(4);
	recipeData[3].resultID = ITEM_SCRAP_SHOVEL;
	recipeData[3].resultAmount = 1;

	// Craft Scrap Pick:
	recipeData[4].itemIDs.push_back(ITEM_WOOD_STICK);
	recipeData[4].itemAmounts.push_back(4);
	recipeData[4].itemIDs.push_back(ITEM_SCRAP_METAL);
	recipeData[4].itemAmounts.push_back(4);
	recipeData[4].resultID = ITEM_SCRAP_PICK;
	recipeData[4].resultAmount = 1;

	// Craft Scrap Metal Cutters:
	recipeData[5].itemIDs.push_back(ITEM_WOOD_STICK);
	recipeData[5].itemAmounts.push_back(4);
	recipeData[5].itemIDs.push_back(ITEM_SCRAP_METAL);
	recipeData[5].itemAmounts.push_back(4);
	recipeData[5].resultID = ITEM_SCRAP_METAL_CUTTERS;
	recipeData[5].resultAmount = 1;

	// Craft Scrap File:
	recipeData[6].itemIDs.push_back(ITEM_WOOD_STICK);
	recipeData[6].itemAmounts.push_back(4);
	recipeData[6].itemIDs.push_back(ITEM_SCRAP_METAL);
	recipeData[6].itemAmounts.push_back(4);
	recipeData[6].resultID = ITEM_SCRAP_FILE;
	recipeData[6].resultAmount = 1;

	// Craft Scrap Saw:
	recipeData[7].itemIDs.push_back(ITEM_WOOD_STICK);
	recipeData[7].itemAmounts.push_back(4);
	recipeData[7].itemIDs.push_back(ITEM_SCRAP_METAL);
	recipeData[7].itemAmounts.push_back(4);
	recipeData[7].resultID = ITEM_SCRAP_SAW;
	recipeData[7].resultAmount = 1;

	// Craft Scrap Hammer:
	recipeData[8].itemIDs.push_back(ITEM_WOOD_STICK);
	recipeData[8].itemAmounts.push_back(4);
	recipeData[8].itemIDs.push_back(ITEM_SCRAP_METAL);
	recipeData[8].itemAmounts.push_back(4);
	recipeData[8].resultID = ITEM_SCRAP_HAMMER;
	recipeData[8].resultAmount = 1;

	// Split tire into rubber:
	recipeData[9].itemIDs.push_back(ITEM_TIRE);
	recipeData[9].itemAmounts.push_back(1);
	recipeData[9].toolIDs.push_back(ITEM_SCRAP_METAL_CUTTERS);
	recipeData[9].resultID = ITEM_RUBBER;
	recipeData[9].resultAmount = 4;

	// Tire Helm:
	recipeData[10].itemIDs.push_back(ITEM_RUBBER);
	recipeData[10].itemAmounts.push_back(4);
	recipeData[10].toolIDs.push_back(ITEM_SCRAP_METAL_CUTTERS);
	recipeData[10].resultID = ITEM_TIRE_ARMOUR_HEAD;
	recipeData[10].resultAmount = 1;

	// Tire Shirt:
	recipeData[11].itemIDs.push_back(ITEM_RUBBER);
	recipeData[11].itemAmounts.push_back(12);
	recipeData[11].toolIDs.push_back(ITEM_SCRAP_METAL_CUTTERS);
	recipeData[11].resultID = ITEM_TIRE_ARMOUR_CHEST;
	recipeData[11].resultAmount = 1;

	// Tire Legs:
	recipeData[12].itemIDs.push_back(ITEM_RUBBER);
	recipeData[12].itemAmounts.push_back(10);
	recipeData[12].toolIDs.push_back(ITEM_SCRAP_METAL_CUTTERS);
	recipeData[12].resultID = ITEM_TIRE_ARMOUR_LEG;
	recipeData[12].resultAmount = 1;

	// Tire Feet:
	recipeData[13].itemIDs.push_back(ITEM_RUBBER);
	recipeData[13].itemAmounts.push_back(4);
	recipeData[13].toolIDs.push_back(ITEM_SCRAP_METAL_CUTTERS);
	recipeData[13].resultID = ITEM_TIRE_ARMOUR_FEET;
	recipeData[13].resultAmount = 1;

	// Tire Shoulders:
	recipeData[14].itemIDs.push_back(ITEM_RUBBER);
	recipeData[14].itemAmounts.push_back(8);
	recipeData[14].toolIDs.push_back(ITEM_SCRAP_METAL_CUTTERS);
	recipeData[14].resultID = ITEM_TIRE_ARMOUR_SHOULDER;
	recipeData[14].resultAmount = 1;

	// Tire Back:
	recipeData[15].itemIDs.push_back(ITEM_RUBBER);
	recipeData[15].itemAmounts.push_back(8);
	recipeData[15].toolIDs.push_back(ITEM_SCRAP_METAL_CUTTERS);
	recipeData[15].resultID = ITEM_TIRE_ARMOUR_BACK;
	recipeData[15].resultAmount = 1;

	// Tire Arms:
	recipeData[16].itemIDs.push_back(ITEM_RUBBER);
	recipeData[16].itemAmounts.push_back(6);
	recipeData[16].toolIDs.push_back(ITEM_SCRAP_METAL_CUTTERS);
	recipeData[16].resultID = ITEM_TIRE_ARMOUR_ARM;
	recipeData[16].resultAmount = 1;

	// Tire Arms:
	recipeData[17].itemIDs.push_back(ITEM_RUBBER);
	recipeData[17].itemAmounts.push_back(4);
	recipeData[17].toolIDs.push_back(ITEM_SCRAP_METAL_CUTTERS);
	recipeData[17].resultID = ITEM_TIRE_ARMOUR_HAND;
	recipeData[17].resultAmount = 1;

	// Furnace:
	recipeData[18].itemIDs.push_back(ITEM_BARREL);
	recipeData[18].itemAmounts.push_back(1);
	recipeData[18].itemIDs.push_back(ITEM_SCRAP_METAL);
	recipeData[18].itemAmounts.push_back(4);
	recipeData[18].toolIDs.push_back(ITEM_SCRAP_METAL_CUTTERS);
	recipeData[18].resultID = ITEM_BARREL_FURNACE;
	recipeData[18].resultAmount = 1;
*/



}
Exemplo n.º 13
0
void ClientGameSession::handleEvent(Packet& packet)
{
	int id = packet.getId();
	switch(id)
	{
		case EVENT_GAME_FULLSTATE:
			{
                int newGameTime;
                packet >> newGameTime;

                GAME_LOG_DEBUG("Full game state received. Old gametimer = " << gameTimer << ". New server gametime = " << newGameTime << ". Estimated delay = " << Game::shared().getNetworkDelay());

                //Round the delay to 10 ms so that the game timer is always a multiple of 10 ms
                gameTimer = newGameTime + ((int)(Game::shared().getNetworkDelay()*1000)/10)*10;

				int count;
				packet >> count;
				for(int i = 0; i < count; ++i)
				{
					int clientId;
					packet >> clientId;

					int factionId;
					packet >> factionId;

					Faction* faction = getFactionById(factionId);
					if(!faction)
					{
						faction = createFaction(factionId);
						factions.push_back(faction);
					}

					faction->deserialize(packet);
					faction->setClientId(clientId);

					if(clientId == Game::shared().getClientId())
						localFaction = faction;

					//If any of the units that we have was NOT sent in this list they must be deleted
					//So we keep a list of IDs that we have and check which ones are in the packet
					//This method might be a bit slow but this process only happens in rare situations
					//so we do not bother adding extra member variables to the unit class to accomplish this
					vector<int> allIDs;
					for(list<Unit*>::iterator it = factions[i]->getUnits().begin(); it != factions[i]->getUnits().end(); ++it)
						allIDs.push_back((*it)->getId());

					int unitCount;
					packet >> unitCount;
					for(int i = 0; i < unitCount; ++i)
					{
						int id;
						packet >> id;

						for(vector<int>::iterator iter = allIDs.begin(); iter != allIDs.end(); ++iter)
							if( *iter == id ){ allIDs.erase(iter); break; }

						Unit* unit = getUnitById(id);
						bool newUnit = false;
						if(!unit)
						{
							newUnit = true;
							unit = createUnit(id, 0);
						}
						unit->deserialize(packet);

						if(faction == localFaction) unit->setLocal(true);

						Object* obj = unit->getObject();
						if(!obj) obj = Root::shared().getScene()->createObject();

						obj->setModel(ModelManager::shared().getModel(unit->getInfo()->modelname + ".aryamodel"));
						obj->setAnimation("stand");

						unit->setObject(obj);

						float heightModel = map->heightAtGroundPosition(unit->getPosition().x, unit->getPosition().z);

						unit->setPosition(vec3(unit->getPosition().x,
									heightModel,
									unit->getPosition().z));

						if(newUnit) faction->addUnit(unit);
						if(unit->getType() == 2 && faction == localFaction)
						{
							input->setSpecPos(unit->getPosition());
						}

						unit->getInfo()->onSpawn(unit);
					}

					//now allIDs contains a list of units that were not in the packet so they must be deleted
					//note that we can not just delete them because of reference counts and so on.
					//we make them obsolte so that they are deleted next frame
					for(vector<int>::iterator iter = allIDs.begin(); iter != allIDs.end(); ++iter)
					{
						Unit* unit = getUnitById(*iter); //if unit == 0 then there are some serious issues ;)
						if(unit) unit->markForDelete();
					}

				}
				rebuildCellList();
			}
			break;

		case EVENT_CLIENT_CONNECTED:
			{
				int clientId;
				packet >> clientId;

				int factionId;
				packet >> factionId;

				Faction* faction = createFaction(clientId);
				faction->deserialize(packet);
				faction->setClientId(clientId);
				factions.push_back(faction);

				if(clientId == Game::shared().getClientId())
					localFaction = faction;

				int unitCount;
				packet >> unitCount;
				for(int i = 0; i < unitCount; ++i)
				{
					int id;
					packet >> id;
					Unit* unit = createUnit(id, 0);
					unit->deserialize(packet);

					if(faction == localFaction) unit->setLocal(true);

					Object* obj = Root::shared().getScene()->createObject();
					obj->setModel(ModelManager::shared().getModel(unit->getInfo()->modelname + ".aryamodel"));
					obj->setAnimation("stand");

					unit->setObject(obj);

					float heightModel = map->heightAtGroundPosition(unit->getPosition().x, unit->getPosition().z);

					unit->setPosition(vec3(unit->getPosition().x,
								heightModel,
								unit->getPosition().z));

					faction->addUnit(unit);
				}
			}
			break;

		case EVENT_CLIENT_DISCONNECTED:
			{
				int id;
				packet >> id;
				GAME_LOG_INFO("Client " << id << " disconnected.");
				for(vector<Faction*>::iterator iter = factions.begin(); iter != factions.end(); ++iter)
				{
					if( (*iter)->getClientId() == id )
					{
						GAME_LOG_INFO("Client " << id << " removed from game session. NOT removing faction!");
						//delete *iter;
						//iter = factions.erase(iter);
						break;
					}
				}
			}
			break;

		case EVENT_MOVE_UNIT: {
                                  int timeStamp;
                                  packet >> timeStamp;

								  int numUnits;
								  packet >> numUnits;

                                  GAME_LOG_DEBUG("Move packet for " << numUnits << " units. " << (gameTimer - timeStamp) << " ms delay. Sent at server-gametime " << timeStamp << ". Recieved at client-gametime " << gameTimer);

								  int unitId;
                                  int nodeCount;
                                  vec2 pos;
                                  float yaw;
                                  vec2 tempPos;
                                  vector<vec2> pathNodes;
								  for(int i = 0; i < numUnits; ++i)
                                  {
									  packet >> unitId;
                                      packet >> pos;
                                      packet >> yaw;
                                      packet >> nodeCount;
                                      pathNodes.clear();
                                      for(int i = 0; i < nodeCount; ++i){ packet >> tempPos; pathNodes.push_back(tempPos); }
									  Unit* unit = getUnitById(unitId);
                                      if(unit) unit->setUnitMovement(timeStamp, pos, yaw, pathNodes);
								  }
								  break;
							  }

		case EVENT_ATTACK_MOVE_UNIT:
							  {
                                  int timeStamp;
                                  packet >> timeStamp;

								  int numUnits;
								  packet >> numUnits;

								  int unitId, targetUnitId;
								  for(int i = 0; i < numUnits; ++i) {
									  packet >> unitId >> targetUnitId;
									  Unit* unit = getUnitById(unitId);
									  Unit* targetUnit = getUnitById(targetUnitId);
									  if(unit && targetUnit) unit->setTargetUnit(timeStamp, targetUnit);
								  }

								  break;
							  }

		case EVENT_UNIT_DIED:
							  {
								  int id;
								  packet >> id;
								  Unit* unit = getUnitById(id);
								  if(unit)
								  {
									  unit->makeDead();
									  unit->getInfo()->onDeath(unit);
								  }
							  }
							  break;

		case EVENT_UNIT_SPAWNED:
							  {
								  int factionId, unitId;
								  packet >> factionId >> unitId;
								  Faction* faction = getFactionById(factionId);
								  if(!faction)
								  {
									  GAME_LOG_WARNING("Unit spawn packet received for invalid faction!");
								  }
								  else
								  {
									  Unit* unit = getUnitById(unitId);
									  bool newUnit = false;
									  if(unit)
										  GAME_LOG_WARNING("Spawn packet for unit that already existed");
									  else
									  {
										  newUnit = true;
										  unit = createUnit(unitId, 0);
									  }
									  unit->deserialize(packet);
									  if(faction == localFaction) unit->setLocal(true);
									  if(newUnit) unit->setCellFromList(unitCells);

									  Object* obj = unit->getObject();
									  if(!obj) obj = Root::shared().getScene()->createObject();
									  obj->setModel(ModelManager::shared().getModel(unit->getInfo()->modelname + ".aryamodel"));
									  obj->setAnimation("stand");
									  unit->setObject(obj);

									  float heightModel = map->heightAtGroundPosition(unit->getPosition().x, unit->getPosition().z);
									  unit->setPosition(vec3(unit->getPosition().x, heightModel, unit->getPosition().z));

									  //This must happen after the object is set, because
									  //then it will set the correct tint color
									  if(newUnit) faction->addUnit(unit);

									  unit->getInfo()->onSpawn(unit);
								  }
							  }
							  break;

		case EVENT_PLAYER_DEFEAT:
							  {
								  int factionID;
								  packet >> factionID;
								  LOG_INFO("Player lost: " << factionID + 1);
								  Arya::SoundManager::shared().play("defeat.wav");
							  }
							  break;

		case EVENT_PLAYER_VICTORY:
							  {
								  int factionID;
								  packet >> factionID;
								  LOG_INFO("Game won by player: " << factionID + 1);
								  Arya::SoundManager::shared().play("victory.wav");
							  }
							  break;

		default:
							  GAME_LOG_INFO("ClientGameSession: unknown event received! (" << id << ")");
							  break;
	}
}
Exemplo n.º 14
0
void Game::OnTurnEnd( Faction& faction )
{
	faction.OnTurnEnd();
	VOnTurnEnd( faction );
}
Exemplo n.º 15
0
void Game::OnTurnStart( Faction& faction )
{
	faction.OnTurnStart();
	VOnTurnStart( faction );
}
Exemplo n.º 16
0
void FactionMgr::addToFaction(SpaceObject *obj, std::string factionID) {
  Faction *f = flist->find(factionID);
  if (f)
    f->addMember(obj);
}
Exemplo n.º 17
0
Unit::Unit(Faction faction)
{
	unitColor = faction.getFactionColor();
}
Exemplo n.º 18
0
/*!
* \brief Ajout dans la liste des statistiques de faction et mise a jour des statistiques generales
* \param faction Faction a archiver dans les statisiques
*/
void World::add_stat_faction(Faction& faction) {
	stats_factions_.push_back(faction.stats());
	nb_attacks_failed_ += faction.get_nb_failed_attack_();
	nb_attacks_success_ += faction.get_nb_successful_attack_();
}