示例#1
0
文件: oun_act.cpp 项目: mecirt/7k2
//----------- Begin of function Unit::return_camp -----------//
//
// Order this unit to return to the camp. For ordering many
// units to return to a camp, UnitArray::return_camp() should
// be called instead.
//
int Unit::return_camp()
{
	if( !home_camp_firm_recno )
		return 0;

	err_when( firm_array.is_deleted(home_camp_firm_recno) );

	Firm* firmPtr = firm_array[home_camp_firm_recno];

	if( firmPtr->region_id != region_id() )
		return 0;

	err_when( !firmPtr->cast_to_FirmCamp() && !firmPtr->cast_to_FirmMonsterFortress() );
	err_when( firmPtr->nation_recno != nation_recno );

	//--------- assign now ---------//

	// ##### begin Gilbert 2/6 #########//
	assign(firmPtr->loc_x1, firmPtr->loc_y1, -1, true);

//	force_move_flag = 1;
	// ##### end Gilbert 2/6 #########//

	return cur_action != SPRITE_IDLE;
}
示例#2
0
//--------- Begin of function Nation::ai_assign_spy_to_firm --------//
//
// Think about sending spies to the specific firm.
//
// return: <int> 1 - a spy is assigned successfully.
// 				  0 - failure.
//
int Nation::ai_assign_spy_to_firm(int firmRecno)
{
	Firm* firmPtr = firm_array[firmRecno];

	err_when( !firmPtr->worker_array );

	//---- check if the firm is full or not -----//

	if( firmPtr->nation_recno == nation_recno )	// if it's our own firm
	{
		if( firmPtr->is_worker_full() )	// use is_worker_full() for own firms as it take into account of units patrolling outside
			return 0;
	}
	else
	{
		if( firmPtr->worker_count == MAX_WORKER )
			return 0;
	}

	//------ look for an existing spy -------//

	int raceId	   = firmPtr->majority_race();
	int mobileOnly = firmPtr->nation_recno == nation_recno;   // if assign to own firms/firms, only get mobile spies, don't get spies from existing firms/firms as that will result in a loop effect

	return ai_assign_spy( firmPtr->loc_x1, firmPtr->loc_y1, raceId, mobileOnly );
}
示例#3
0
文件: otownlnk.cpp 项目: mecirt/7k2
//------- Begin of function Town::release_link ---------//
//
void Town::release_link()
{
   int i;
	Firm *firmPtr;
	Town *townPtr;

   //------ release linked firms ------//

	for( i=0 ; i<linked_firm_count ; i++ )
	{
		firmPtr = firm_array[linked_firm_array[i]];
		firmPtr->release_town_link(town_recno);
		
		if(firmPtr->is_ai)
			firmPtr->ai_link_checked = 0;

		if( firmPtr->active_link_town_recno == town_recno )
			firmPtr->active_link_town_recno = 0;
   }

   //------ release linked towns ------//

   for( i=0 ; i<linked_town_count ; i++ )
   {
		townPtr = town_array[linked_town_array[i]];
		townPtr->release_town_link(town_recno);
		
		if(townPtr->ai_town)
			townPtr->ai_link_checked = 0;
	}
}
示例#4
0
文件: otownlnk.cpp 项目: mecirt/7k2
//----- Begin of function Town::update_camp_link -----//
//
// Update the status of links from this town to camps.
//
void Town::update_camp_link()
{
	//--- enable the link of the town's side to all linked camps ---//

	Firm* firmPtr;

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

		 if( !firmPtr->cast_to_FirmCamp() )	 
			 continue;

		 //--- don't set it if the town and camp both belong to a human player, the player will set it himself ---//

		 if( firmPtr->nation_recno == nation_recno &&
			  nation_recno && !nation_array[nation_recno]->is_ai() )
		 {
			 continue;
		 }

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

		 toggle_firm_link( i+1, 1, COMMAND_AUTO );
	}

	//------- update camp link status -------//

	has_linked_own_camp = 0;
	has_linked_enemy_camp = 0;

	for( i=0 ; i<linked_firm_count ; i++ )
	{
		if( linked_firm_enable_array[i] != LINK_EE )
			continue;

		firmPtr = firm_array[linked_firm_array[i]];

		if( !firmPtr->cast_to_FirmCamp() || 
			firmPtr->cast_to_FirmCamp()->overseer_recno == 0 )
		{
			continue;
		}

		if( firmPtr->nation_recno == nation_recno )
			has_linked_own_camp = 1;
		else
			has_linked_enemy_camp = 1;
	}
}
示例#5
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;
}
示例#6
0
文件: ospya.cpp 项目: mecirt/7k2
//--------- Begin of function SpyArray::update_firm_spy_count ---------//
//
// Update the player_spy_count of this firm. This function is called
// when the firm change its nation.
//
// <int> firmRecno - recno of the firm to be updated.
//
void SpyArray::update_firm_spy_count(int firmRecno)
{
	//---- recalculate Firm::player_spy_count -----//

	Spy*  spyPtr;
	Firm* firmPtr = firm_array[firmRecno];

	if( firmPtr->cast_to_FirmCamp() )
	{
		FirmCamp *firmCamp = firmPtr->cast_to_FirmCamp();
		firmCamp->player_spy_count = 0;
		for( int i=spy_array.size() ; i>0 ; i-- )
		{
			if( spy_array.is_deleted(i) )
				continue;

			spyPtr = spy_array[i];

			if( spyPtr->spy_place == SPY_FIRM &&
				 spyPtr->spy_place_para == firmRecno &&
				 spyPtr->true_nation_recno == nation_array.player_recno )
			{
				firmCamp->player_spy_count++;
			}
		}
	}
	else if( firmPtr->cast_to_FirmTrain() )
	{
		FirmTrain *firmTrain = firmPtr->cast_to_FirmTrain();
		firmTrain->player_spy_count = 0;
		for( int i=spy_array.size() ; i>0 ; i-- )
		{
			if( spy_array.is_deleted(i) )
				continue;

			spyPtr = spy_array[i];

			if( spyPtr->spy_place == SPY_FIRM &&
				 spyPtr->spy_place_para == firmRecno &&
				 spyPtr->true_nation_recno == nation_array.player_recno )
			{
				firmTrain->player_spy_count++;
			}
		}
	}

	return;
}
示例#7
0
文件: OR_TOWN.cpp 项目: AMDmi3/7kaa
static void calc_firm_total()
{
	//-------- calculate firm incomes --------//

	total_firm_income = 0;

	memset( firm_income_array, 0, sizeof(firm_income_array) );

	int   thisIncome;
	Firm* firmPtr;

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

		firmPtr = firm_array[i];

		if( firmPtr->nation_recno == info.viewing_nation_recno )
		{
			thisIncome = (int) firmPtr->income_365days();

			if( thisIncome > 0 )
			{
				firm_income_array[firmPtr->firm_id-1] += thisIncome;
				total_firm_income += thisIncome;
			}
		}
	}

	//------ calculate total firm cost --------//

	total_firm_count = 0;
	total_firm_cost  = 0;

	FirmInfo* firmInfo;

	for( i=1 ; i<=MAX_FIRM_TYPE ; i++ )
	{
		firmInfo = firm_res[i];

		total_firm_cost += firmInfo->year_cost *
								 firmInfo->nation_firm_count_array[info.viewing_nation_recno-1];

		total_firm_count += firmInfo->nation_firm_count_array[info.viewing_nation_recno-1];
	}
}
示例#8
0
//-------- Begin of function Nation::think_assign_spy_target_camp --------//
//
// Think about planting spies into independent towns and enemy towns.
//
int Nation::think_assign_spy_target_camp(int raceId, int regionId)
{
	Firm  *firmPtr;
	int	curRating, bestRating=0, bestFirmRecno=0;

	for( int firmRecno=firm_array.size() ; firmRecno>0 ; firmRecno-- )
	{
		if( firm_array.is_deleted(firmRecno) )
			continue;

		firmPtr = firm_array[firmRecno];

		if( firmPtr->nation_recno == nation_recno )		// don't assign to own firm
			continue;

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

		if( firmPtr->overseer_recno == 0 ||
			 firmPtr->worker_count == MAX_WORKER )
		{
			continue;
		}

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

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

		Unit* overseerUnit = unit_array[firmPtr->overseer_recno];

		if( overseerUnit->spy_recno )		// if the overseer is already a spy
			continue;

		curRating = 100 - overseerUnit->loyalty;

		if( curRating > bestRating )
		{
			bestRating 	  = curRating;
			bestFirmRecno = firmRecno;
		}
	}

	return bestFirmRecno;
}
示例#9
0
文件: otownlnk.cpp 项目: mecirt/7k2
//----- Begin of function Town::has_linked_camp -----//
//
// Return whether there is a camp of the specific nation
// linked to this town.
//
// <int> nationRecno  - recno of the nation.
// <int> needOverseer - whether only count camps with overseers or not.
//
int Town::has_linked_camp(int nationRecno, int needOverseer)
{
	Firm* firmPtr;

	for( int i=0 ; i<linked_firm_count ; i++ )
	{
		firmPtr = firm_array[ linked_firm_array[i] ];
	
		if( firmPtr->cast_to_FirmCamp() &&
			 firmPtr->nation_recno == nationRecno )
		{
			if( !needOverseer || firmPtr->cast_to_FirmCamp()->overseer_recno )
				return 1;
		}
	}

	return 0;
}
示例#10
0
//-------- Begin of function Town::think_capture_linked_firm --------//
//
// Try to capture firms linked to this town if all the workers in firms
// resident in this town. 
//
void Town::think_capture_linked_firm()
{
	Firm* firmPtr;

	//----- scan for linked firms -----//

	for( int i=linked_firm_count-1 ; i>=0 ; i-- )
	{
		firmPtr = firm_array[ linked_firm_array[i] ];

		if( firmPtr->nation_recno == nation_recno )		// this is our own firm
			continue;

		if( firmPtr->can_worker_capture(nation_recno) )	// if we can capture this firm, capture it now
		{
			firmPtr->capture_firm(nation_recno);
		}
	}
}
示例#11
0
void Graph::addFirms(int cycleNum, std::vector<Firm*> firms){
     for(int i = 0; i < firms.size();i++){
             std::string dk = getDataKey("type","firm");
             dk += getDataKey("cycleNum",intToStr(cycleNum));
             Firm* firm = firms.at(i);
             dk+= getDataKey("numIndividuals",intToStr((int)firm->employees.size()));
             dk+= getDataKey("avgProductivity",intToStr(firm->getproductivity()));
             dk+= getDataKey("unitsLeft",intToStr((int)firm->unitsLeft));
             dk+= getDataKey("capital",intToStr(firm->capital));
             dk+= getDataKey("firmId",intToStr(firm->id));
             addNode(dk,"Cycle-"+intToStr(cycleNum)+"-Firm-"+intToStr(firm->id)); 
             std::string thisCycle = cycles.at(cycles.size()-1).id;
             std::string thisFirm = nodes.at(nodes.size()-1).id;
             addEdge(thisCycle,thisFirm, str_existsin,(str_existsin+"-"+intToStr(cycleNum))); 
             
             
             addIndividuals(cycleNum,firm,thisFirm); 
     }
     buildTrades(cycleNum,firms);
}
示例#12
0
文件: oun_info.cpp 项目: mecirt/7k2
//--------- 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;
}
示例#13
0
文件: oc_pld1.cpp 项目: 112212/7k2
void CampaignEastWest::plot_d1_create_game()
{
	// reduce cash

	(~nation_array)->cash = (~nation_array)->cash / 4;

	// reduce mineral if the mine is owned by the player

	for( int i = 1; i <= site_array.size(); ++i )
	{
		if( site_array.is_deleted(i) )
			continue;

		Site *sitePtr = site_array[i];
		if( sitePtr->site_type == SITE_RAW && sitePtr->has_mine )
		{
			Location *locPtr = world.get_loc(sitePtr->map_x_loc, sitePtr->map_y_loc);
			err_when( !locPtr->is_firm() );
			Firm *firmPtr = firm_array[locPtr->firm_recno()];
			if( firmPtr->is_own() )
			{
				sitePtr->reserve_qty = sitePtr->reserve_qty / 10;

				if( firmPtr->cast_to_FirmMine() )
				{
					firmPtr->cast_to_FirmMine()->reserve_qty = (float)sitePtr->reserve_qty;
				}
				else if( firmPtr->cast_to_FirmMonsterAlchemy() )
				{
					firmPtr->cast_to_FirmMonsterAlchemy()->reserve_qty = (float)sitePtr->reserve_qty;
				}
			}
		}
	}
}
示例#14
0
文件: ofirma.cpp 项目: mecirt/7k2
//--------- Begin of function FirmArray::del_firm ---------//
//
// Warning : After calling this function, the recno() is still
//           pointing to the deleted record.
//           So go() to a new record to prevent running NULL object
//
// <int> recNo = the no. of the record to be deleted
//               (default : current record no.)
//
void FirmArray::del_firm(int recNo)
{
   Firm* firmPtr = firm_array[recNo];

	//--- del its link from base_obj_array ----//

	base_obj_array.del(firmPtr->base_obj_recno);

	//---- delete the object and detach it from firm_array ---//

	int	xLoc = firmPtr->center_x;
	int	yLoc = firmPtr->center_y;

	if( !sys.quick_exit_flag() )
		firmPtr->deinit();

	delete firmPtr;

	linkout(recNo);

//	world.plant_limit = world.plant_limit + m.random(5);
}
示例#15
0
文件: ofirma.cpp 项目: mecirt/7k2
//--------- Begin of function FirmArray::next_year ---------//
//
void FirmArray::next_year()
{
	int	 i;
	Firm*  firmPtr;

	LOG_MSG("begin FirmArray::next_year");
	LOG_MSG(m.get_random_seed() );
	for(i=1; i <=size() ; i++)
	{
		firmPtr = (Firm*)get_ptr(i);

		if( firmPtr && !firmPtr->under_construction )
		{
			LOG_MSG("Firm next_month");
			LOG_MSG( i );
			firmPtr->next_year();
			LOG_MSG(m.get_random_seed() );
		}
	}
	LOG_MSG("end FirmArray::next_year");
	LOG_MSG(m.get_random_seed() );
}
示例#16
0
文件: of_war.cpp 项目: 7k2/7k2
// ---------- Begin of function FirmWar::can_set_rally_point ------//
//
// whether the firm can set rally point
//
// [int] destBaseObjRecno		- destination base obj recno, 0 for setting position
//
int FirmWar::can_set_rally_point(int destBaseObjRecno)
{
    if( destBaseObjRecno == 0 )
    {
        return 1;
    }
    else
    {
        if( base_obj_array.is_deleted(destBaseObjRecno) )
            return 0;

        Firm *firmPtr = base_obj_array[destBaseObjRecno]->cast_to_Firm();
        if( firmPtr )
        {
            if( firmPtr->cast_to_FirmCamp() )
            {
                return 1;
            }
        }
    }

    return 0;
}
示例#17
0
文件: otownlnk.cpp 项目: mecirt/7k2
//-------- Begin of function Town::linked_camp_count ------//
//
// Return the number of linked military camp to this town.
//
// <bool> hasOverseer - only count the camps with an overseer.
//
int Town::linked_camp_count(bool hasOverseer)
{
	int 	i, linkedCount=0;
	Firm* firmPtr;

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

			if( firmPtr->cast_to_FirmCamp() )
			{
				if( !hasOverseer || firmPtr->cast_to_FirmCamp()->overseer_recno )
				{
					linkedCount++;
				}
			}
		}
	}

	return linkedCount;
}
示例#18
0
文件: ou_carai.cpp 项目: mecirt/7k2
//--------- Begin of static function i_button_go_stop ---------//
//
static void i_button_go_stop(ButtonCustom *button, int repaintBody)
{
	Firm *firmPtr = NULL;
	if( !firm_array.is_deleted(button->custom_para.value) )
	{
		firmPtr = firm_array[button->custom_para.value];
	}

	vga.active_buf->put_bitmap( button->x1, button->y1, 

		// button resource name
		image_button.read( button->pushed_flag ? (char*)"CARA-STD" :
			mouse.in_area(button->x1, button->y1, button->x2, button->y2) ? (char*)"CARA-STH" : (char*)"CARA-STU" ),

		// remap table
		game.get_color_remap_table( (!firmPtr ? 0 : firmPtr->nation_recno), 0) );

	// put destination marker
	{
		UnitCaravan *unitPtr = (UnitCaravan *)button->custom_para.ptr;
		if( unitPtr->dest_stop_id > 0 && unitPtr->dest_stop_id <= MAX_STOP_FOR_CARAVAN 
			&& unitPtr->stop_array[unitPtr->dest_stop_id-1].firm_recno == button->custom_para.value )
		{
			vga.active_buf->put_bitmap_trans_decompress( button->x1+18, button->y1+6,
				image_button.read("TRI-R") );
		}
	}

	// put firm name

	if( firmPtr )
	{
		font_snds.put_paragraph( button->x1+34, button->y1+5+(button->pushed_flag?1:0), 
			button->x2-5, button->y2-5+(button->pushed_flag?1:0),
			firmPtr->firm_name() );
	}
}
示例#19
0
文件: otornado.cpp 项目: 112212/7k2
//------- Begin of function Tornado::hit_building -----//
//	building means firm or town
//
void Tornado::hit_building()
{
	short damageXLoc = damage_x_loc();
	short damageYLoc = damage_y_loc();
	if( damageXLoc < 0 || damageXLoc >= world.max_x_loc ||
		damageYLoc < 0 || damageYLoc >= world.max_y_loc)
		return;

	Location* locPtr = world.get_loc(damageXLoc, damageYLoc);

	if(locPtr->is_firm() )
//		&& firm_res[(firmPtr=firm_array[locPtr->firm_recno()])->firm_id]->buildable )
	{
		Firm *firmPtr = firm_array[locPtr->firm_recno()];
		firmPtr->hit_points -= attack_damage*2;

		if( !damage_player_flag && firmPtr->is_own() )
		{
			damage_player_flag = 1;
			// add news message
			news_array.tornado_hit(sprite_recno);
		}

		if( firmPtr->hit_points <= 0)
		{
			firmPtr->hit_points = (float) 0;

			se_res.sound(firmPtr->center_x, firmPtr->center_y, 1,
				'F', firmPtr->firm_id, "DIE" );

			firm_array.del_firm(locPtr->firm_recno());
		}
	}

	if( locPtr->is_town() )
	{
		Town *townPtr = town_array[locPtr->town_recno()];

		if( !damage_player_flag && townPtr->is_own() )
		{
			damage_player_flag = 1;
			// add news message
			news_array.tornado_hit(sprite_recno);
		}

		if( townPtr->hit_points > 0.0f )
		{
			townPtr->hit_points -= attack_damage*2;
			if( townPtr->hit_points <= 0 )
			{
				townPtr->hit_points = (float) 0;
			}
		}
		else
		{
			// ###### begin Gilbert 10/2 #######//
			if( (life_time % 10) == 0 ) 
				townPtr->kill_town_people(0);
			// ###### end Gilbert 10/2 #######//
		}
	}
}
示例#20
0
文件: OTOWNDRW.cpp 项目: brianV/7kaa
//------- Begin of function Town::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 Town::draw_detect_link_line(int actionDetect)
{
	int 	i, firmX, firmY, townX, townY;
	Firm* firmPtr;
	Town* townPtr;

	//-------- 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 ---------//

	char* bitmapPtr;
	char  goodLinkName[9] = "GOODLINK";

	goodLinkName[7] = '1'+(char)(sys.frame_count%3);

	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 );

		if( !can_toggle_firm_link(linked_firm_array[i]) )
			continue;

		//------ draw the link icon and detect mouse action -----//

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

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

			if( rc )
				mouse.reset_click();		// reset queued mouse click for fast single clicking

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

			if( rc==1 && nation_recno==nation_array.player_recno )
			{
				if( linked_firm_enable_array[i] & LINK_ED )
				{
					toggle_firm_link( i+1, 0, COMMAND_PLAYER );
					// ###### begin Gilbert 25/9 #######//
					se_ctrl.immediate_sound("TURN_OFF");
					// ###### end Gilbert 25/9 #######//
				}
				else
				{
					toggle_firm_link( i+1, 1, COMMAND_PLAYER );
					// ###### begin Gilbert 25/9 #######//
					se_ctrl.immediate_sound("TURN_ON");
					// ###### end Gilbert 25/9 #######//

				}

				// ######## begin Gilbert 23/9 ##########//
				if( firmPtr->firm_id == FIRM_CAMP && !remote.is_enable())
				// ######## end Gilbert 23/9 ##########//
				{
					if( nation_recno )
						update_target_loyalty();
					else
						update_target_resistance();

               update_camp_link();
				}

				return 1;
			}

			//------ right clicking to recruit soldiers ------//

			else if( rc==2 )
			{
				if( firmPtr->nation_recno == nation_recno && !firmPtr->under_construction &&
					 firmPtr->worker_array && firmPtr->worker_count < MAX_WORKER )
				{
					firmPtr->pull_town_people(town_recno, COMMAND_PLAYER, browse_selected_race_id(), 1);			// last 1-force pulling people from the town to the firm
					// ###### begin Gilbert 25/9 #######//
					se_ctrl.immediate_sound("PULL_MAN");
					// ###### end Gilbert 25/9 #######//
				}
			}
		}
		else
		{
			if( nation_recno == nation_array.player_recno )
				world.zoom_matrix->put_bitmap_clip( firmX-11, firmY-11, bitmapPtr );
		}
	}

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

	int townRecno;

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

		townPtr = town_array[townRecno];

		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;

		anim_line.draw_line(&vga_back, srcX, srcY, townX, townY, linked_town_enable_array[i]==LINK_EE );

		//------- detect on the migration icon -------//

		if( nation_recno == nation_array.player_recno &&
			 nation_recno == townPtr->nation_recno &&
			 can_migrate(townRecno) )
		{
			bitmapPtr = image_icon.get_ptr("MIGRATE");

			if( actionDetect )
			{
				if( world.zoom_matrix->detect_bitmap_clip( townX-11, townY-11, bitmapPtr ) )
				{
					mouse.reset_click();		// reset queued mouse click for fast single clicking

					err_when(town_array[townRecno]->population>MAX_TOWN_POPULATION);
					migrate_to(townRecno, COMMAND_PLAYER);
					// ###### begin Gilbert 25/9 #######//
					se_ctrl.immediate_sound("PULL_MAN");
					// ###### end Gilbert 25/9 #######//
					return 1;
				}
			}
			else
			{
				world.zoom_matrix->put_bitmap_clip( townX-11, townY-11, bitmapPtr );
			}
		}
	}

	return 0;
}
示例#21
0
文件: otownlnk.cpp 项目: mecirt/7k2
//------- Begin of function Town::setup_link ---------//
//
void Town::setup_link()
{
	//-----------------------------------------------------------------------------//
	// check the connected firms location and structure if ai_link_checked is true
	//-----------------------------------------------------------------------------//

	if(ai_town)
		ai_link_checked = 0;

	//----- build town-to-firm link relationship -------//

	int   firmRecno;
	Firm* firmPtr;
	FirmInfo* firmInfo;

	linked_firm_count = 0;

	for( firmRecno=firm_array.size() ; firmRecno>0 ; firmRecno-- )
	{
		if( firm_array.is_deleted(firmRecno) )
			continue;

		firmPtr  = firm_array[firmRecno];
		firmInfo = firm_res[firmPtr->firm_id];

		if( !firmInfo->is_linkable_to_town )
			continue;

		//----- only linkable if the firm and the town belong to the same nation or the firm can influence a foreign town, i.e. Camp, Fort and Fryhtan Lair,

		if( nation_recno==0 )
		{
			//--- independent towns can linked to work firms and markets ---//

			if( !firmPtr->cast_to_FirmWork() && !firmPtr->cast_to_FirmMarket()
				 && !firmPtr->cast_to_FirmCamp() )
			{
				continue;
			}
		}
		else
		{
			//--- nation towns can only linked to own firms or camps -------//

			if( firmPtr->nation_recno != nation_recno && !firmPtr->cast_to_FirmCamp() )
				continue;
		}

		//---------- check if the firm is close enough to this firm -------//

		if( m.points_distance( firmPtr->center_x, firmPtr->center_y, center_x, center_y )
			 > world.effective_distance(firmPtr->firm_id, 0) )
		{
			continue;
		}

		//------ check if both are on the same terrain type ------//

		if( (world.get_loc(firmPtr->loc_x1, firmPtr->loc_y1)->is_plateau()==1)
			 != (world.get_loc(loc_x1, loc_y1)->is_plateau()==1) )
		{
			continue;
		}

		//----- if the firm requires same race -------//

		if( !firm_res.is_linkable_to_town(firmPtr->firm_id, firmPtr->race_id, race_id) )
			continue;

		//------- determine default link flag -------//

		int defaultLinkStatus = LINK_EE;

		if( nation_recno==0 )		// if this is an independent town
		{
			if( firmPtr->nation_recno==0 || resistance(firmPtr->nation_recno) > INDEPENDENT_LINK_RESISTANCE )
				defaultLinkStatus = LINK_DD;
		}

		//-------- add the link now -------//

		if( linked_firm_count < MAX_LINKED_FIRM_TOWN )
		{
			err_when( linked_firm_count>0 && linked_firm_array[linked_firm_count-1] == firmRecno );		// BUGHERE - check double linking error

			linked_firm_array[linked_firm_count] = firmRecno;
			linked_firm_enable_array[linked_firm_count] = defaultLinkStatus;

			linked_firm_count++;
		}
		else
		{
			err_here();
		}

		if( firmPtr->linked_town_count < MAX_LINKED_TOWN_TOWN )
		{
			firmPtr->linked_town_array[firmPtr->linked_town_count] = town_recno;
			firmPtr->linked_town_enable_array[firmPtr->linked_town_count] = defaultLinkStatus;

			firmPtr->linked_town_count++;

			if(firmPtr->is_ai)
				firmPtr->ai_link_checked = 0;
		}
		else
		{
			err_here();
		}
	}

	//----- build town-to-town link relationship -------//

	linked_town_count = 0;

	int   townRecno;
	Town* townPtr;

	for( townRecno=town_array.size() ; townRecno>0 ; townRecno-- )
	{
		if( town_array.is_deleted(townRecno) || townRecno==town_recno )
			continue;

		townPtr = town_array[townRecno];

		//----- if the firm requires same race -------//

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

		//------ check if the town is close enough to this firm -------//

		if( m.points_distance( townPtr->center_x, townPtr->center_y,
			 center_x, center_y ) > world.effective_distance(0, 0) )
		{
			continue;
		}

		//------ check if both are on the same terrain type ------//

		if( (world.get_loc(townPtr->loc_x1, townPtr->loc_y1)->is_plateau()==1)
			 != (world.get_loc(loc_x1, loc_y1)->is_plateau()==1) )
		{
			continue;
		}

		//-------- link this town -------//

		if( linked_town_count < MAX_LINKED_TOWN_TOWN )
		{
			linked_town_array[linked_town_count] = townRecno;
			linked_town_enable_array[linked_town_count] = LINK_EE;

			linked_town_count++;
		}
		else
		{
			err_here();
		}

		//-------- link the other town  -------//

		if( townPtr->linked_town_count < MAX_LINKED_TOWN_TOWN )
		{
			townPtr->linked_town_array[townPtr->linked_town_count] = town_recno;
			townPtr->linked_town_enable_array[townPtr->linked_town_count] = LINK_EE;

			townPtr->linked_town_count++;

			if(townPtr->ai_town)
				townPtr->ai_link_checked = 0;
		}
		else
		{
			err_here();
		}
	}
}
示例#22
0
文件: oplace.cpp 项目: 112212/7k2
//-------- Begin of function Place::invoke_camp_defense ---------//
//
// Call out defenders from neighboring camps to help.
//
void Place::invoke_camp_defense(BaseObj* attackerObj)
{
	if( !attackerObj )
		return;

	//----- if this is an independent town -----//

	if( !nation_recno )
	{
		//---- if this is a slave town ----//

		if( cast_to_Town() && cast_to_Town()->is_pay_tribute_to_monster() )
		{
			//---- reckon the net attacking power in the battling area ----//

			int hasWar;			// ref var for returning the result

			int netAttackerPower = world.net_attacker_power_in_area(center_x, center_y,
									  attackerObj->nation_recno, nation_recno, 0, hasWar, EFFECTIVE_DEFEND_DISTANCE);

			//-- no need to call for reinforcement if the defense force is more powerful than the attacking force --//

			if( netAttackerPower <= 0 )
				return;

			//------ call enslaving lair's AI to protect it ------//

			Town* thisTown = cast_to_Town();

			for( int i=0 ; i<thisTown->linked_firm_count ; i++ )
			{
				//--- if this linked firm is a lair enslaving the town ---//

				if( thisTown->tribute_to_lair( thisTown->linked_firm_array[i], 1 ) )
				{
					FirmLair* firmLair = firm_array[ thisTown->linked_firm_array[i] ]->cast_to_FirmLair();

					if( firmLair && firmLair->is_ai )
						firmLair->invoke_defense(attackerObj, netAttackerPower);
				}
			}
		}

		return;
	}

	//---- reckon the net attacking power in the battling area ----//

	int hasWar;			// ref var for returning the result

	int netAttackerPower = world.net_attacker_power_in_area(center_x, center_y,
							  attackerObj->nation_recno, nation_recno, 0, hasWar, EFFECTIVE_DEFEND_DISTANCE);

	//-- no need to call for reinforcement if the defense force is more powerful than the attacking force --//

	if( netAttackerPower <= 0 )
		return;

	//--------- call for reinforcement now -------//

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

		Firm* firmPtr = firm_array[i];

		//--- look for our camp ----//

		// ###### begin Gilbert 15/4 #########//
		// if( !firmPtr->cast_to_FirmCamp() || firmPtr->nation_recno!=nation_recno )
		if( !firmPtr->cast_to_FirmCamp() || firmPtr->nation_recno!=nation_recno || nation_recno == 0 )
		// ###### end Gilbert 15/4 #########//
			continue;

		//--- only if the camp's within the effective defense distance ---//

		if( misc.points_distance(firmPtr->center_x, firmPtr->center_y, center_x, center_y )
			 > EFFECTIVE_DEFEND_DISTANCE )
		{
			continue;
		}

		//----- ask the camp to send out defenders now ------//

		int defensePower = firmPtr->cast_to_FirmCamp()->invoke_defense(attackerObj, netAttackerPower);

		netAttackerPower -= defensePower;

		if( netAttackerPower <= 0 )
			break;
	}
}
示例#23
0
//-------- Begin of function Nation::hire_best_capturer ------//
//
// Hire the best unit you can find in one of the existing inns.
//
// <int>  townRecno 			    - recno of the town to capture
// <int>  raceId				    - race id. of the unit to hire
//
// return: <int> the recno of the unit hired.
//
int Nation::hire_best_capturer(int townRecno, int raceId)
{
	if( !ai_should_hire_unit(30) )		// 30 - importance rating
		return 0;

	FirmInn	*firmInn;
	Firm		*firmPtr;
	InnUnit *innUnit;
	Skill		*innUnitSkill;
	int		i, j, innUnitCount, curRating;
	int		bestRating=0, bestInnRecno=0, bestInnUnitId=0;
	Town* 	townPtr = town_array[townRecno];
	int		destRegionId = world.get_region_id(townPtr->loc_x1, townPtr->loc_y1);

	for(i=0; i<ai_inn_count; i++)
	{
		firmPtr = (FirmInn*) firm_array[ai_inn_array[i]];

		err_when( firmPtr->firm_id != FIRM_INN );

		if( firmPtr->region_id != destRegionId )
			continue;

		firmInn = firmPtr->cast_to_FirmInn();

		innUnitCount=firmInn->inn_unit_count;

		if( !innUnitCount )
			continue;

		innUnit = firmInn->inn_unit_array + innUnitCount - 1;

		//------- check units in the inn ---------//

		for(j=innUnitCount; j>0; j--, innUnit--)
		{
			innUnitSkill = &(innUnit->skill);

			if( innUnitSkill->skill_id==SKILL_LEADING &&
				 unit_res[innUnit->unit_id]->race_id == raceId &&
				 cash >= innUnit->hire_cost )
			{
				//----------------------------------------------//
				// evalute a unit on:
				// -its race, whether it's the same as the nation's race
				// -the inn's distance from the destination
				// -the skill level of the unit.
				//----------------------------------------------//

				curRating = innUnitSkill->skill_level;

				if( curRating > bestRating )
				{
					bestRating = curRating;

					bestInnRecno  = firmInn->firm_recno;
					bestInnUnitId = j;
				}
			}
		}
	}

	if( !bestInnUnitId )
		return 0;

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

	firmInn = (FirmInn*) firm_array[bestInnRecno];

	int unitRecno = firmInn->hire(bestInnUnitId);

	if( !unitRecno )
		return 0;

	unit_array[unitRecno]->set_rank(RANK_GENERAL);

	return unitRecno;
}
示例#24
0
文件: ofirma.cpp 项目: mecirt/7k2
//--------- Begin of function FirmArray::process ---------//
//
// Process all firm in firm_array for action and movement for next frame
//
// Return : 1 - all firm in the FirmArray has been processed
//          0 - only some has been processed, not all
//
int FirmArray::process()
{
   int  i;
	Firm *firmPtr;

	// ####### begin Gilbert 19/11 ######//
	if( sys.day_frame_count == 0 )
	{
		god_res.update_prayer_count();		// count no. of prayer of each god, each nation
	}
	// ####### end Gilbert 19/11 ######//

	//----- each time process some firm only ------//

	for( i=1 ; i<=size() ; i++ )
	{
		firmPtr = (Firm*) get_ptr(i);

		if( !firmPtr )    // the firm has been deleted
			continue;

		err_when(firmPtr->firm_recno!=i);

		//-------- system yield ---------//

		if( i%20==1 )
			sys.yield();

#if defined(ENABLE_LOG)
		String logStr;
		logStr = "begin process firm ";
		logStr += firmPtr->firm_recno;
		logStr += " nation=";
		logStr += firmPtr->nation_recno;
		LOG_MSG(logStr);
#endif
	
		if(i==50)
		{

			FirmMarket *mPtr = (FirmMarket*) firmPtr;
			MarketGoods *marketGoods = mPtr->market_goods_array;
			marketGoods++;

			if(marketGoods->stock_qty)
				int debug = 0;
		}

		// ##### begin Gilbert 18/5 ########//

		//-------- process visibility -----------//

		if( i%FRAMES_PER_DAY == int(sys.frame_count%FRAMES_PER_DAY) )	// only process each firm once per day
		{
			// before under construction checking 

			if( firmPtr->explore_for_player() )
			{
				world.visit( firmPtr->loc_x1, firmPtr->loc_y1, firmPtr->loc_x2, firmPtr->loc_y2, EXPLORE_RANGE-1 );
			}
		}
		// ##### begin Gilbert 18/5 ########//


		//------ if the firm is under construction ------//

		if( firmPtr->under_construction )
		{
			LOG_MSG(" process_construction");
			firmPtr->process_construction();
			LOG_MSG(m.get_random_seed() );
			continue;
		}

		//------ if the firm is being upgrade ------//

		if( firmPtr->upgrading_firm_id )
		{
			if( firmPtr->process_upgrade() )
				continue;
		}

		// ###### begin Gilbert 4/1 #######//
		firmPtr->process();
		// ###### end Gilbert 4/1 #######//

		//--------- process and process_ai firms ----------//

		if( i%FRAMES_PER_DAY == int(sys.frame_count%FRAMES_PER_DAY) )	// only process each firm once per day
		{
			#ifdef DEBUG
			unsigned long profileStartTime = m.get_time();
			#endif

//			//-------- process visibility -----------//
//
//			if( firmPtr->explore_for_player() )
//			{
//				world.visit( firmPtr->loc_x1, firmPtr->loc_y1, firmPtr->loc_x2, firmPtr->loc_y2, EXPLORE_RANGE-1 );
//			}

			LOG_MSG(" next_day");
			firmPtr->next_day();
			LOG_MSG(m.get_random_seed() );

			#ifdef DEBUG
			firm_profile_time += m.get_time() - profileStartTime;
			#endif

			//-- if the hit points drop to zero, the firm should be deleted --//

			if( firmPtr->hit_points <=0 )
			{
				se_res.sound( firmPtr->center_x, firmPtr->center_y, 1, 'F', firmPtr->firm_id, "DEST" );
				del_firm( firmPtr->firm_recno );
				continue;
			}

			//--------- process AI ------------//

			#ifdef DEBUG
			if( config.disable_ai_flag==0 && firmPtr->is_ai )
			#else
			if( firmPtr->is_ai )
			#endif
			{
				LOG_MSG(" process_common_ai");
				firmPtr->process_common_ai();
				LOG_MSG(m.get_random_seed() );

				#ifdef DEBUG
				unsigned long profileAiStartTime = m.get_time();
				#endif

				LOG_MSG(" process_ai");
				firmPtr->process_ai();
				LOG_MSG(m.get_random_seed());

				#ifdef DEBUG
				firm_ai_profile_time += m.get_time() - profileAiStartTime;
				#endif

				if( is_deleted(i) )		// the firm may have been deleted in process_ai()
					continue;
			}
		}

		//-------- process animation ---------//

		LOG_MSG(" process_animation");
		firmPtr->process_animation();
		LOG_MSG( m.get_random_seed() );

		//-------- process monster firm ---------//

		LOG_MSG(" process_animation");
		firmPtr->process_monster_firm();
		LOG_MSG( m.get_random_seed() );

	}

	return 0;
}
示例#25
0
文件: ounadraw.cpp 项目: 112212/7k2
//--------- Begin of function UnitArray::draw_dot ---------//
//
// Draw 2x2 tiny squares on map window representing the location of the unit ---//
//
// [int] filterUnitClassId - if given, only display units whose type is filterUnitClassId
//
void UnitArray::draw_dot(int filterUnitClassId)
{
	int		i, j, mapX, mapY;
	short		nationColor;
	int		vgaBufPitch = vga_back.buf_pitch();
	short		playerNationRecno = nation_array.player_recno;

	short		lineFromX, lineFromY, lineToX, lineToY;

	short unexploredColor = vga_back.translate_color(UNEXPLORED_COLOR);
	short	nationColorArray[MAX_NATION+1];

	for( int n = 0; n < MAX_NATION+1; ++n )
		nationColorArray[n] = vga_back.translate_color(nation_array.nation_color_array[n]);

	// ##### begin Gilbert 2/11 ######//
	short	excitedColorArray[MAX_NATION+1];  //[excitedColorCount];
	short	slowExcitedColorArray[MAX_NATION+1];  //[excitedColorCount];

	for( i = 0; i <= MAX_NATION; ++i )
	{
		if( i == 0 || !nation_array.is_deleted(i) )
		{
			short *remapTable = game.get_color_remap_table(i, 0);
			excitedColorArray[i] = remapTable[0xe0 + (sys.frame_count % 4)];
			slowExcitedColorArray[i] = remapTable[0xe0 + (sys.frame_count % 8)/2];
		}
		else
		{
			excitedColorArray[i] = 
			slowExcitedColorArray[i] = vga_back.translate_color(V_WHITE);
		}
	}
	// ##### end Gilbert 2/11 ######//

	int arraySize = size();

	//------------- set boundary of anim_line to mini-map ------------//

	short animLineBoundX1 = anim_line.bound_x1;
	short animLineBoundY1 = anim_line.bound_y1;
	short animLineBoundX2 = anim_line.bound_x2;
	short animLineBoundY2 = anim_line.bound_y2;
	anim_line.bound_x1 = MAP_X1;
	anim_line.bound_y1 = MAP_Y1;
	anim_line.bound_x2 = MAP_X2;
	anim_line.bound_y2 = MAP_Y2;

	// #### begin Gilbert 29/1 ########//
	int showAttackerPath = nation_array.player_recno
		&& god_res[GOD_JAPANESE]->nation_prayer_count(nation_array.player_recno);
	int playerNation = nation_array.player_recno;
	// #### end Gilbert 29/1 ########//

	for(i=1; i<=arraySize; i++)
	{
		register Unit *unitPtr = (Unit*)get_ptr(i);

		if( !unitPtr || !unitPtr->is_visible() || unitPtr->is_stealth() )
			continue;

		int lineColor = TRANSPARENT_CODE;

		if( !unitPtr->selected_flag )		// if the unit is currently selected, ignore the filters
		{
			if( filterUnitClassId && unit_res[unitPtr->unit_id]->unit_class != filterUnitClassId )
				continue;

			// draw only caravan in trade mode
			if( world.map_matrix->map_mode == MAP_MODE_TRADE && unitPtr->unit_id != UNIT_CARAVAN )
				continue;

			// filter selected nation
			if( world.map_matrix->filter_nation_flag && world.map_matrix->filter_nation_recno != unitPtr->nation_recno )
				continue;
		}

		//---------------- draw unit path in mini_map ------------//

		if( (config.show_unit_path & 2) && unitPtr->selected_flag
			&& (config.show_ai_info || !playerNation || unitPtr->is_nation(playerNation))
			&& unitPtr->cur_action != SPRITE_IDLE)
		{
			if( unitPtr->mobile_type == UNIT_SEA )
				lineColor = V_WHITE;
			else
				lineColor = V_BLACK;
		}

		// ------ show unit targeting our nation  ----------//

		else if( showAttackerPath && unitPtr->cur_order.mode == UNIT_ATTACK
			&& unitPtr->cur_action != SPRITE_ATTACK		// if already attack, not need to show path
			&& !base_obj_array.is_deleted(unitPtr->cur_order.para)
			&& base_obj_array[unitPtr->cur_order.para]->nation_recno == playerNation )
		{
			lineColor = VGA_RED;
		}

		if( lineColor != TRANSPARENT_CODE )
		{
			//-----------------------------------------------------------//
			
			if(unitPtr->cur_x_loc()!=unitPtr->go_x_loc() || unitPtr->cur_y_loc()!=unitPtr->go_y_loc())
			{
				lineToX = world.map_matrix->calc_loc_pos_x(unitPtr->go_x_loc(), unitPtr->go_y_loc()) + MAP_X1;
				lineToY = world.map_matrix->calc_loc_pos_y(unitPtr->go_x_loc(), unitPtr->go_y_loc()) + MAP_Y1;
				lineFromX = world.map_matrix->calc_loc_pos_x(unitPtr->next_x_loc(), unitPtr->next_y_loc()) + MAP_X1;
				lineFromY = world.map_matrix->calc_loc_pos_y(unitPtr->next_x_loc(), unitPtr->next_y_loc()) + MAP_Y1;
				vga_back.line(lineFromX, lineFromY, lineToX, lineToY, lineColor);
			}

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

			if( unitPtr->cur_path && unitPtr->cur_path_result_id > 0 )
			{
				int locFromX, locFromY, locToX, locToY;

				locFromX = unitPtr->go_x_loc();
				locFromY = unitPtr->go_y_loc();

				for( j=unitPtr->cur_path_result_id ; j>0 ; j-- )
				{
					PathResult* pathResult = unitPtr->cur_path + j - 1;

					locToX = pathResult->loc_x;
					locToY = pathResult->loc_y;

					lineFromX = world.map_matrix->calc_loc_pos_x(locFromX, locFromY) + MAP_X1;
					lineFromY = world.map_matrix->calc_loc_pos_y(locFromX, locFromY) + MAP_Y1;

					lineToX = world.map_matrix->calc_loc_pos_x(locToX, locToY) + MAP_X1;
					lineToY = world.map_matrix->calc_loc_pos_y(locToX, locToY) + MAP_Y1;

					vga_back.line(lineFromX, lineFromY, lineToX, lineToY, lineColor);

					locFromX = locToX;
					locFromY = locToY;
				}
			}
		}
	}

	//---------------- restore boundary setting of anim_line --------------//

	anim_line.bound_x1 = animLineBoundX1;
	anim_line.bound_y1 = animLineBoundY1;
	anim_line.bound_x2 = animLineBoundX2;
	anim_line.bound_y2 = animLineBoundY2;

	for(i=1; i<=arraySize; i++)
	{
		// #### begin Gilbert 3/11 ######//
		int dotSize;

		{ // minimize register variable at one time
			register Unit *unitPtr = (Unit*)get_ptr(i);

			if( !unitPtr || !unitPtr->is_visible() || unitPtr->is_stealth())
				continue;

			if( !unitPtr->selected_flag )		// if the unit is currently selected, ignore the filters
			{
				// draw only caravan in trade mode
				if( world.map_matrix->map_mode == MAP_MODE_TRADE && unitPtr->unit_id != UNIT_CARAVAN )
					continue;

				if( filterUnitClassId && unit_res[unitPtr->unit_id]->unit_class != filterUnitClassId )
					continue;

				// filter selected nation
				if( world.map_matrix->filter_nation_flag && world.map_matrix->filter_nation_recno != unitPtr->nation_recno )
					continue;
			}

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

			if( world.map_matrix->map_mode != MAP_MODE_TRADE )
			{
				if( unitPtr->cur_action == SPRITE_ATTACK )
					nationColor = excitedColorArray[unitPtr->nation_recno];
				else if( unitPtr->selected_flag )
					nationColor = slowExcitedColorArray[unitPtr->nation_recno];
				else
					nationColor = nationColorArray[unitPtr->nation_recno];
			}
			else
			{
				// if selected firm is mine, factory or market,
				// caravan linked to it flashes

				err_when( MAX_STOP_FOR_CARAVAN != 2 ); // current code check only two stops
				Firm *firmPtr;
				if( firm_array.selected_recno 
					&& (firmPtr = firm_array[firm_array.selected_recno])
					&& (firmPtr->cast_to_FirmMine() || firmPtr->cast_to_FirmFactory() || firmPtr->cast_to_FirmMarket())
					&& ( ((UnitCaravan *)unitPtr)->stop_array[0].firm_recno == firm_array.selected_recno
						|| ((UnitCaravan *)unitPtr)->stop_array[1].firm_recno == firm_array.selected_recno) )
				{
					nationColor = slowExcitedColorArray[unitPtr->nation_recno];
				}
				else
				{
					nationColor = nationColorArray[unitPtr->nation_recno];
				}
			}

			mapX = world.map_matrix->calc_loc_pos_x(unitPtr->cur_x_loc(), unitPtr->cur_y_loc()) + MAP_X1;
			mapY = world.map_matrix->calc_loc_pos_y(unitPtr->cur_x_loc(), unitPtr->cur_y_loc()) + MAP_Y1;
			dotSize = unitPtr->mobile_type == UNIT_LAND ? 2 : 3;
		}

		{ // minimize register variable at one time
			register short *writePtr = vga_back.buf_ptr(mapX, mapY);

			if( dotSize == 2 )
			{
				if( writePtr[0] != unexploredColor )
					writePtr[0] = nationColor;

				if( writePtr[1] != unexploredColor )
					writePtr[1] = nationColor;

				if( writePtr[vgaBufPitch] != unexploredColor )
					writePtr[vgaBufPitch] = nationColor;

				if( writePtr[vgaBufPitch+1] != unexploredColor )
					writePtr[vgaBufPitch+1] = nationColor;
			}
			else if( dotSize == 3 )
			{
				if( writePtr[-vgaBufPitch-1] != unexploredColor )
					writePtr[-vgaBufPitch-1] = nationColor;

				if( writePtr[-vgaBufPitch] != unexploredColor )
					writePtr[-vgaBufPitch] = nationColor;

				if( writePtr[-vgaBufPitch+1] != unexploredColor )
					writePtr[-vgaBufPitch+1] = nationColor;

				if( writePtr[-1] != unexploredColor )
					writePtr[-1] = nationColor;

				if( writePtr[0] != unexploredColor )
					writePtr[0] = nationColor;

				if( writePtr[1] != unexploredColor )
					writePtr[1] = nationColor;

				if( writePtr[vgaBufPitch-1] != unexploredColor )
					writePtr[vgaBufPitch-1] = nationColor;

				if( writePtr[vgaBufPitch] != unexploredColor )
					writePtr[vgaBufPitch] = nationColor;

				if( writePtr[vgaBufPitch+1] != unexploredColor )
					writePtr[vgaBufPitch+1] = nationColor;
			}
		}
		// #### end Gilbert 3/11 ######//
	} //end for
}
示例#26
0
文件: onationa.cpp 项目: 112212/7k2
//------- Begin of function NationArray::update_military_rating ------//
//
void NationArray::update_military_rating()
{
	int nationCombatLevelArray[MAX_NATION];

	memset( nationCombatLevelArray, 0, sizeof(nationCombatLevelArray) );

	//------ calculate firm statistic -------//

	Firm* firmPtr;

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

		firmPtr = firm_array[i];

		if( firmPtr->nation_recno == 0 )
			continue;

		if( firmPtr->cast_to_FirmCamp() )
		{
			FirmCamp *firmCamp = firmPtr->cast_to_FirmCamp();

			nationCombatLevelArray[firmPtr->nation_recno-1] +=
				firmCamp->total_combat_level() +
				(firmCamp->overseer_recno>0 + firmCamp->soldier_count) * 20;
				// 20 is the base military points for a unit, so the nation that has many more units can be reflected in the military rating
		}
		// ###### patch begin 9/11 ########//
		else if( firmPtr->cast_to_FirmTrain() )
		{
			FirmTrain *firmTrain = firmPtr->cast_to_FirmTrain();

			nationCombatLevelArray[firmPtr->nation_recno-1] +=
				firmTrain->total_military_combat_level() +
				firmTrain->total_military_count() * 20;
				// 20 is the base military points for a unit, so the nation that has many more units can be reflected in the military rating
		}
		// ###### patch end 9/11 ########//
	}

	//------ calculate unit statistic -------//

	Unit* unitPtr;

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

		unitPtr = unit_array[i];

		if( unitPtr->nation_recno == 0 )
			continue;

		//---- if this unit is a ship, increase total_ship_combat_level ----//

		if( unit_res[unitPtr->unit_id]->unit_class == UNIT_CLASS_SHIP )
		{
			nation_array[unitPtr->nation_recno]->total_ship_combat_level += (int) unitPtr->hit_points;
		}

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

		if( unitPtr->unit_mode == UNIT_MODE_OVERSEE )		// firm commanders are counted above with firm_array
			continue;

		int addPoints = (int) unitPtr->hit_points;

		UnitInfo* unitInfo = unit_res[unitPtr->unit_id];

		// ##### begin Gilbert 24/3 ########//
