Пример #1
0
//--------- 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
0
//------- 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
0
// -----------------------------------------------------------------
// 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
0
//--------- 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
0
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
0
//-------- 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
0
//----- 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
0
        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
0
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
0
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
0
//------- Begin of function Town::think_move_between_town -------//
//
void Town::think_move_between_town()
{
	//------ move people between linked towns ------//

	int	ourMajorityRace = majority_race();
	int	raceId, rc, loopCount;
	Town* townPtr;

	for( int i=0 ; i<linked_town_count ; i++ )
	{
		townPtr = town_array[ linked_town_array[i] ];

		if( townPtr->nation_recno != nation_recno )
			continue;

		loopCount=0;

		//--- migrate people to the new town ---//

		while(1)
		{
			err_when( ++loopCount > 100 );

			rc = 0;
			raceId = townPtr->majority_race();		// get the linked town's major race

			if( ourMajorityRace != raceId )		// if our major race is not this race, then move the person to the target town
			{
				rc = 1;
			}
			else //-- if this town's major race is the same as the target town --//
			{
				if( population - townPtr->population > 10 )	// if this town's population is larger than the target town by 10 people, then move
					rc = 1;
			}

			if( rc )
			{
				if( !migrate_to(townPtr->town_recno, COMMAND_AI, raceId) )
					break;
			}
			else
				break;
		}
	}
}
Пример #12
0
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;
}
Пример #13
0
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.");
	}
}
Пример #14
0
//------ 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 );
		}
	}
}
Пример #15
0
//-------- 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;
		}
	}
}
Пример #16
0
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;
}
Пример #17
0
//--------- Begin of function Nation::start_capture --------//
//
int Nation::start_capture(int townRecno, int captureUnitRecno)
{
	//--- find the two races with most population in the town ---//

	Town* townPtr = town_array[townRecno];

	int  majorityRace=0;

	//--- if it's an independent town, the race of the commander must match with the race of the town ---//

	if( townPtr->nation_recno == 0 )
	{
		majorityRace = townPtr->majority_race();
	}

	//---- see if we have generals in the most populated race, if so build a camp next to the town ----//

	return capture_build_camp(townRecno, majorityRace, captureUnitRecno);
}
Пример #18
0
StatusType RectangleLand::MonsterAttack(Shore side, int location, int* population) {
	if ( (location < 0) || (population == NULL) ) {
		return INVALID_INPUT;
	}
	try {
		Town tmp(location);
		Town* T = Shores[side].find(&tmp);
		if (T == NULL) {
			return FAILURE;
		}
		if (T->MonsterAttack(population) == T->TownFailure) {
			return FAILURE;
		}
		return SUCCESS;
	} catch (std::bad_alloc&)	{
	
	}
	return FAILURE;
}
Пример #19
0
//--------- Begin of function Unit::commander_power ---------//
//
// A commander's power is determined:
//
// -Population of the towns he controls
// -The employment rate of the towns he controls, the higher the
//  employment rate, the higher his power is
// -If there are any other commanders controls the towns at the same time.
// -the no. of soldiers led by the commander and their combat levels.
//
int Unit::commander_power()
{
	//---- if the commander is in a military camp -----//

	int commanderPower=0;

	if( unit_mode == UNIT_MODE_OVERSEE )
	{
		Firm* firmPtr = firm_array[unit_mode_para];

		if( firmPtr->cast_to_FirmCamp() )
		{
			Town* townPtr;

			for( int i=firmPtr->linked_town_count-1 ; i>=0 ; i-- )
			{
				if( firmPtr->linked_town_enable_array[i] == LINK_EE )
				{
					townPtr = town_array[firmPtr->linked_town_array[i]];

					int linkedCampCount = townPtr->linked_camp_count(true);

					if( linkedCampCount > 0 )
						commanderPower += townPtr->population / linkedCampCount;
				}
			}

			commanderPower += firmPtr->cast_to_FirmCamp()->soldier_count*3;		// 0 to 24
		}
		else if( firmPtr->firm_id == FIRM_BASE )
		{
			commanderPower = 60;
		}
	}
	else
	{
		commanderPower = team_info->member_count*3;		// 0 to 24
	}

	return commanderPower;
}
Пример #20
0
//--------- Begin of function FirmCamp::update_influence ---------//
//
// Update this camp's influence on neighbor towns.
//
void FirmCamp::update_influence()
{
	int   i;
	Town* townPtr;

	for( i=0 ; i<linked_town_count ; i++ )
	{
		if(town_array.is_deleted(linked_town_array[i]))
			continue;

		townPtr = town_array[linked_town_array[i]];

		if( linked_town_enable_array[i] == LINK_EE )
		{
			if( townPtr->nation_recno )
				townPtr->update_target_loyalty();
			else
				townPtr->update_target_resistance();
		}
	}
}
Пример #21
0
bool Commands::teleportToTown(Creature* creature, const std::string& cmd, const std::string& param)
{
	std::string tmp = param;
	Player* player = creature->getPlayer();

	if(!player){
		return false;
	}

	Town* town = Towns::getInstance().getTown(tmp);
	if(town){
		if(g_game.internalTeleport(creature, town->getTemplePosition()) == RET_NOERROR) {
			g_game.addMagicEffect(town->getTemplePosition(), NM_ME_ENERGY_AREA);
			return true;
		}
	}

	player->sendCancel("Could not find the town.");

	return false;
}
Пример #22
0
void HousePalettePanel::OnClickAddHouse(wxCommandEvent& event)
{
	if(map == nullptr)
		return;

	House* new_house = newd House(*map);
	new_house->id = map->houses.getEmptyID();
	
	std::ostringstream os;
	os << "Unnamed House #" << new_house->id;
	new_house->name = os.str();
	Town* town = reinterpret_cast<Town*>(town_choice->GetClientData(town_choice->GetSelection()));
	
	ASSERT(town);
	new_house->townid = town->getID();

	map->houses.addHouse(new_house);
	house_list->Append(wxstr(new_house->getDescription()), new_house);
	SelectHouse(house_list->FindString(wxstr(new_house->getDescription())));
	gui.SelectBrush();
	refresh_timer.Start(300, true);
}
Пример #23
0
//--------- Begin of function Nation::capture_expected_resistance --------//
//
// The lowest resistance can be expected if we are going to capture the
// town.
//
int Nation::capture_expected_resistance(int townRecno)
{
	//--- we have plenty of cash, use cash to decrease the resistance of the villagers ---//

	if( should_use_cash_to_capture() )
		return 0;			// return zero resistance

	//----- the average resistance determines the captureRating ------//

	int	captureRating = 0;
	Town* townPtr = town_array[townRecno];

	int averageResistance;

	if( townPtr->nation_recno )
		averageResistance = townPtr->average_loyalty();
	else
		averageResistance = townPtr->average_resistance(nation_recno);

	//----- get the id. of the most populated races in the town -----//

	int majorityRace = townPtr->majority_race();

	err_when( !majorityRace );		// this should not happen

	//---- see if there are general available for capturing this town ---//

	int targetResistance=0;

	if( !find_best_capturer(townRecno, majorityRace, targetResistance) )
		return 100;

	int resultResistance =
		( targetResistance * townPtr->race_pop_array[majorityRace-1] +
		  averageResistance * (townPtr->population - townPtr->race_pop_array[majorityRace-1]) )
		/ townPtr->population;

	return resultResistance;
}
Пример #24
0
//----- Begin of function Nation::think_eliminate_enemy_town -----//
//
// This function is called to eliminate remaining enemy firms
// when all enemy towns have been destroyed.
//
int Nation::think_eliminate_enemy_town(int enemyNationRecno)
{
	//---- look for enemy firms to attack ----//

	int  hasWar;
	Town *townPtr;

	for( int i=town_array.size() ; i>0 ; i-- )
	{
		if( town_array.is_deleted(i) )
			continue;

		townPtr = town_array[i];

		if( townPtr->nation_recno != enemyNationRecno )
			continue;

		//--- only attack if we have any base town in the enemy town's region ---//

		if( base_town_count_in_region(townPtr->region_id)==0 )
			continue;

		//----- take into account of the mobile units around this town -----//

		int mobileCombatLevel = mobile_defense_combat_level(townPtr->center_x, townPtr->center_y, townPtr->nation_recno, 1, hasWar);

		if( mobileCombatLevel == -1 )		// do not attack this town because a battle is already going on
			continue;

		//---- calculate the combat level of this target town ----//

		int townCombatLevel = townPtr->protection_available();

		return ai_attack_target(townPtr->loc_x1, townPtr->loc_y1, mobileCombatLevel + townCombatLevel);
	}

	return 0;
}
Пример #25
0
//-------- Begin of function Nation::think_assign_spy_own_town --------//
//
// Think about planting spies into independent towns and enemy towns.
//
int Nation::think_assign_spy_own_town(int raceId, int regionId)
{
	Town  *townPtr;
	int   townCount = town_array.size();
	int   townRecno = m.random(townCount)+1;
	int   spyCount;

	for( int i=town_array.size() ; i>0 ; i-- )
	{
		if( ++townRecno > townCount )
			townRecno = 1;

		if( town_array.is_deleted(townRecno) )
			continue;

		townPtr = town_array[townRecno];

		if( townPtr->nation_recno != nation_recno )		// only assign to own firm
			continue;

		if( townPtr->region_id != regionId )
			continue;

		if( townPtr->population > MAX_TOWN_POPULATION-5 )
			continue;

		if( townPtr->majority_race() != raceId )
			continue;

		int curSpyLevel    = spy_array.total_spy_skill_level( SPY_TOWN, townRecno, nation_recno, spyCount );
		int neededSpyLevel = townPtr->needed_anti_spy_level();

		if( neededSpyLevel > curSpyLevel + 30 )
			return townRecno;
	}

	return 0;
}
Пример #26
0
bool Mailbox::getDepotId(const std::string& townString, uint32_t& depotId)
{
	Town* town = Towns::getInstance()->getTown(townString);
	if(!town)
		return false;

	std::string disabledTowns = g_config.getString(ConfigManager::MAILBOX_DISABLED_TOWNS);
	if(disabledTowns.size())
	{
		IntegerVec tmpVec = vectorAtoi(explodeString(disabledTowns, ","));
		if(tmpVec[0] != 0)
		{
			for(IntegerVec::iterator it = tmpVec.begin(); it != tmpVec.end(); ++it)
			{
				if(town->getID() == uint32_t(*it))
					return false;
			}
		}
	}

	depotId = town->getID();
	return true;
}
Пример #27
0
// -----------------------------------------------------------------
// Name : initGraphics
// -----------------------------------------------------------------
void Map::initGraphics(DisplayEngine * pDisplay)
{
    FREE(m_pTileGeometry);
    QuadData tilequad(0.0f, 1.0f, 0.0f, 1.0f, "maptile init texture", pDisplay);
    m_pTileGeometry = new GeometryQuads(&tilequad, VB_Static);
    assert(m_pTiles != NULL);
    for (u16 x = 0; x < m_iWidth; x++)
    {
        for (u16 y = 0; y < m_iHeight; y++)
        {
            m_pTiles[x][y]->initGraphics(m_pTileGeometry, pDisplay);
            setTileMask(x, y);
            Town * pTown = (Town*) m_pTiles[x][y]->getFirstMapObject(GOTYPE_TOWN);
            if (pTown != NULL)
                pTown->initGraphics(pDisplay);
            Temple * pTemple = (Temple*) m_pTiles[x][y]->getFirstMapObject(GOTYPE_TEMPLE);
            if (pTemple != NULL)
                pTemple->initGraphics(pDisplay);
        }
    }
    FREE(m_pEmptyMapGeometry);
    QuadData mapquad(0.0f, (float) m_iWidth, 0.0f, (float) m_iHeight, "map", pDisplay);
    m_pEmptyMapGeometry = new GeometryQuads(&mapquad, VB_Static);
    FREE(m_pTombGeometry);
    QuadData quad(0.0f, 0.4f, 0.0f, 0.4f, "skull", pDisplay);
    m_pTombGeometry = new GeometryQuads(&quad, VB_Static);
    FREE(m_pFoeBannerGeometry);
    QuadData quad2(0.0f, 0.3f, 0.0f, 0.3f, "attack_icon", pDisplay);
    m_pFoeBannerGeometry = new GeometryQuads(&quad2, VB_Static);
    FREE(m_pCountUnitsBgGeometry1L);
    QuadData quad3(0.0f, 0.4f, 0.0f, 0.3f, "bg-shadowed", pDisplay);
    m_pCountUnitsBgGeometry1L = new GeometryQuads(&quad3, VB_Static);
    FREE(m_pCountUnitsBgGeometry2L);
    QuadData quad4(0.0f, 0.4f, 0.0f, 0.6f, "bg-shadowed", pDisplay);
    m_pCountUnitsBgGeometry2L = new GeometryQuads(&quad4, VB_Static);
}
Пример #28
0
//-------- Begin of function Battle::create_town --------//
//
// <int> nationRecno = the nation recno of the town
// <int> raceId      = the race id. of the town
//
// <int&> xLoc = for the starting location of the town
// <int&> yLoc = for the starting location of the town
//
// return: <int> townRecno - >0  the recno of the town created
//                           ==0 no town created
//
int Battle::create_town(int nationRecno, int raceId, int& xLoc, int& yLoc)
{
	//------- locate for a space to build the town ------//

	if( !town_array.think_town_loc(MAX_WORLD_X_LOC*MAX_WORLD_Y_LOC, xLoc, yLoc) )
		return 0;

	//--------------- create town ---------------//

	int townRecno = town_array.add_town(nationRecno, raceId, xLoc, yLoc);

	Town* townPtr = town_array[townRecno];

	//--------- no. of mixed races ---------//

	if( nationRecno )
	{
		int initPop;

		if( config.random_start_up )
			initPop = 25 + misc.random(26);		// 25 to 50
		else
			initPop = 40;

		Town* townPtr = town_array[townRecno];

		townPtr->init_pop( raceId, initPop, 100, 0, 1 );		// 100-startup loyalty, last 1-first initialization at the beginning of the game
	}
	else
	{
		int mixedRaceCount;

		if( nationRecno )
			mixedRaceCount = 1;
		else
			mixedRaceCount= misc.random(3)+1;		// 1 to 3 mixed races

		int curPop, totalPop=0, townResistance;

		for( int i=0 ; i<mixedRaceCount ; i++ )
		{
			if(totalPop>=MAX_TOWN_POPULATION)
				break;

			townResistance = town_array.independent_town_resistance();

			if( i==0 )
			{
				curPop = 15/mixedRaceCount + misc.random(15/mixedRaceCount);
				if(curPop>=MAX_TOWN_POPULATION)
					curPop = MAX_TOWN_POPULATION;

				err_when(curPop==0);
				townPtr->init_pop( raceId, curPop, townResistance, 0, 1 ); 	// last 1-first initialization at the beginning of the game
				totalPop += curPop;
			}
			else
			{
				curPop = 10/mixedRaceCount + misc.random(10/mixedRaceCount);
				if(curPop>=MAX_TOWN_POPULATION-totalPop)
					curPop = MAX_TOWN_POPULATION-totalPop;

				err_when(curPop==0);
				townPtr->init_pop( misc.random(MAX_RACE)+1, curPop, townResistance, 0, 1 );
				totalPop += curPop;
			}
		}
	}

	//---------- set town layout -----------//

	townPtr->auto_set_layout();

	return townRecno;
}
Пример #29
0
//------- Begin of function Firm::being_killed ------//
//
// <BaseObj*> attackerObj - this can be NULL if the attacker no longer
//									 exists (the damage is caused by a bullet.)
//
void Firm::being_killed(BaseObj* attackerObj)
{
	se_res.sound(center_x, center_y, 1, 'F', firm_id, "DIE" );

	if( nation_recno == nation_array.player_recno && attackerObj )		//BUGHERE
		news_array.firm_destroyed(firm_recno, attackerObj);

	// ######## begin Gilbert 17/6 ########//
	if( nation_recno == 0 && firm_id == FIRM_LAIR && is_monster() )
	{
		news_array.monster_firm_destroyed( monster_id(), center_x, center_y );
	}
	// ######## end Gilbert 17/6 ########//

	if( nation_recno )
	{
		if( attackerObj && attackerObj->nation_recno )
			nation_array[attackerObj->nation_recno]->enemy_firm_destroyed++;

		if( nation_recno )
			nation_array[nation_recno]->own_firm_destroyed++;
	}

	//-----------------------------------------//

	if( attackerObj && attackerObj->nation_recno )
	{
		Nation* attackerNation = nation_array[attackerObj->nation_recno];

		//-- destroying a monster firm raise the attacking nation's reputation --//

		if( is_monster() )
		{
			float repIncrease = (float) max_hit_points() / 600;

			//-- if the lair is enslaving the towns, increase the reputation bonus --//

			if( cast_to_FirmLair() )
			{
				int tributeAmount = cast_to_FirmLair()->collect_town_tribute(0);

				repIncrease += (float) tributeAmount / 600;
			}

			attackerNation->change_reputation(repIncrease);

			//--- when destroying an enslaving Fryhtan lair, the independent towns enslaved by it will reduce its resistance towards you by 30 points ---//

			if( cast_to_FirmLair() )
			{
				int   i;
				Town* townPtr;

				for( i=0 ; i<linked_town_count ; i++ )
				{
					if(town_array.is_deleted(linked_town_array[i]))
						continue;

					townPtr = town_array[linked_town_array[i]];

					//--- if it is a linked independent town ---//

					if( townPtr->nation_recno == 0 &&
						 // ####### begin Gilbert 9/3 ########//
						 nation_recno &&
						 // ####### end Gilbert 9/3 ########//
						 townPtr->resistance(nation_recno) < MONSTER_COLLECT_TOWN_TRIBUTE_LOYALTY )
					{
						townPtr->change_resistance(attackerObj->nation_recno, -30);
					}
				}
			}
		}

		//------ destroyng a building gives money ------//

		float killMoney = (float) (firm_res[firm_id]->setup_cost + firm_recno%100) / 3;		// add some randomness

		attackerNation->add_income( INCOME_TREASURE, killMoney );
		attackerNation->increased_cash = killMoney;
	}

	firm_array.del_firm(firm_recno);
}
Пример #30
0
//------- Begin of function Firm::draw_detect_link_line ---------//
//
// [int] actionDetect - 0 - this is a draw action
//								1 - this is a detect action
//                      (default: 0)
//
// return: <int> 1 - detected
//					  0 - not detected
//
int Firm::draw_detect_link_line(int actionDetect)
{
	if( firm_id == FIRM_INN ) 	// FirmInn's link is only for scan for neighbor inns quickly, the link line is not displayed
		return 0;

	//--------------------------------------//

	int 	i, firmX, firmY, townX, townY;
	Firm* firmPtr;
	Town* townPtr;
	FirmInfo* firmInfo = firm_res[firm_id];

	//-------- set source points ----------//

	int srcX = ( ZOOM_X1 + (loc_x1-world.zoom_matrix->top_x_loc) * ZOOM_LOC_WIDTH
				  + ZOOM_X1 + (loc_x2-world.zoom_matrix->top_x_loc+1) * ZOOM_LOC_WIDTH ) / 2;

	int srcY = ( ZOOM_Y1 + (loc_y1-world.zoom_matrix->top_y_loc) * ZOOM_LOC_HEIGHT
				  + ZOOM_Y1 + (loc_y2-world.zoom_matrix->top_y_loc+1) * ZOOM_LOC_HEIGHT ) / 2;

	//------ draw lines to linked firms ---------//

	int	lineType;
	char* bitmapPtr;

	for( i=0 ; i<linked_firm_count ; i++ )
	{
		firmPtr = firm_array[linked_firm_array[i]];

		firmX = ( ZOOM_X1 + (firmPtr->loc_x1-world.zoom_matrix->top_x_loc) * ZOOM_LOC_WIDTH
				  + ZOOM_X1 + (firmPtr->loc_x2-world.zoom_matrix->top_x_loc+1) * ZOOM_LOC_WIDTH ) / 2;

		firmY = ( ZOOM_Y1 + (firmPtr->loc_y1-world.zoom_matrix->top_y_loc) * ZOOM_LOC_HEIGHT
				  + ZOOM_Y1 + (firmPtr->loc_y2-world.zoom_matrix->top_y_loc+1) * ZOOM_LOC_HEIGHT ) / 2;

		anim_line.draw_line(&vga_back, srcX, srcY, firmX, firmY, linked_firm_enable_array[i]==LINK_EE );

		//----- check if this firm can toggle link or not -----//

		if( !can_toggle_firm_link(firmPtr->firm_recno) )
			continue;

		//------ if the link is switchable -------//

		bitmapPtr = power.get_link_icon( linked_firm_enable_array[i], nation_recno==firmPtr->nation_recno );

		if( actionDetect )
		{
			if( own_firm() && world.zoom_matrix->detect_bitmap_clip( firmX-11, firmY-11, bitmapPtr ) )
			{
				if( linked_firm_enable_array[i] & LINK_ED )
				{
					toggle_firm_link( i+1, 0, COMMAND_PLAYER );
					se_ctrl.immediate_sound("TURN_OFF");
				}
				else
				{
					toggle_firm_link( i+1, 1, COMMAND_PLAYER );
					se_ctrl.immediate_sound("TURN_ON");
				}
				return 1;
			}
		}
		else
		{
			if( nation_recno == nation_array.player_recno )
				world.zoom_matrix->put_bitmap_clip( firmX-11, firmY-11, bitmapPtr );
		}
	}

	//------ draw lines to linked towns ---------//

	for( i=0 ; i<linked_town_count ; i++ )
	{
		townPtr = town_array[linked_town_array[i]];

		townX = ( ZOOM_X1 + (townPtr->loc_x1-world.zoom_matrix->top_x_loc) * ZOOM_LOC_WIDTH
				  + ZOOM_X1 + (townPtr->loc_x2-world.zoom_matrix->top_x_loc+1) * ZOOM_LOC_WIDTH ) / 2;

		townY = ( ZOOM_Y1 + (townPtr->loc_y1-world.zoom_matrix->top_y_loc) * ZOOM_LOC_HEIGHT
				  + ZOOM_Y1 + (townPtr->loc_y2-world.zoom_matrix->top_y_loc+1) * ZOOM_LOC_HEIGHT ) / 2;

		if( worker_array && selected_worker_id &&
			 worker_array[selected_worker_id-1].town_recno == townPtr->town_recno )
		{
			lineType = -1;
			anim_line.thick_line(&vga_back, srcX, srcY, townX, townY, linked_town_enable_array[i]==LINK_EE, lineType );
		}
		else
		{
			lineType = 0;
			anim_line.draw_line(&vga_back, srcX, srcY, townX, townY, linked_town_enable_array[i]==LINK_EE, lineType );
		}

		//----- check if this firm can toggle link or not -----//

		if( !can_toggle_town_link() )
			continue;

		//--------- draw link symbol -----------//

		bitmapPtr = power.get_link_icon( linked_town_enable_array[i], nation_recno==townPtr->nation_recno );

		if( actionDetect )
		{
			int rc = world.zoom_matrix->detect_bitmap_clip( townX-11, townY-11, bitmapPtr );

			//------ left clicking to toggle link -------//

			if( rc==1 && own_firm() )
			{
				if( linked_town_enable_array[i] & LINK_ED )
				{
					toggle_town_link( i+1, 0, COMMAND_PLAYER );
					se_ctrl.immediate_sound("TURN_OFF");
				}
				else
				{
					toggle_town_link( i+1, 1, COMMAND_PLAYER );
					se_ctrl.immediate_sound("TURN_ON");
				}

				//
				// update RemoteMsg::firm_toggle_link_town()
				//
				if( firm_id == FIRM_CAMP && !remote.is_enable())
				{
					if( townPtr->nation_recno )
						townPtr->update_target_loyalty();
					else
						townPtr->update_target_resistance();

					townPtr->update_camp_link();
				}

				return 1;
			}

			//------ right clicking to move workers ------//

			else if( rc==2 && selected_worker_id > 0 )
			{
				//--- only when this worker is ours ----//

				if( firm_res[firm_id]->live_in_town &&
					 worker_array[selected_worker_id-1].is_nation(firm_recno, nation_array.player_recno) )
				{
					if(townPtr->population>=MAX_TOWN_POPULATION)
						return 0;

					set_worker_home_town(townPtr->town_recno, COMMAND_PLAYER);
					se_ctrl.immediate_sound("PULL_MAN");
					return 1;
				}
			}
		}
		else
		{
			if( nation_recno == nation_array.player_recno )
				world.zoom_matrix->put_bitmap_clip( townX-11, townY-11, bitmapPtr );
		}
	}

	return 0;
}