Beispiel #1
0
Structure* World::addNewHome(int x, int y)
{
  Structure home;
  home.placeObject(x,y);
  structures.push_back(home);
  return &structures.back();
}
Beispiel #2
0
void World::runFrameWithInput(Event* Event)
{
  // The other update function, this is going to be run when there is input. 
  // If the event is a click on a unit or structure then we set it as the selected entity

  // Most of the code in this function is pretty much solely for testing purposes
  // Actual input will be handled in a much more sane fashion in a separate location
  if (Event->type == input::e_keyEvent)
    {
      // Handle when the "C" key is pressed
      if(Event->key == DKeysym::DK_Key_c)
	{
	  if (!worldCreated)
	    {
	      worldMap.setSize(20);
	      terrainMap.setSize(20);
	      worldWeather.setWeatherMapSize(20);
	      creators::fillTerrain(&worldMap);
	      std::cout << std::endl;
	      creators::fillTerrainDetails(&terrainMap, &worldMap);
	      std::cout << std::endl;
	      creators::placeResources(&objects, &terrainMap);
	      creators::fillWeather(worldWeather.getWeatherMap());	      
	      worldCreated = true;
	    }
	  else if(worldCreated)
	    {
	      Entity newEnt;
	      newEnt.initEntity(0,0,0,"test");
	      std::cout << "New Entity created" << std::endl;
	      citizens.push_back(newEnt);
	      std::cout << "Entity added to citizens" << std::endl;
	    }
	}
      // Handle when the "P" key is pressed
      else if (Event->key == DKeysym::DK_Key_p)
	{
	  if (selected)
	    {
	      std::cout << "Selected report" << std::endl;
	      std::cout << "Position: (";
	      std::cout << selected->getVitals().x << "," << selected->getVitals().y << ")";
	      std::cout << " Time Alive: " << selected->getVitals().timeAlive;
	      std::cout << " Hungry: " << selected->getStats().hunger;
	      std::cout << " Tired: " << selected->getStats().tired << std::endl;
	    }
	  else
	    {
	      std::vector<Object>::iterator it;
	      for (it = objects.begin(); it != objects.end(); ++it)
		{
		  std::cout << it->pollObject() << std::endl;
		}
	    }
	}
      // Handle when the "S" key is pressed
      else if (Event->key == DKeysym::DK_Key_s)
	{
	  if (selected)
	    {
	      std::cout << "Clearing Selection" << std::endl;
	      selected = NULL;
	    }
	  else
	    {
	      std::cout << "Creating new structure" << std::endl;
	      Structure temp;
	      temp.placeObject(0,0);
	      structures.push_back(temp);
	      std::cout << "Structure added to list" << std::endl;
	    }
	}
      // Handle when the "1" key is pressed
      else if (Event->key == DKeysym::DK_Key_1)
	{
	  if (citizens.size() >= 1 && selected != &citizens[0])
	    {
	      selected = &citizens[0];
	      std::cout << "First entity selected" << std::endl;
	    }
	}
      // Handle when the "2" key is pressed
      else if (Event->key == DKeysym::DK_Key_2)
	{
	  if (citizens.size() >= 2 && selected != &citizens[1])
	    {
	      selected = &citizens[1];
	      std::cout << "Second entity selected" << std::endl;
	    }
	}
      // Handle when the "W" key is pressed
      else if (Event->key == DKeysym::DK_Key_w)
	{
	  worldWeather.getWeatherMap()->setLocationAtCoord(0,0,33);
	}
      // Handle when the "T" key is pressed
      else if (Event->key == DKeysym::DK_Key_t)
	{
	  if (selected != &citizens[1])
	    {
	      std::cout << "Moving selected entity to entity 1" << std::endl;
	      selected->moveToTarget(&citizens[1]);
	    }
	}
      // Handle when the "M" key is pressed
      else if (Event->key == DKeysym::DK_Key_m)
	{
	  if (structures.size() > 0)
	    {
	      std::cout << "Starting construction on first structure" << std::endl;
	      structures[0].startConstruction();	      
	    }
	}
      else if (Event->key == DKeysym::DK_Key_r)
	{
	  if (selected)
	    {	   
	      organizations[0].removeFromGroup(selected);
	    }
	  else
	    {
	      std::vector<Structure>::iterator it;
	      for (it = structures.begin(); it != structures.end(); ++it)
		{
		  Structure temp = *it;
		  temp.structureReport();
		}
	    }
	}
      else if (Event->key == DKeysym::DK_Key_o)
	{	 
	  createNewFood();
	}
      else if (Event->key == DKeysym::DK_Key_f)
	{
	  createNewFire();
	}
      else if (Event->key == DKeysym::DK_Key_g)
	{
	  if (selected)
	    {
	      if (organizations[0].requestEntry(selected))
		  {
		    organizations[0].addToGroup(selected);
		  }		  	    
	    }
	  else
	    {
	      DudeGroup newGroup;
	      organizations.push_back(newGroup);
	    }
	}
    }
  else if (Event->type = input::e_mouseEvent)
    {
      std::cout << "Mouse test" << std::endl;
    }
  // Finally run the standard frame
  runFrame();
}