Пример #1
0
void Dialog::on_dialog_addCity_clicked()
{
      QString cityname = ui->name_line->text();
      qDebug() << cityname;

      QString cityX = ui->xline->text();
      qDebug() << cityX;

      QString cityY = ui->yline->text();
      qDebug() << cityY;


      int intCityX = cityX.toInt();
      qDebug() << intCityX;

      int intCityY = cityY.toInt();
      qDebug() << intCityY;

      ControlDialog controldialog (cityname, cityX, cityY);
      int result = controldialog.exec();

      if ( controldialog.control == 1)
      {
          City *NewCity = new City (cityname , intCityX , intCityY);
          map->addCity(NewCity);
          NewCity->draw(*scene);
          close();
      }
}
Пример #2
0
 /** returns distance from this city to another one (dest_city), 
     calculated from these cities coordinates */
 Distance distance(const City &dest_city) const
 {
     Coord dx = getX() - dest_city.getX();
     Coord dy = getY() - dest_city.getY();
   
     return sqrt(static_cast<double>(dx*dx + dy*dy));
 }
Пример #3
0
int Dijkstra(int START,int END)
{
	priority_queue<City,vector<City>,CMP> QUE;
	vector<int> Path(MAXN,INF);
	Path[START]=0;
	City temp;
	temp.set(START,0);
	QUE.push(temp);
	while(!QUE.empty())
	{
		int Ups=QUE.top().LCity;
		if(Ups==END) return QUE.top().Cost;
		QUE.pop();
		for(unsigned i=0;i<Graph[Ups].size();i++){
			int tCity=Graph[Ups][i].LCity;
			int tCost=Graph[Ups][i].Cost;
			if(tCost+Path[Ups]<Path[tCity]){
				Path[tCity]=tCost+Path[Ups];
				temp.set(tCity,Path[tCity]);
				QUE.push(temp);
			}
		}
	}
	return -1;
}
CitySelectDlg::CitySelectDlg(QString str1,QString str2,QString str3):ZPopup()
{
    setTitle(str1);
    listBox = new ZListBox("%I%M",this);
    
    // insert menu items with images from SysRegistry
    ZConfig config ( getAppDir() + "cities.ini", false );
    QStringList grouplist;
    config.getGroupsKeyList ( grouplist );
    QString cityCode = "";
    
    for ( QStringList::Iterator it = grouplist.begin(); it != grouplist.end(); ++it ) 
    {
        cityCode = config.readEntry(*it, "Code", "");
        City *city = new City(listBox);
        qDebug(*it);
        qDebug(cityCode);
        city->setName(*it);
        city->setCode(cityCode);
        
        listBox->insertItem(city);
        city->appendSubItem(1,ctr(city->getName()));
        
    }
    
    insertChild(listBox);
    setSoftkeyText(str2,str3);
    connect(this,SIGNAL(leftSoftkeyClicked()),this,SLOT(slotSelected()));
    connect(listBox,SIGNAL(returnPressed(ZSettingItem *)),this,SLOT(slotItemClicked(ZSettingItem *)));
    
}
Пример #5
0
void Vector::readAirports()
{
  char line[1000], state2[80];
  City city;
  ifstream inf("airportLL.txt");

  while (inf.getline(line, 1000))
  {
    if (isalpha(line[0]))
      strcpy(state2, strtok(line, "\n"));
    
    if (line[0] == '[')
    {
      city.readAirport(line, state2);
      
      for (int i = 0; i < count; i++)
        if (cityArray[i].isEqual(&city))
        {
          cityArray[i].copyLocation(&city);
          break;
        }  // if found a matching name
      
      city.deallocate();
    }  // if an airport line
  }  // while
}  // readAirports()
uint GWCityAskInitInfoHandler::Execute( GWCityAskInitInfo* pPacket, Player* pPlayer )
{
	__ENTER_FUNCTION

		ServerPlayer* pServerPlayer = (ServerPlayer*)pPlayer;
		ID_t	ServerID = pServerPlayer->GetServerData()->m_ServerID;
		for(UINT i = 0; i<g_Config.m_SceneInfo.m_SceneCount; i++)
		{
			if(g_Config.m_SceneInfo.m_pScene[i].m_ServerID == ServerID)
			{//本服务器的场景
				for(INT j =0; j<MAX_CITY_PER_WORLD; j++ )
				{
					City* pCity = g_pCityManager->GetCityByIndex(j);
					if(pCity)
					{
						if(pCity->GetPortSceneID() == g_Config.m_SceneInfo.m_pScene[i].m_SceneID)
						{//当前城市是挂在这个场景上的
							/*WGCityInitInfo*/

						}
						
					}
				}
					

			}


		}
		return PACKET_EXE_CONTINUE ;

	__LEAVE_FUNCTION

		return PACKET_EXE_ERROR ;
}
//---------------------------------------------------------------------------
void Civilization::SaveToFile(FILE *stream)
{
 int n = Nest->GetCityName();
 fwrite(&n,sizeof(int),1,stream);
 n = FoodSourceCity->GetCityName();
 fwrite(&n,sizeof(int),1,stream);
 n = Cities->Count;
 fwrite(&n,sizeof(int),1,stream);
 City *nCity;
 for(int i=0; i<Cities->Count; i++)
  {
   nCity = (City*)Cities->Items[i];
   n = nCity->GetCityPositionX();
   fwrite(&n,sizeof(int),1,stream);
   n = nCity->GetCityPositionY();
   fwrite(&n,sizeof(int),1,stream);
  }
 n = Roads->Count;
 fwrite(&n,sizeof(int),1,stream);
 Route *nRoad;
 for(int i=0; i<Roads->Count; i++)
  {
   nRoad = (Route*)Roads->Items[i];

   n = nRoad->GetCityName(1);
   fwrite(&n,sizeof(int),1,stream);
   n = nRoad->GetCityName(2);
   fwrite(&n,sizeof(int),1,stream);
  }
}
Пример #8
0
std::vector<Trade_route> City::find_sellers_of(Resource res)
{
  std::vector<Trade_route> ret;
  for (std::map<int,Trade_route>::iterator it = trade_routes.begin();
       it != trade_routes.end();
       it++) {
    City* seller = GAME->world->lookup_city_uid(it->first);
    if (seller) {
      int avail = seller->get_net_resource_production(res);
      if (avail > 0) {
// Insert into our return vector, sorted by distance.
// TODO: Sort by unit price (including overhead)!
        int dist = it->second.distance;
        bool found = false;
        for (int i = 0; !found && i < ret.size(); i++) {
          if (dist <= ret[i].distance) {
            found = true;
            ret.insert( ret.begin() + i, it->second );
          }
        }
        if (!found) {
          ret.push_back(it->second);
        }
      } // if (avail > 0)
    } // if (seller)
  } // for (std::map<int,Trade_route>::iterator it = trade_routes.begin(); ... )
  return ret;
}
Пример #9
0
/**
 * Loads the region type from a YAML file.
 * @param node YAML node.
 */
