コード例 #1
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;
}
コード例 #2
0
ファイル: otownlnk.cpp プロジェクト: mecirt/7k2
//------- Begin of function Town::toggle_firm_link ---------//
//
// Toggle the firm link of the current firm.
//
// <int> linkId - id. of the link
// <int> toggleFlag - 1-enable, 0-disable
// <char> remoteAction - remote action type 
// [int] setBoth - if this is 1, it will set the link to either LINK_EE or LINK_DD (and no LINK_ED or LINK_DD)
//						 if this is -1, the only one side will be set even though the nation recno of the firm and town are the same
//					    (default: 0)
//
void Town::toggle_firm_link(int linkId, int toggleFlag, char remoteAction, int setBoth)
{
	if( !remoteAction && remote.is_enable() )
	{
		// packet structure : <town recno> <link Id> <toggle Flag>
		short *shortPtr = (short *)remote.new_send_queue_msg(MSG_TOWN_TOGGLE_LINK_FIRM, 3*sizeof(short));
		shortPtr[0] = town_recno;
		shortPtr[1] = linkId;
		shortPtr[2] = toggleFlag;
		return;
	}

	Firm* linkedFirm = firm_array[linked_firm_array[linkId-1]];
	int 	linkedNationRecno = linkedFirm->nation_recno;

	int sameNation = linkedNationRecno == nation_recno;

//	int sameNation = linkedNationRecno == nation_recno ||		// if one of the linked end is an indepdendent firm/nation, consider this link as a single nation link
//						  linkedNationRecno == 0 ||
//						  nation_recno == 0;

	if( toggleFlag )
	{
		if( (sameNation && setBoth==0) || setBoth==1 )		// 0 if setBoth == -1
			linked_firm_enable_array[linkId-1] = LINK_EE;
		else
			linked_firm_enable_array[linkId-1] |= LINK_ED;
	}
	else
	{
		if( (sameNation && setBoth==0) || setBoth==1 )
			linked_firm_enable_array[linkId-1] = LINK_DD;
		else
			linked_firm_enable_array[linkId-1] &= ~LINK_ED;
	}

	//------ set the linked flag of the opposite firm -----//

	Firm* firmPtr = firm_array[ linked_firm_array[linkId-1] ];
	int   i;

	for(i=firmPtr->linked_town_count-1; i>=0; i--)
	{
		if( firmPtr->linked_town_array[i] == town_recno )
		{
			if( toggleFlag )
			{
				if( (sameNation && setBoth==0) || setBoth==1 )
					firmPtr->linked_town_enable_array[i]  = LINK_EE;
				else
					firmPtr->linked_town_enable_array[i] |= LINK_DE;
			}
			else
			{
				if( (sameNation && setBoth==0) || setBoth==1 )
					firmPtr->linked_town_enable_array[i]  = LINK_DD;
				else
					firmPtr->linked_town_enable_array[i] &= ~LINK_DE;
			}

			break;
		}
	}

	//-------- update the town's influence --------//

	if( nation_recno==0 )
		update_target_resistance();

	//--- redistribute demand if a link to market place has been toggled ---//

	if( linkedFirm->firm_id == FIRM_MARKET )
		town_array.distribute_demand();
}
コード例 #3
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;
}