void Prefecture::deliverService() { if( getWorkers() > 0 && getWalkerList().size() == 0 ) { bool fireDetect = _fireDetect.getI() >= 0; PrefectPtr walker = Prefect::create( _getCity() ); walker->setMaxDistance( 26 ); //bool patrol = true; if( fireDetect ) { Pathway pathway; TilePos startPos = getAccessRoads().front()->getIJ(); bool pathFounded = Pathfinder::getInstance().getPath( startPos, _fireDetect, pathway, false, Size( 0 ) ); //patrol = !pathFounded; if( pathFounded ) { walker->setPathway( pathway ); walker->setIJ( pathway.getOrigin().getIJ() ); } _fireDetect = TilePos( -1, -1 ); } walker->send2City( PrefecturePtr( this ), fireDetect ? 200 : 0 ); addWalker( walker.as<Walker>() ); } }
Picture& Road::computePicture() { int i = getTile().getI(); int j = getTile().getJ(); std::list<Tile*> roads = getAccessRoads(); int directionFlags = 0; // bit field, N=1, E=2, S=4, W=8 for (std::list<Tile*>::iterator itRoads = roads.begin(); itRoads!=roads.end(); ++itRoads) { Tile &tile = **itRoads; if (tile.getJ() > j) { directionFlags += 1; } // road to the north else if (tile.getJ() < j) { directionFlags += 4; } // road to the south else if (tile.getI() > i) { directionFlags += 2; } // road to the east else if (tile.getI() < i) { directionFlags += 8; } // road to the west } // std::cout << "direction flags=" << directionFlags << std::endl; int index; switch (directionFlags) { case 0: // no road! index = 101; break; case 1: // North index = 101; break; case 2: // East index = 102; break; case 4: // South index = 103; break; case 8: // West index = 104; break; case 3: // North+East index = 97; break; case 5: // North+South index = 93+2*(rand()%2); break; // 93/95 case 6: // East+South index = 98; break; case 7: // North+East+South index = 106; break; case 9: // North+West index = 100; break; case 10: // East+West index = 94+2*(rand()%2); break; // 94/96 case 11: // North+East+West index = 109; break; case 12: // South+West index = 99; break; case 13: // North+South+West index = 108; break; case 14: // East+South+West index = 107; break; case 15: // North+East+South+West index = 110; break; } Picture *picture = &PicLoader::instance().get_picture( rcRoadGroup, index); return *picture; }
bool Factory::_mayDeliverGood() const { return ( getAccessRoads().size() > 0 ) && ( getWalkerList().size() == 0 ); }
bool Factory::_mayDeliverGood() const { return ( getAccessRoads().size() > 0 ) && ( _d->pushers.size() == 0 ); }