void RuleRegion::load(const YAML::Node &node)
{
	_type = node["type"].as<std::string>(_type);
	_cost = node["cost"].as<int>(_cost);
	std::vector< std::vector<double> > areas;
	areas = node["areas"].as< std::vector< std::vector<double> > >(areas);
	for (size_t i = 0; i != areas.size(); ++i)
	{
		_lonMin.push_back(areas[i][0] * M_PI / 180);
		_lonMax.push_back(areas[i][1] * M_PI / 180);
		_latMin.push_back(areas[i][2] * M_PI / 180);
		_latMax.push_back(areas[i][3] * M_PI / 180);
	}
	if (const YAML::Node &cities = node["cities"])
	{
		for (YAML::const_iterator i = cities.begin(); i != cities.end(); ++i)
		{
			City *rule = new City("", 0.0, 0.0);
			rule->load(*i);
			_cities.push_back(rule);
		}
	}
	if (const YAML::Node &weights = node["missionWeights"])
	{
		_missionWeights.load(weights);
	}
	_regionWeight = node["regionWeight"].as<unsigned>(_regionWeight);
	_missionZones = node["missionZones"].as< std::vector<MissionZone> >(_missionZones);
	_missionRegion = node["missionRegion"].as<std::string>(_missionRegion);
}
Пример #10
0
void DrawCityModule::setup(City &city)
{
    _city = &city;
    _ground = &city.ground();
    _description = &city.description();

    setupShaders();
    update();

    for(size_t i=0; i<_components.size(); ++i)
        delete _components[i];
    _components.clear();

    _components.push_back(_skyComponent       = new SkyComponent(      *_city, _skyShader));
    _components.push_back(_groundComponent    = new GroundComponent(   *_city, _groundShader));
    _components.push_back(_waterComponent     = new WaterComponent(    *_city, _waterShader));
    _components.push_back(_citizensComponent  = new CitizensComponent( *_city, _minimalistShader));
    _components.push_back(_junctionsComponent = new JunctionsComponent(*_city, _infrastructShader));
    _components.push_back(_streetsComponent   = new StreetsComponent(  *_city, _infrastructShader));
    _components.push_back(_buildingsComponent = new BuildingsComponent(*_city, _infrastructShader));
    _components.push_back(_bridgesComponent   = new BridgesComponent(  *_city, _infrastructShader));

    for(size_t i=0; i<_components.size(); ++i)
        _components[i]->setup();
}
Пример #11
0
//**in**
//City A the starting point of the line
//City B the ending point of the line
//City point the point to find the distance to
//**out**
//the distance from this line to the point
double point_to_line(Vec2 A, Vec2 B, City point)
{
	float diffX = B.x() - A.x();
	float diffY = B.y() - A.y();
	if ((diffX == 0) && (diffY == 0)){
		diffX = point.x() - A.x();
		diffY = point.y() - A.y();
		return sqrt(diffX * diffX + diffY * diffY);
	    }

	float t = ((point.x() - A.x()) * diffX + (point.y() - A.y()) * diffY) / (diffX * diffX + diffY * diffY);

	if (t < 0){
		//point is nearest to the first point i.e x1 and y1
		diffX = point.x() - A.x();
		diffY = point.y() - A.y();
	}
	else if (t > 1){
		//point is nearest to the end point i.e x2 and y2
		diffX = point.x() - B.x();
		diffY = point.y() - B.y();
	}
	else
	{
		//if perpendicular line intersect the line segment.
		diffX = point.x() - (A.x() + t * diffX);
		diffY = point.y() - (A.y() + t * diffY);
	}
    //return shortest distance
    return sqrt(diffX * diffX + diffY * diffY);
}
//---------------------------------------------------------------------------
// Description: This method update the preview panel drawing the road with
//              the heigher intensity of pheromone in red
bool __fastcall Civilization::DrawPreviewBoard()
{
 // Scale factor
 const float Scale  = 0.25;
 const int   Radius = 5;
 City *mCity = NULL;

 for(int i=0; i<Roads->Count; i++)
  {
   ((Route*)Roads->Items[i])->DrawRoad(Preview,clBlue,Scale);
  }

 FindMainRoads(25,Preview,3,Scale);

 for(int i=0; i<Cities->Count; i++)
  {
   mCity = (City*)Cities->Items[i];

   int X = Scale*mCity->GetCityPositionX();
   int Y = Scale*mCity->GetCityPositionY() + 2;

   Preview->Canvas->Pen->Color =   clGreen;
   Preview->Canvas->Brush->Color =   clGreen;
   Preview->Canvas->Ellipse(X-Radius, Y-Radius, X+Radius, Y+Radius);//, X+Radius, Y+Radius, X+Radius, Y+Radius);
   Preview->Canvas->Brush->Color =   clWhite;
  }

 return true;
}
Пример #13
0
void Vector::readAirports()
{
  char line[1000];
  char state[40];
  City city;
  ifstream fp;
  fp.open("airportLL.txt");
  
  while (fp.getline(line, 1000))
  {
    if (isalpha(line[0]))
      strcpy(state, line);
    
    if (line[0] == '[')
    {
      city.readAirport(line, state);
      
      for (int i = 0; i < count; i++)
        if (cityArray[i].isEqual(&city))
        {
          cityArray[i].copyLocation(&city);
          //cout<<cityArray[i].name;
          break;
        }  // if found a matching name
      
      city.deallocate();
    }  // if an airport line
  }  // while
}  // readAirports()
Пример #14
0
City* Game::CreateCity( const Point& pos, Faction& owner )
{
	// Create a graphical entity
	ITexture* pTexture = AssetManager::Get().GetAsset< ITexture >( "BTNSteelMelee.png" );

	Material* pMaterial = AssetManager::Get().GetAsset<Material>( "Materials/GhoulMat.xmat" );

	// Create entity
	Entity* pCubeEntity = GameManager::CreateEntity();

	MeshComponent* pMesh = pCubeEntity->AddComponent<MeshComponent>();
	pMesh->SetMesh( Mesh::CreateBox() );
	pMesh->GetMesh()->Release();
	pMesh->SetMaterial( pMaterial );

	pCubeEntity->GetTransform().SetPosition( m_pWorld->GetPositionForTile( pos.x, pos.y ) );

	// Create the city
	City* pCity = pCubeEntity->AddComponent<City>();
	pCity->SetFaction( &owner );
	m_Cities.push_back( pCity );
	pCity->AddRef();

	m_pWorld->SetEntityPosition( pCubeEntity, pos.x, pos.y );

	return pCity;
}
Пример #15
0
int main() {
	Map gameMap;
	vector<City*> worldMap;
	string filename = "Cities.txt";					// name of file containing map information
	string savefile = "game1";

	worldMap = gameMap.getWorldMap();
	cout << "Before: " << gameMap.getWorldMap().size() << endl << endl;

	cout << "Populating map from file." << endl;
	gameMap.populateMap(filename);
	cout << "Finished populating map."  << endl << endl;

	cout << "After:  " << gameMap.getWorldMap().size() << endl << endl;

	// test of searching map for city and returning city info
	City* currentCity = gameMap.locateCity("Montreal");
	if(currentCity != NULL) {
		currentCity->setInfectedBlue(3);
	}

	ofstream fp_out(savefile, ios::out);
	if(fp_out.is_open()) {
		gameMap.saveGame(fp_out);
		fp_out.close();
	}
	else
		cout << "Error opening file." << endl;

	cout << "Press any key to exit.";
	cin.get();

	return 0;
}
UINT GWCityCloseSuccessHandler::Execute( GWCityCloseSuccess* pPacket, Player* pPlayer )
{
    __ENTER_FUNCTION

        ServerPlayer* pServerPlayer = (ServerPlayer*)pPlayer;
        _CITY_GUID    CityGuid = pPacket->GetCityGuid();

        City* pDelCity = g_pCityManager->GetCityByGuid(CityGuid);
        if(!pDelCity->IsLock())
        {//已经有人在删除此城市了
            Assert(FALSE);
            return PACKET_EXE_CONTINUE ;
        }

        SceneID_t CitySceneID = pDelCity->GetSceneID();

        GUID_t PlayerGuid = pDelCity->GetApplicantGuid();
        g_pCityManager->DelCityByGuid(CityGuid);

        WGCityCloseSuccess MsgToServer;
        MsgToServer.SetPlayerGuid(PlayerGuid);
        MsgToServer.SetSceneID(CitySceneID);
        pServerPlayer->SendPacket(&MsgToServer);
        
        return PACKET_EXE_CONTINUE ;

    __LEAVE_FUNCTION

        return PACKET_EXE_ERROR ;
}
Пример #17
0
City City::create(const QVariantMap &values)
{
    City model;
    model.setProperties(values);
    if (!model.d->create()) {
        model.d->clear();
    }
    return model;
}
Пример #18
0
		string toString() {
			std::string s = begin.toString() + " " + end.toString() + " ";
			std::stringstream out;
			out << distance;
			s += out.str() + " ";
			if (toll) s+= "true";
			else s+= "false";
			return s;
		}