//		if( unitInfo->unit_class == UNIT_CLASS_WEAPON )
//			addPoints += (unitInfo->weapon_power + unitPtr->get_weapon_version() - 1) * 30;
		if( !unitInfo->class_info.has_combat_level )
		{
			addPoints += unitInfo->weapon_power * 30;
			if( unitInfo->class_info.has_weapon_version )
				addPoints += (unitPtr->get_weapon_version() - 1) * 30;
		}
		// ##### end Gilbert 24/3 ########//

		if( unitPtr->leader_unit_recno && !unit_array.is_deleted(unitPtr->leader_unit_recno) )
			addPoints += addPoints * unit_array[unitPtr->leader_unit_recno]->skill_level() / 100;

		nationCombatLevelArray[unitPtr->nation_recno-1] += addPoints + 20;		// 20 is the base military points for a unit, so the nation that has many more units can be reflected in the military rating
	}

	//------ update nation statistic ------//

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

		nation_array[i]->military_rating = nationCombatLevelArray[i-1]/50;
	}
}
示例#27
0
文件: onationa.cpp 项目: 112212/7k2
//------- Begin of function NationArray::update_total_human_count ------//
//
// Update total human count as there are some bugs in calculation of
// total human count. This function is used for on-fly correcting
// the problem.
//
void NationArray::update_total_human_count()
{
	int totalHumanCountArray[MAX_NATION];

	memset( totalHumanCountArray, 0, sizeof(totalHumanCountArray) );

	//------ calculate firm statistic -------//

	Firm* firmPtr;

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

		firmPtr = firm_array[i];

		if( firmPtr->nation_recno == 0 || !firmPtr->is_human() )
			continue;

		if( firmPtr->cast_to_FirmCamp() )
		{
			FirmCamp *firmCamp = firmPtr->cast_to_FirmCamp();

			for( int j=firmCamp->soldier_count-1 ; j>=0 ; j-- )
			{
				if( firmCamp->soldier_array[j].is_human() )
					totalHumanCountArray[firmCamp->nation_recno-1]++;
			}
		}

		if( firmPtr->cast_to_FirmTrain() )
		{
			FirmTrain *firmTrain = firmPtr->cast_to_FirmTrain();

			totalHumanCountArray[firmTrain->nation_recno-1] += firmTrain->trainee_count;
		}
	}

	//------ calculate unit statistic -------//

	Unit* unitPtr;

	for( i=unit_array.size() ; i>0 ; i-- )
	{
		if( unit_array.is_truly_deleted(i) )
			continue;

		unitPtr = unit_array[i];

		if( unitPtr->nation_recno && unitPtr->is_human() &&
			 unitPtr->rank_id != RANK_KING )		// does not count kings
		{
			if( unitPtr->unit_id == UNIT_WAGON )
				totalHumanCountArray[unitPtr->nation_recno-1] += unitPtr->cast_to_UnitWagon()->population;
			else
				totalHumanCountArray[unitPtr->nation_recno-1]++;
		}
	}

	//------ update nation statistic ------//

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

		nation_array[i]->total_human_count = totalHumanCountArray[i-1];
	}
}
示例#28
0
文件: ou_carai.cpp 项目: mecirt/7k2
//--------- Begin of function UnitCaravan::disp_stop ---------//
//
void UnitCaravan::disp_stop(int dispY1, int refreshFlag)
{
	int y = INFO_Y1 + 94;

	int i, j;

	for( i = 0; i < MAX_STOP_FOR_CARAVAN; ++i, y += 70 )
	{
		TradeStop *tradeStop = stop_array+i;

		button_go_stop[i].create( INFO_X1+17, y+2, INFO_X1+167, y+35, i_button_go_stop,
			ButtonCustomPara( this, tradeStop->firm_recno ) );
		button_go_stop[i].set_help_code( "CGOSTOP" );

		button_set_stop[i].create( INFO_X1+169, y+2, INFO_X1+215, y+20, i_button_set_stop,
			ButtonCustomPara( NULL, 0 ) );
		button_set_stop[i].set_help_code( "CSETSTOP" );

		button_cancel_stop[i].create( INFO_X1+169, y+21, INFO_X1+215, y+39, i_button_cancel_stop,
			ButtonCustomPara( NULL, 0 ) );
		button_cancel_stop[i].set_help_code( "CDELSTOP" );

		button_reset_stop[i].create( INFO_X1+169, y+42, INFO_X1+215, y+60, i_button_reset_stop,
			ButtonCustomPara( NULL, 0 ) );
		button_reset_stop[i].set_help_code( "CCLRSEL" );

		for( j = 0; j < MAX_GOODS_SELECT_BUTTON; ++j )
			button_select_array[i][j].create( INFO_X1+17+carv_gdd_x[j], y+34, INFO_X1+17+carv_gdd_x[j+1]-1, y+61,
			i_disp_caravan_select_button, ButtonCustomPara( NULL, j ), 0 );

		button_go_stop[i].custom_para = ButtonCustomPara( this, tradeStop->firm_recno );
		button_go_stop[i].paint();
		button_set_stop[i].paint();
		button_cancel_stop[i].paint();
		button_reset_stop[i].paint();

		Firm *firmPtr = NULL;
		if( !firm_array.is_deleted(tradeStop->firm_recno))
			firmPtr = firm_array[tradeStop->firm_recno];

		for( j = 0; j < MAX_GOODS_SELECT_BUTTON; ++j )
		{
			// display quantity on the firm

			int rawId = j+FIRST_GOODS_SELECT_BUTTON-PICK_UP_RAW_FIRST+1;
			if( rawId < 1 || rawId > MAX_RAW )
				rawId = 0;
			int productId = j+FIRST_GOODS_SELECT_BUTTON-PICK_UP_PRODUCT_FIRST+1;
			if( productId < 1 || productId > MAX_PRODUCT )
				productId = 0;

			int stock = -1;

			if( firmPtr )
			{
				if( firmPtr->cast_to_FirmMarket() )
				{
					MarketGoods *marketGoods;
					if( rawId )
					{
						marketGoods = firmPtr->cast_to_FirmMarket()->market_raw_array(rawId);
						err_when( marketGoods && marketGoods->raw_id != rawId );
					}
					else if( productId )
					{
						marketGoods = firmPtr->cast_to_FirmMarket()->market_product_array(productId);
						err_when( marketGoods && marketGoods->product_raw_id != productId );
					}
					else
					{
						err_here();
						marketGoods = NULL;
					}

					if( marketGoods )
						stock = (int) marketGoods->stock_qty;
				}
				else if( firmPtr->cast_to_FirmMine() )
				{
					if( rawId && firmPtr->cast_to_FirmMine()->raw_id == rawId )
					{
						stock = (int) firmPtr->cast_to_FirmMine()->stock_qty;
					}
				}
				else if( firmPtr->cast_to_FirmFactory() )
				{
					if( productId && firmPtr->cast_to_FirmFactory()->product_raw_id == productId )
					{
						stock = (int) firmPtr->cast_to_FirmFactory()->stock_qty;
					}
					//else if( rawId && firmPtr->cast_to_FirmFactory()->product_raw_id == rawId )
					//{
					// stock = (int) firmPtr->cast_to_FirmFactory()->raw_stock_qty;
					//}
				}
			}

			if( stock >= 0 )
			{
				// display button

				button_select_array[i][j].enable_flag = 1;
				button_select_array[i][j].paint( tradeStop->pick_up_array[j] );
			}
			else
			{
				button_select_array[i][j].enable_flag = 0;
				button_select_array[i][j].pushed_flag = tradeStop->pick_up_array[j];
			}
		}
	}
}
示例#29
0
文件: ospya.cpp 项目: mecirt/7k2
//-------- Begin of function SpyArray::catch_spy ------//
//
// <int> spyPlace - either SPY_TOWN or SPY_FIRM
// <int> spyPlacePara - town_recno or firm_recno
//
int SpyArray::catch_spy(int spyPlace, int spyPlacePara)
{
	int nationRecno, totalPop;

	if( spyPlace == SPY_TOWN )
	{
		Town* townPtr = town_array[spyPlacePara];

		nationRecno = townPtr->nation_recno;
		totalPop    = townPtr->population;
	}
	else if( spyPlace == SPY_FIRM )
	{
		Firm* firmPtr = firm_array[spyPlacePara];

		nationRecno = firmPtr->nation_recno;
		if( firmPtr->cast_to_FirmCamp() )
		{
			FirmCamp *firmCamp = firmPtr->cast_to_FirmCamp();
			totalPop    = firmCamp->soldier_count + (firmCamp->overseer_recno>0);
		}
		else if( firmPtr->cast_to_FirmWork() )
		{
			FirmWork *firmWork = firmPtr->cast_to_FirmWork();
			totalPop    = firmWork->worker_count;
		}
		else if( firmPtr->cast_to_FirmTrain() )
		{
			totalPop = firmPtr->cast_to_FirmTrain()->trainee_count;
			return 0;		// don't catch spy
		}
		else if( firmPtr->cast_to_FirmInn() )
		{
			totalPop = firmPtr->cast_to_FirmInn()->inn_unit_count;
			return 0;		// don't catch spy
		}
		else if( firmPtr->cast_to_FirmMarket() )
		{
			totalPop = 0;
			return 0;
		}
		else if( firmPtr->cast_to_FirmMonsterTrain() )
		{
			totalPop = firmPtr->cast_to_FirmMonsterTrain()->trainee_count;
			return 0;		// don't catch spy
		}
		else if( firmPtr->cast_to_FirmMonsterAlchemy() )
		{
			totalPop = 0;
			return 0;
		}
		else if( firmPtr->cast_to_FirmLishorr() )
		{
			totalPop = 0;
			return 0;
		}
		else if( firmPtr->cast_to_FirmMonsterFortress() )
		{
			FirmMonsterFortress *firmMonsterFortress = firmPtr->cast_to_FirmMonsterFortress();
			totalPop = firmMonsterFortress->archer_count + firmMonsterFortress->extra_builder_count;
		}
		else if( firmPtr->cast_to_FirmAnimal() )
		{
			totalPop = 0;
			return 0;
		}
		else if( firmPtr->cast_to_FirmIncubator() )
		{
			totalPop = 0;
			return 0;
		}
		else if( firmPtr->cast_to_FirmMagic() )
		{
			totalPop = 0;
			return 0;
		}
		else if( firmPtr->cast_to_FirmOffensive() )
		{
			totalPop = 0;
			return 0;
		}
		else if( firmPtr->cast_to_FirmOffensive2() )
		{
			totalPop = 0;
			return 0;
		}
		else
		{
			err_here();
			totalPop = 0;
		}
	}
	else
		err_here();

	//--- calculate the total of anti-spy skill in this town ----//

	int enemySpyCount=0, counterSpySkill=0;
	Spy* spyPtr;

	int techLevel = 0;
	if( nationRecno )
		techLevel = tech_res[TECH_COUNTER_SPY]->get_nation_tech_level(nationRecno);

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

		spyPtr = spy_array[i];

		if( spyPtr->spy_place == spyPlace &&
			 spyPtr->spy_place_para == spyPlacePara )
		{
			if( spyPtr->true_nation_recno == nationRecno )
				counterSpySkill += spyPtr->spy_skill + spyPtr->spy_skill * techLevel / 2;
			else
				enemySpyCount++;
		}
	}

	//----- if all citizens are enemy spies ----//

	if( enemySpyCount == totalPop )
		return 0;

	err_when( enemySpyCount > totalPop );

	//-------- try to catch enemy spies now ------//

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

		spyPtr = spy_array[i];

		if( spyPtr->action_mode == SPY_IDLE )		// it is very hard to get caught in sleep mode
			continue;

		if( spyPtr->spy_place == spyPlace &&
			 spyPtr->spy_place_para == spyPlacePara &&
			 spyPtr->true_nation_recno != nationRecno )	// doesn't get caught in sleep mode
		{
			int escapeChance = 100 + spyPtr->spy_skill - counterSpySkill;

			escapeChance = max( spyPtr->spy_skill/10, escapeChance );

			if( m.random(escapeChance) == 0 )
			{
				spyPtr->get_killed(); 		// only catch one spy per calling
				return 1;
			}
		}
	}

	return 0;
}
示例#30
0
文件: OTOWNDRW.cpp 项目: AMDmi3/7kaa
//------- Begin of function Town::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 Town::draw_detect_link_line(int actionDetect)
{
	//-------- 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 ---------//

	char* bitmapPtr;

	for(int i=0 ; i<linked_firm_count ; i++ )
	{
		int firmX, firmY;
		Firm *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 );

		if( !can_toggle_firm_link(linked_firm_array[i]) )
			continue;

		//------ draw the link icon and detect mouse action -----//

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

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

			if( rc )
				mouse.reset_click();		// reset queued mouse click for fast single clicking

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

			if( rc==1 && nation_recno==nation_array.player_recno )
			{
				if( linked_firm_enable_array[i] & LINK_ED )
				{
					toggle_firm_link( i+1, 0, COMMAND_PLAYER );
					// ###### begin Gilbert 25/9 #######//
					se_ctrl.immediate_sound("TURN_OFF");
					// ###### end Gilbert 25/9 #######//
				}
				else
				{
					toggle_firm_link( i+1, 1, COMMAND_PLAYER );
					// ###### begin Gilbert 25/9 #######//
					se_ctrl.immediate_sound("TURN_ON");
					// ###### end Gilbert 25/9 #######//

				}

				// ######## begin Gilbert 23/9 ##########//
				if( firmPtr->firm_id == FIRM_CAMP && !remote.is_enable())
				// ######## end Gilbert 23/9 ##########//
				{
					if( nation_recno )
						update_target_loyalty();
					else
						update_target_resistance();

               update_camp_link();
				}

				return 1;
			}

			//------ right clicking to recruit soldiers ------//

			else if( rc==2 )
			{
				if( firmPtr->nation_recno == nation_recno && !firmPtr->under_construction &&
					 firmPtr->worker_array && firmPtr->worker_count < MAX_WORKER )
				{
					firmPtr->pull_town_people(town_recno, COMMAND_PLAYER, browse_selected_race_id(), 1);			// last 1-force pulling people from the town to the firm
					// ###### begin Gilbert 25/9 #######//
					se_ctrl.immediate_sound("PULL_MAN");
					// ###### end Gilbert 25/9 #######//
				}
			}
		}
		else
		{
			if( nation_recno == nation_array.player_recno )
				world.zoom_matrix->put_bitmap_clip( firmX-11, firmY-11, bitmapPtr );
		}
	}

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

	bool awesome_lines_flag = false; // Set this to true to draw animated lines to ALL towns in the network. Not advised for actual play.

	for( int i=0 ; i<linked_town_count ; i++ )
	{
		int townX, townY;
		int townRecno = linked_town_array[i];

		Town *townPtr = town_array[townRecno];

		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 ( !awesome_lines_flag || (townPtr->nation_recno != nation_array.player_recno) )
			anim_line.draw_line(&vga_back, srcX, srcY, townX, townY, linked_town_enable_array[i]==LINK_EE );
	}

	//------------ detect on the migration icon ------------//
	// allow migration to any town in the same town network //

	if (town_network_recno != 0 && (nation_recno == nation_array.player_recno))
	{
		TownNetwork &townNetwork = *town_network_array[town_network_recno];
		bitmapPtr = image_icon.get_ptr("MIGRATE");
		for (int i = 0; i < townNetwork.size(); ++i)
		{
			int townRecno = townNetwork[i];
			Town *townPtr = town_array[townRecno];

			// Do not draw/detect on self
			if (townRecno == town_recno) continue;

			int townX, townY;
			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 awesome_lines_flag is true then draw the aminated lines on all towns in the town-network
			if (awesome_lines_flag)
			{
				anim_line.draw_line(&vga_back, srcX, srcY, townX, townY, 1 /*-animated*/);
			}

			// Only perform checks on migration (draw/detect) when the 'active' part of the town is within
			// the zoom matrix
			if ( world.zoom_matrix->is_bitmap_clip( townX-11, townY-11, bitmapPtr ) &&
				 can_migrate(townRecno) )
			{
				if( actionDetect )
				{
					int detectClick = world.zoom_matrix->detect_bitmap_clip( townX-11, townY-11, bitmapPtr );
					if( detectClick )
					{
						mouse.reset_click();		// reset queued mouse click for fast single clicking

						// Migrate 1 person on left click and 10 people on right click
						err_when(town_array[townRecno]->population>MAX_TOWN_POPULATION);
						int migrateRaceId = browse_selected_race_id();
						err_when( !migrateRaceId );
						migrate_to(townRecno, COMMAND_PLAYER, migrateRaceId, (detectClick == 1 ? 1 : 10));
						// ###### begin Gilbert 25/9 #######//
						se_ctrl.immediate_sound("PULL_MAN");
						// ###### end Gilbert 25/9 #######//
						return 1;
					}
				}
				else
				{
					world.zoom_matrix->put_bitmap_clip( townX-11, townY-11, bitmapPtr );
				}
			}
		}
	}

	return 0;
}