本文整理汇总了C++中Town类的典型用法代码示例。如果您正苦于以下问题:C++ Town类的具体用法?C++ Town怎么用?C++ Town使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Town类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: deinit_unit_mode
//--------- Begin of function Unit::deinit_unit_mode ---------//
//
void Unit::deinit_unit_mode()
{
if( sys.signal_exit_flag )
return;
//----- this unit was defending the town before it gets killed ----//
if(unit_mode==UNIT_MODE_TOWN_DEFENDER)
{
if(!town_array.is_deleted(unit_mode_para))
{
Town *townPtr = town_array[unit_mode_para];
if(nation_recno == townPtr->nation_recno)
townPtr->reduce_defender_count();
}
set_mode(0); // reset mode
}
// ###### begin Gilbert 30/4 #########//
else if( unit_mode == UNIT_MODE_CAMP_DEFENDER )
{
// no extra action needed other than reset mode
// if(!firm_array.is_deleted(unit_mode_para))
// {
// Firm *firmPtr = firm_array[unit_mode_para];
// if(nation_recno == firmPtr->nation_recno)
// firmPtr->reduce_defender_count();
// }
set_mode(0); // reset mode
}
// ###### end Gilbert 30/4 #########//
/*
//----- this is a monster unit defending its town ------//
else if( unit_mode==UNIT_MODE_MONSTER && unit_mode_para )
{
if(((UnitMonster*)this)->monster_action_mode!=MONSTER_ACTION_DEFENSE)
return;
FirmMonster* firmMonster = (FirmMonster*) firm_array[unit_mode_para];
err_when( firmMonster->firm_id != FIRM_MONSTER );
firmMonster->reduce_defender_count(rank_id);
}
*/
}
示例2: majority_race
//------- Begin of function Town::think_ai_migrate_to_town --------//
//
// Think about the town to migrate to.
//
int Town::think_ai_migrate_to_town()
{
//------ think about which town to migrate to ------//
Nation* nationPtr = nation_array[nation_recno];
int curRating, bestRating=0, bestTownRecno=0;
short *aiTownPtr = nationPtr->ai_town_array;
int majorityRace = majority_race();
Town *townPtr;
for(int i=0; i<nationPtr->ai_town_count; i++, aiTownPtr++)
{
if( town_recno == *aiTownPtr )
continue;
townPtr = town_array[*aiTownPtr];
err_when( townPtr->nation_recno != nation_recno );
if( !townPtr->is_base_town ) // only migrate to base towns
continue;
if( townPtr->region_id != region_id )
continue;
if( population > MAX_TOWN_POPULATION-townPtr->population ) // if the town does not have enough space for the migration
continue;
//--------- compare the ratings ---------//
curRating = 1000 * townPtr->race_pop_array[majorityRace-1] / townPtr->population; // *1000 so that this will have a much bigger weight than the distance rating
curRating += world.distance_rating( center_x, center_y, townPtr->center_x, townPtr->center_y );
if( curRating > bestRating )
{
//--- if there is a considerable population of this race, then must migrate to a town with the same race ---//
if( race_pop_array[majorityRace-1] >= 6 )
{
if( townPtr->majority_race() != majorityRace ) // must be commented out otherwise low population town will never be optimized
continue;
}
bestRating = curRating;
bestTownRecno = townPtr->town_recno;
}
}
return bestTownRecno;
}
示例3:
// -----------------------------------------------------------------
// Name : findTown
// -----------------------------------------------------------------
Town * Map::findTown(u32 uTownId)
{
// Loop through map
for (int x = 0; x < m_iWidth; x++)
{
for (int y = 0; y < m_iHeight; y++)
{
Town * pTown = (Town*) (m_pTiles[x][y])->getFirstMapObject(GOTYPE_TOWN);
if (pTown != NULL && pTown->getId() == uTownId)
return pTown;
}
}
return NULL;
}
示例4: ai_assign_spy_to_town
//--------- Begin of function Nation::ai_assign_spy_to_town --------//
//
// Think about sending spies to the specific town.
//
// <int> townRecno - recno of the town
// [int] raceId - race id. of the spy
// (default: majority_race() of the tonw)
//
// return: <int> 1 - a spy is assigned successfully.
// 0 - failure.
//
int Nation::ai_assign_spy_to_town(int townRecno, int raceId)
{
Town* townPtr = town_array[townRecno];
if( townPtr->population >= MAX_TOWN_POPULATION )
return 0;
if( !raceId )
raceId = townPtr->majority_race();
int mobileOnly = townPtr->nation_recno == nation_recno; // if assign to own towns/firms, only get mobile spies, don't get spies from existing towns/firms as that will result in a loop effect
return ai_assign_spy( townPtr->loc_x1, townPtr->loc_y1, raceId, mobileOnly );
}
示例5: payRent
bool Houses::payRent(Player* player, House* house, uint32_t bid, time_t _time/* = 0*/)
{
if(rentPeriod == RENTPERIOD_NEVER || !house->getOwner() ||
house->getPaidUntil() > _time || !house->getRent() ||
player->hasCustomFlag(PlayerCustomFlag_IgnoreHouseRent))
return true;
Town* town = server.towns().getTown(house->getTownId());
if(!town)
return false;
bool paid = false;
uint32_t amount = house->getRent() + bid;
if(server.configManager().getBool(ConfigManager::BANK_SYSTEM) && player->balance >= amount)
{
player->balance -= amount;
paid = true;
}
else if(Depot* depot = player->getDepot(town->getID(), true))
paid = server.game().removeMoney(depot, amount, FLAG_NOLIMIT);
if(!paid)
return false;
if(!_time)
_time = time(nullptr);
uint32_t paidUntil = _time;
switch(rentPeriod)
{
case RENTPERIOD_DAILY:
paidUntil += 86400;
break;
case RENTPERIOD_WEEKLY:
paidUntil += 7 * 86400;
break;
case RENTPERIOD_MONTHLY:
paidUntil += 30 * 86400;
break;
case RENTPERIOD_YEARLY:
paidUntil += 365 * 86400;
break;
default:
break;
}
house->setPaidUntil(paidUntil);
return true;
}
示例6: mobilize_capturer
//-------- Begin of function Nation::mobilize_capturer ------//
//
// Mobilize the capturer unit if he isn't mobilized yet.
//
int Nation::mobilize_capturer(int unitRecno)
{
//--- if the picked unit is an overseer of an existng camp ---//
Unit* unitPtr = unit_array[unitRecno];
if( unitPtr->unit_mode == UNIT_MODE_OVERSEE )
{
Firm* firmPtr = firm_array[unitPtr->unit_mode_para];
Town* townPtr;
//-- can recruit from either a command base or seat of power --//
//-- train a villager with leadership to replace current overseer --//
int i;
for( i=0 ; i<firmPtr->linked_town_count ; i++ )
{
townPtr = town_array[ firmPtr->linked_town_array[i] ];
if( townPtr->nation_recno != nation_recno )
continue;
//--- first try to train a unit who is racially homogenous to the commander ---//
int unitRecno = townPtr->recruit( SKILL_LEADING, firmPtr->majority_race(), COMMAND_AI );
//--- if unsucessful, then try to train a unit whose race is the same as the majority of the town ---//
if( !unitRecno )
unitRecno = townPtr->recruit( SKILL_LEADING, townPtr->majority_race(), COMMAND_AI );
if( unitRecno )
{
add_action(townPtr->loc_x1, townPtr->loc_y1, -1, -1, ACTION_AI_ASSIGN_OVERSEER, FIRM_CAMP);
break;
}
}
if( i==firmPtr->linked_town_count ) // unsuccessful
return 0;
//------- mobilize the current overseer --------//
firmPtr->mobilize_overseer();
}
return 1;
}
示例7: add_town
//----- Begin of function TownArray::add_town -------//
//
// <int> nationRecno - the nation recno
// <int> raceId - the race of the majority of the town poulation
// <int> xLoc, yLoc - location of the town
//
int TownArray::add_town(int nationRecno, int raceId, int xLoc, int yLoc)
{
Town* townPtr;
townPtr = new Town;
linkin(&townPtr);
townPtr->town_recno = recno();
townPtr->init(nationRecno, raceId, xLoc, yLoc);
nation_array.update_statistic(); // update largest_town_recno
return recno();
}
示例8: create
static Target create( const Option& o )
{
Town* town = new Town( &o );
TargetValue* THIS = new TargetValue( town );
town->setTHIS(THIS);
Target target = THIS;
town->build(o);
//l.addFeature( target );
return Target(target);
}
示例9: main
int main()
{
int i,j;
/*Strategy * a;
for(i=0;i<1000;i++)
{
a= new Strategy(5);
a->getScore();
a->getBar(20);
a->updateScore(1);
delete a;
}
cout<<"strat"<<endl;
int c[]={1,0,1,1,0,1,0,1,1,0};
Agent * b;
for(i=0;i<1000;i++)
{
b= new Agent(10,0,0);
b->isGoingToBar(20);
b->tellWins(c,40);
b->isDead();
delete b;
}
cout<<"Agent"<<endl;
Group * d;
for(i=0;i<1000;i++)
{
d=new Group(4,5,0,0);
d->isGoingToBar(20);
d->getNumPeeps();
d->isEmpty();
delete d;
}
cout<<"Group"<<endl;*/
int g[]={1,2,3,4,5};
Town * t;
for(i=0;i<1000;i++)
{
t=new Town(5,100,g,true,3,50,50);
for(j=0;j<1000;j++)
{
//cout<<i<<" "<<j<<endl;
t->turn();
}
delete t;
}
cout<<"Town"<<endl;
}
示例10: refToTown
State_TownMenu::State_TownMenu(Town& town, Ship& ship)
: refToTown(town), refToShip(ship)
{
int potenwidth = 14 + town.getName().size();
potenwidth = potenwidth > 18 ? potenwidth : 18;
console = new TCODConsole(potenwidth, 9);
}
示例11: tmp
StatusType RectangleLand::AddNeighborhood(Shore side, int location, int population){
if ( (location < 0) || (population <= 0) ) {
return INVALID_INPUT;
}
try{
Town tmp(location);
Town* T = Shores[side].find(&tmp);
if (T == NULL) {
return FAILURE;
}
if (T->AddNeighborhood(population) == T->TownSuccess) {
return SUCCESS;
}
} catch (std::bad_alloc&) {
}
return FAILURE;
}
示例12: teleportToTown
void Commands::teleportToTown(Player* player, const std::string& cmd, const std::string& param)
{
Town* town = Towns::getInstance().getTown(param);
if (town) {
Position oldPosition = player->getPosition();
Position newPosition = g_game.getClosestFreeTile(player, 0, town->getTemplePosition(), true);
if (oldPosition != newPosition) {
if (newPosition.x == 0) {
player->sendCancel("You can not teleport there.");
} else if (g_game.internalTeleport(player, newPosition) == RET_NOERROR) {
g_game.addMagicEffect(oldPosition, NM_ME_POFF, player->isInGhostMode());
g_game.addMagicEffect(newPosition, NM_ME_TELEPORT, player->isInGhostMode());
}
}
} else {
player->sendCancel("Could not find the town.");
}
}
示例13: float
//------ Begin of function FirmWork::process_independent_town_worker -----//
//
// Process workers from independent towns.
//
// When workers work for a foreign firm, the overall resistance of
// the worker's town towards that nation decreases.
//
void FirmWork::process_independent_town_worker()
{
#define RESISTANCE_DECREASE_PER_WORKER float(0.2) // resistance decrease per month every 15 days
Town* townPtr;
for( int i=0 ; i<worker_count ; i++ )
{
err_when( !worker_array[i].town_recno );
townPtr = town_array[ worker_array[i].town_recno ];
if( townPtr->nation_recno==0 ) // if it's an independent town
{
townPtr->change_resistance( nation_recno, -RESISTANCE_DECREASE_PER_WORKER );
}
}
}
示例14: put_town_rec
//-------- Begin of static function put_town_rec --------//
//
static void put_town_rec(int recNo, int x, int y, int refreshFlag)
{
int townRecno = town_filter(recNo);
Town* townPtr = town_array[townRecno];
//---------- display info ----------//
x+=3;
y+=3;
font_san.put( x , y, townPtr->town_name() );
font_san.put( x+175, y, townPtr->population );
font_san.put( x+241, y, townPtr->jobless_population );
font_san.put( x+309, y, townPtr->average_loyalty() );
//------- display race icons -------//
x += 350;
int i;
int iconSpacing = RACE_ICON_WIDTH+2;
#if(MAX_RACE > 7)
int raceCount = 0;
for( i=0 ; i<MAX_RACE ; i++ )
{
if( townPtr->race_pop_array[i] > 0 )
{
++raceCount;
}
}
if( raceCount > 7 )
{
iconSpacing = 7 * iconSpacing / raceCount;
}
#endif
for( i=0 ; i<MAX_RACE ; i++ )
{
if( townPtr->race_pop_array[i] > 0 )
{
vga_back.put_bitmap( x, y-2, race_res[i+1]->icon_bitmap_ptr );
x += iconSpacing;
}
}
}
示例15: setLastErrorString
bool IOMap::parseTowns(OTB::Loader& loader, const OTB::Node& townsNode, Map& map)
{
for (auto& townNode : townsNode.children) {
PropStream propStream;
if (townNode.type != OTBM_TOWN) {
setLastErrorString("Unknown town node.");
return false;
}
if (!loader.getProps(townNode, propStream)) {
setLastErrorString("Could not read town data.");
return false;
}
uint32_t townId;
if (!propStream.read<uint32_t>(townId)) {
setLastErrorString("Could not read town id.");
return false;
}
Town* town = map.towns.getTown(townId);
if (!town) {
town = new Town(townId);
map.towns.addTown(townId, town);
}
std::string townName;
if (!propStream.readString(townName)) {
setLastErrorString("Could not read town name.");
return false;
}
town->setName(townName);
OTBM_Destination_coords town_coords;
if (!propStream.read(town_coords)) {
setLastErrorString("Could not read town coordinates.");
return false;
}
town->setTemplePos(Position(town_coords.x, town_coords.y, town_coords.z));
}
return true;
}