Пример #19
0
int main(void)
{


    //create a city
    City* Lyon = new City();

    //String to stock commands entered by users
    string command;

    //stock int in order to give as argument to method
    int id;
    int year;
    int month;
    int day;
    int hour;
    int minute;
    int seconde;
    char value;
    int d7;

    //time structure
    time_t time;
    struct tm date;

    // get commands entered by users
    cin>>command;

    while (command.compare("EXIT")!=0) {

        #ifdef MAP
        //cout<< "nouveau depart boucle" << "\r\n";
        //cout<< "la commande entree est : " << command << "\r\n";
        #endif

      if (command.compare("STATS_C")==0) {

        #ifdef MAP
        //cout<< "Appel a la commande STATS_C" << "\r\n";
        #endif

        cin>>id;

        //Function called
        Lyon->Stats_C(id);

        //trace
        #ifdef MAP
            cout<<id<<"\r\n";
        #endif

        // Clear the command
        command="";

     } else if (command.compare("STATS_D7_H24")==0) {
Пример #20
0
City* City::create(const char *pszFileName)
{
    City *pobSprite = new City();
    if (pobSprite && pobSprite->initWithFile(pszFileName))
    {
        pobSprite->autorelease();
        return pobSprite;
    }
    CC_SAFE_DELETE(pobSprite);
    return NULL;
}
Пример #21
0
int City::operator == (const City& city){

	if(name == city.getName() && country == city.getCountry())
	{
		return 1;
	}
	else
	{
		return 0;
		
	}
}
Пример #22
0
void World::ProcessEndTurn()
{
	City* c;

	for( std::vector<City*>::iterator ci = Cities.begin(); ci != Cities.end(); ci++ )
	{
		c = (City*)(*ci);
		c->ProcessEndTurn();
	}

	IsBetweenTurns = true;
	BetweenTurnFrame = 0;
}
Пример #23
0
void log2()
{

    XLOGGER2_OPEN(_T("UpgradeXLog"));
    {
        XLOGGER2_FUNCT_INFO;
    }

    City city;
    city.ShowFun();
    city.LoveCity();
    XLOGGER2_CLOSE
}
Пример #24
0
City *generate_city(const Parameters &p)
{
	City *c = new City;

	c->add_location(generate_location(p)); // start location...

	generate_trucks(p, c);
	generate_requests(p, c);
	generate_landfills(p, c);
	generate_staging_areas(p, c);

	return c;
}
Пример #25
0
std::vector<Trade_route> City::find_buyers_for(Resource res)
{
  std::vector<Trade_route> ret;
  for (std::map<int,Trade_route>::iterator it = trade_routes.begin();
       it != trade_routes.end();
       it++) {
    City* buyer = GAME->world->lookup_city_uid(it->first);
    if (buyer && buyer->get_daily_demand(res) > 0) {
      ret.push_back(it->second);
    }
  }
  return ret;
}
Пример #26
0
int Vector::findAirport(const char *airport) const
{
  City city;
  
  city.setAirport(airport);
  
  for (int i = 0; i < count; i++)
    if (cityArray[i].isEqual(&city))
      return i;
  
  cout << airport << " is not a valid airport.\n";
  return -1;
}  // findAirport()
Пример #27
0
//part of the quick hull algorithm based on http://www.ahristov.com/tutorial/geometry-games/convex-hull.html
int point_location(City A, City B, City P){
        int cp1 = (B.x() - A.x())*(P.y()-A.y()) - (B.y()-A.y())*(P.x()-A.x());
        if(cp1 > 0)
                return 1;
       	else
		 return -1;
}
Пример #28
0
//part of the quick hull algorithm based on http://www.ahristov.com/tutorial/geometry-games/convex-hull.html
int distance(City A, City B, City C){
        int ABx = B.x() - A.x();
        int ABy = B.y() - A.y();
        int num = ABx * (A.y() - C.y()) - ABy * (A.x() - C.x());
        if (num < 0)
                num = -num;
        return num;
}
Пример #29
0
uint GWCityCloseHandler::Execute( GWCityClose* pPacket, Player* pPlayer )
{
	__ENTER_FUNCTION

		ServerPlayer* pServerPlayer = (ServerPlayer*)pPlayer;

		_CITY_GUID	  CityGuid		= pPacket->GetCityGuid();
		GUID_t		  PlayerGuid	= pPacket->GetPlayerGuid();
		WGCityError MsgError;

		USER* pUser = g_pOnlineUser->FindUser( PlayerGuid ) ;
		if( pUser==NULL )
		{
			Log::SaveLog( WORLD_LOGFILE, "GWCityCloseHandler...User GUID=%X not find!", 
				PlayerGuid) ;
			return PACKET_EXE_CONTINUE ;
		}

		City* pDelCity = g_pCityManager->GetCityByGuid(CityGuid);
		if(!pDelCity)
		{
			Log::SaveLog( WORLD_LOGFILE, "GWCityCloseHandler...User GUID world=%d poolpos=%d  not find!", 
				CityGuid.m_World, CityGuid.m_PoolPos) ;
			return PACKET_EXE_CONTINUE ;
		}

		if(pDelCity->IsLock())
		{//已经有人删除此城市了
			Log::SaveLog( WORLD_LOGFILE, "GWCityCloseHandler...User GUID world=%d poolpos=%d  not find!", 
				CityGuid.m_World, CityGuid.m_PoolPos) ;
			return PACKET_EXE_CONTINUE ;
		}
		
		pDelCity->SetApplicantGuid(PlayerGuid);
		pDelCity->SetLock(TRUE);
		
		WGCityClose MsgToServer;
		MsgToServer.SetSceneID(pDelCity->GetSceneID());
		MsgToServer.SetPlayerID(pUser->GetPlayerID());
		pServerPlayer->SendPacket(&MsgToServer);
		
		return PACKET_EXE_CONTINUE ;

	__LEAVE_FUNCTION

		return PACKET_EXE_ERROR ;
}
Пример #30
0
int main()
{
	srand(time(NULL));
	
	std::cout << "=== Generation ===" << std::endl;
	
	City myCity;
	myCity.Generate();
	
	std::cout << "=== Export OBJ ===" << std::endl;
	ExportObj exporter(std::string(EXPORT_FILENAME));
	exporter.Export(&myCity);
	
	std::cout << "=== Export OBJ termine ===" << std::endl;
	
	return EXIT_SUCCESS;
}