Example #1
0
//------- Begin of function Firm::draw_frame -----------//
//
// Draw a specific frame of the firm.
//
void Firm::draw_frame(int frameId, int displayLayer)
{
	//---------- draw animation now ------------//

	FirmBuild*  firmBuild = firm_res.get_build(firm_build_id);
	FirmBitmap* firmBitmap;

	int bitmapRecno, i;
	int firstBitmap = firmBuild->first_bitmap(frameId);
	int bitmapCount = firmBuild->bitmap_count(frameId);

	char* colorRemapTable = game.get_color_remap_table(nation_recno, firm_array.selected_recno==firm_recno);

	for( i=0, bitmapRecno=firstBitmap ; i<bitmapCount ; i++, bitmapRecno++ )
	{
		firmBitmap = firm_res.get_bitmap(bitmapRecno);

		if( firmBitmap )
			firmBitmap->draw_at(loc_x1*ZOOM_LOC_WIDTH, loc_y1*ZOOM_LOC_HEIGHT, colorRemapTable, displayLayer);
	}
}
Example #2
0
int FirmDie::process()
{
	FirmBuild *firmBuild = firm_die_res.get_build(firm_build_id);

	if( --frame_delay_count < 1 )
//	if( ++frame_delay_count > firmBuild->frame_delay_array[frame-1])
	{
	//	frame_delay_count = 0;
	//	if( ++frame > 	firmBuild->frame_count)
		if( ++frame > 	end_frame)
		{
			if (frame_looping >0)
			{
				frame_looping --;
				frame = start_frame;
				return 0;
			}
			firmBuild->free_bitmap_res();
			return 1;
		}
	}
	return 0;
}
Example #3
0
void FirmDie::draw(int displayLayer)
{
	// get ground dirt from firm_res
	FirmBuild* firmBuild = firm_res.get_build(firm_build_id);

	if( firmBuild->ground_bitmap_recno )
	{
//		firm_res.get_bitmap(firmBuild->ground_bitmap_recno)
//			->draw_at(loc_x1*ZOOM_LOC_WIDTH, loc_y1*ZOOM_LOC_HEIGHT, NULL, displayLayer);
	}

	//---------- draw animation now ------------//

	firmBuild = firm_die_res.get_build(firm_build_id);
	FirmDieBitmap* firmBitmap;

	int bitmapRecno, i;
	int firstBitmap = firmBuild->first_bitmap(frame);
	int bitmapCount = firmBuild->bitmap_count(frame);
	

	short* colorRemapTable = firmBuild->get_color_remap_table(nation_recno, 0);

	for( i=0, bitmapRecno=firstBitmap ; i<bitmapCount ; i++, bitmapRecno++ )
	{
		firmBitmap = firm_die_res.get_bitmap(bitmapRecno);

		if( firmBitmap )
		{
		//	char *bitmapPtr;
		//	firmBitmap->bitmap_ptr = bitmapPtr = firm_die_res.res_bitmap.read_imported(firmBitmap->bitmap_ptr);
		//	firmBitmap->width = *(short *)bitmapPtr;
		//	firmBitmap->height= *(1+(short *)bitmapPtr);
			firmBitmap->draw_at(loc_x1 * LOCATE_WIDTH, loc_y1 * LOCATE_HEIGHT, altitude, colorRemapTable, displayLayer, firmBuild);
		}
	}
}
Example #4
0
//------- Begin of function Firm::draw_full_size -----------//
//
// Draw the firm on the map
//
void Firm::draw_full_size(int displayLayer)
{
	FirmBuild* firmBuild = firm_res.get_build(firm_build_id);

	//-------- check if the firm is within the view area --------//

	int x1 = abs_x1 - World::view_top_x;

	if( x1 <= -firmBuild->max_bitmap_width || x1 >= ZOOM_WIDTH )	// out of the view area, not even a slight part of it appears in the view area
		return;

	int y1 = abs_y1 - World::view_top_y;

	if( y1 <= -firmBuild->max_bitmap_height || y1 >= ZOOM_HEIGHT )
		return;

	//------- get the color remap table for this bitmap ------//

	char* colorRemapTable = game.get_color_remap_table(nation_recno, firm_array.selected_recno == firm_recno);

	// ######## begin Gilbert 29/10 #######//
	// ------ draw flags behind the building -------//
	if( under_construction )
	{
#define FLAG_WIDTH 9
#define FLAG_HEIGHT 25
		char *flagBitmapPtr = image_spict.get_ptr("FLAG-S0");
		int drawX = loc_x1 * ZOOM_LOC_WIDTH - world.view_top_x + ZOOM_X1;
		int drawY = loc_y1 * ZOOM_LOC_HEIGHT - world.view_top_y + ZOOM_Y1;
		world.zoom_matrix->put_bitmap_remap_clip(drawX, drawY, flagBitmapPtr, colorRemapTable, 1);	// 1-the bitmap is compressed

		drawX = (loc_x2+1)*ZOOM_LOC_WIDTH - FLAG_WIDTH - world.view_top_x + ZOOM_X1;
		world.zoom_matrix->put_bitmap_remap_clip(drawX, drawY, flagBitmapPtr, colorRemapTable, 1);	// 1-the bitmap is compressed
	}
	// ######## end Gilbert 29/10 #######//

	//---------- get the bitmap pointer ----------//

	FirmBitmap* firmBitmap = NULL;

	if( under_construction )
	{
		int buildFraction = construction_frame();
		firmBitmap = firm_res.get_bitmap(firmBuild->under_construction_bitmap_recno
			+ buildFraction);
	}

	else if( !is_operating() )                      // is_operating() is a virtual function
		firmBitmap = firm_res.get_bitmap(firmBuild->idle_bitmap_recno);

	else
		firmBitmap = firm_res.get_bitmap(firmBuild->first_bitmap(cur_frame));

	// ------ check if the display layer is correct ---------//
	if( !firmBitmap || !(firmBitmap->display_layer & displayLayer) )
		return;

	//-------- check if the firm is within the view area --------//

	x1 = loc_x1 * ZOOM_LOC_WIDTH - World::view_top_x + firmBitmap->offset_x;

	if( x1 <= -firmBitmap->width || x1 >= ZOOM_WIDTH )	// out of the view area, not even a slight part of it appears in the view area
		return;

	y1 = loc_y1 * ZOOM_LOC_HEIGHT - World::view_top_y + firmBitmap->offset_y;

	if( y1 <= -firmBitmap->height || y1 >= ZOOM_HEIGHT )
		return;

	//------- decide which approach to use for displaying -----//

	int x2 = x1 + firmBitmap->width - 1;
	int y2 = y1 + firmBitmap->height - 1;

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

	if( 0 && under_construction )
	{
		err_when( (abs_x2-abs_x1+1) * (abs_y2-abs_y1+1) > COMMON_DATA_BUF_SIZE );

		//---------- decompress the image ---------//

		IMGremapDecompress(sys.common_data_buf, firmBitmap->bitmap_ptr, colorRemapTable);

		//---------- pixelize the image -----------//

		char* pixelPtr = sys.common_data_buf + sizeof(short) * 2;

		int y, bitmapWidth=abs_x2-abs_x1+1, bitmapHeight=abs_y2-abs_y1+1;
		int lineCount;
		int solidLineCount = bitmapHeight / 2 * (int) hit_points / (int) max_hit_points;
		int solidLinePixel = bitmapHeight / 2 * bitmapWidth * (int) hit_points / (int) max_hit_points -
									solidLineCount * bitmapWidth;

		int hitPerPixel = (int) max_hit_points / bitmapWidth / bitmapHeight / 2;

		for( lineCount=1, y=bitmapHeight-2 ; y>=0 ; y-=2, lineCount++ )
		{
			 if( lineCount > solidLineCount )
				 memset( pixelPtr+y*bitmapWidth, TRANSPARENT_CODE, bitmapWidth );

			 if( lineCount==solidLineCount+1 )		// the current progressing line
				 memset( pixelPtr+y*bitmapWidth, TRANSPARENT_CODE, solidLinePixel );
		}

		//---- only portion of the sprite is inside the view area ------//

		if( x1 < 0 || x2 >= ZOOM_WIDTH || y1 < 0 || y2 >= ZOOM_HEIGHT )
		{
			vga_back.put_bitmap_area_trans( x1+ZOOM_X1, y1+ZOOM_Y1, sys.common_data_buf,
				max(0,x1)-x1, max(0,y1)-y1, min(ZOOM_WIDTH-1,x2)-x1, min(ZOOM_HEIGHT-1,y2)-y1 );
		}

		//---- the whole sprite is inside the view area ------//

		else
		{
			vga_back.put_bitmap_trans( x1+ZOOM_X1, y1+ZOOM_Y1, sys.common_data_buf );
		}
	}
	else	//----- display the normal image (not under construction) ----//
	{
		//---- only portion of the sprite is inside the view area ------//

		if( x1 < 0 || x2 >= ZOOM_WIDTH || y1 < 0 || y2 >= ZOOM_HEIGHT )
		{
			vga_back.put_bitmap_area_trans_remap_decompress( x1+ZOOM_X1, y1+ZOOM_Y1, firmBitmap->bitmap_ptr,
				max(0,x1)-x1, max(0,y1)-y1, min(ZOOM_WIDTH-1,x2)-x1, min(ZOOM_HEIGHT-1,y2)-y1, colorRemapTable );
		}

		//---- the whole sprite is inside the view area ------//

		else
		{
			vga_back.put_bitmap_trans_remap_decompress( x1+ZOOM_X1, y1+ZOOM_Y1, firmBitmap->bitmap_ptr, colorRemapTable );
		}
	}

	// ######## begin Gilbert 29/10 #######//
	// ------ draw flags in front of the building -------//
	if( under_construction )
	{
		char *flagBitmapPtr = image_spict.get_ptr("FLAG-S0");
		int drawX = loc_x1 * ZOOM_LOC_WIDTH - world.view_top_x + ZOOM_X1;
		int drawY = (loc_y2+1) * ZOOM_LOC_HEIGHT - FLAG_HEIGHT - world.view_top_y + ZOOM_Y1;
		world.zoom_matrix->put_bitmap_remap_clip(drawX, drawY, flagBitmapPtr, colorRemapTable, 1);	// 1-the bitmap is compressed

		drawX = (loc_x2+1)*ZOOM_LOC_WIDTH - FLAG_WIDTH - world.view_top_x + ZOOM_X1;
		world.zoom_matrix->put_bitmap_remap_clip(drawX, drawY, flagBitmapPtr, colorRemapTable, 1);	// 1-the bitmap is compressed
	}
	// ######## end Gilbert 29/10 #######//
}
Example #5
0
// add before delete the firm
void FirmDie::init(Firm *firmPtr, short dieFlag, int random)
{
	int x, y;
	firm_id = firmPtr->firm_id;
	firm_build_id = firmPtr->firm_build_id;
	nation_recno = firmPtr->nation_recno;
	loc_x1 = firmPtr->loc_x1;
	loc_y1 = firmPtr->loc_y1;
	loc_x2 = firmPtr->loc_x2;
	loc_y2 = firmPtr->loc_y2;

	parent_loc_x1 = firmPtr->loc_x1;
	parent_loc_y1 = firmPtr->loc_y1;
	parent_loc_x2 = firmPtr->loc_x2;
	parent_loc_y2 = firmPtr->loc_y2;

	altitude = firmPtr->altitude;
//	frame = 1;
	frame_delay_count = 0;
	die_flag = dieFlag;
	start_frame = 0;
	end_frame = 0;
	frame_looping = 0;

	if (die_flag == 6)
		se_res.sound(firmPtr->center_x, firmPtr->center_y, 1, 'F', 0, "DIE" );
	else
		se_res.sound(firmPtr->center_x, firmPtr->center_y, 1, 'F', 0, "A1" );
	
	FirmBuild *firmBuild = firm_die_res.get_build(firm_build_id);
	firmBuild->load_bitmap_res();

	int bitmapCount;
	int firstBitmap;
	FirmBitmap* firmBitmap;
	int frameCount = firmBuild->frame_count;
	for ( int k=1; k <= frameCount; k++ )
	{
		firstBitmap = firmBuild->first_bitmap(k);
		bitmapCount = firmBuild->bitmap_count(k);
		for ( int j=0; j <bitmapCount; j++ )
		{
			firmBitmap = firm_die_res.get_bitmap(firstBitmap + j);
			if( firmBitmap )
			{
				if (firmBitmap->ani_part == die_flag)
				{
					if (start_frame == 0)
					{
						start_frame = k;
						end_frame = k;
						frame_delay_count = firmBitmap->delay;
						if (firmBitmap->random_flag == 'R' || (firmBitmap->random_flag >'0' && firmBitmap->random_flag <='9'))
						{
							x = (loc_x2 - loc_x1 + 1)/firmBitmap->loc_width;
							y = (loc_y2 - loc_y1 + 1)/firmBitmap->loc_height;
							random = random % (x * y);
							loc_x1 = loc_x1 + random % x;
							loc_y1 = loc_y1 + random / x;
							loc_x2 = loc_x1 + firmBitmap->loc_width - 1;
							loc_y2 = loc_y1 + firmBitmap->loc_height - 1;
							//		altitude = world.get_corner( loc_x1, loc_y1 )->get_altitude();
							if (firmBitmap->random_flag != 'R')
								frame_looping = firmBitmap->random_flag - '0';
						}
					}
					else
						end_frame = k;
					break;
				}
			}
		}
	}

	err_when(end_frame < start_frame || end_frame == 0);
		
	frame = start_frame;
}
Example #6
0
void FirmOffensive2::put_info(int refreshFlag)
{
    if( !should_show_info() )
        return;

    vga.active_buf->put_bitmap( INFO_X1, INFO_Y1, image_gameif.read("MISSBASE") );

    int hitPoints;
    String str;
    int offsetX = 0;
    int offsetY = 0;

    if( hit_points > (float)0 && hit_points < (float)1 )
        hitPoints = 1;		// display 1 for value between 0 and 1
    else
        hitPoints = (int) hit_points;

    if ( max_hit_points() )
    {
        offsetX = -35;
        offsetY = -14;
        short*	hitPointBitmap =NULL;
        int ratio = hitPoints *40 / (int)max_hit_points();
        int size = hitPoints *76 / (int)max_hit_points();

        //106 x 35 --- 15 to 90 ie. 0 to 40
        hitPointBitmap = (short *)mem_add( BitmapW::size(15 +size, 35) );
        if (ratio <11)
            vga.active_buf->put_bitmap_trans( INFO_X1 +80 +20 +offsetX, INFO_Y1 +49 +offsetY, image_spict.read("MTR_B2"));
        else if (ratio <40)
            vga.active_buf->put_bitmap_trans( INFO_X1 +80 +20 +offsetX, INFO_Y1 +49 +offsetY, image_spict.read("MTR_B3"));
        else
            vga.active_buf->put_bitmap_trans( INFO_X1 +80 +20 +offsetX, INFO_Y1 +49 +offsetY, image_spict.read("MTR_B4"));

        vga.active_buf->read_bitmapW( INFO_X1 +80 +20 +offsetX, INFO_Y1 +49 +offsetY, INFO_X1 +94 +20 +size +offsetX, INFO_Y1 +80 +offsetY, hitPointBitmap );
        vga.active_buf->put_bitmap_trans( INFO_X1 +80 +20 +offsetX, INFO_Y1 +49 +offsetY, image_spict.read("MTR_B1"));
        vga.active_buf->put_bitmapW( INFO_X1 +80 +20 +offsetX, INFO_Y1 +49 +offsetY, hitPointBitmap );
        mem_del( hitPointBitmap );

        font_whbl.center_put( INFO_X1 +43, INFO_Y1 +45, INFO_X1 +65, INFO_Y1 +57, m.format((int)hitPoints,4));
        font_whbl.center_put( INFO_X1 +169, INFO_Y1 +45, INFO_X1 +191, INFO_Y1 +57, m.format((int)max_hit_points(),4) );
    }

    // font_whbl.center_put( INFO_X1 +12, INFO_Y1 +9, INFO_X2, INFO_Y1 +21, "Offensive Building 3", 0, 1 );
    font_whbl.center_put( INFO_X1 +12, INFO_Y1 +9, INFO_X2, INFO_Y1 +21, firm_name(), 0, 1 );

    FirmBuild* firmBuild = firm_res.get_build(firm_build_id);
    short *colorRemapTable = firmBuild->get_color_remap_table(nation_recno, firm_array.selected_recno == firm_recno);
    colorRemapTable = firm_res.calc_color_remap_table( colorRemapTable, 1.0f );

    FirmBitmap* firmBitmap = firm_res.get_bitmap(firmBuild->first_bitmap(1));
    if( firmBitmap )
    {
        Bitmap* bitmapPtr = (Bitmap *) firmBuild->res_bitmap.read_imported(firmBitmap->bitmap_ptr);

        int x1;
        int y1;
        int srcX2;
        int srcY2;

        if (config.building_size == 1)
        {
            x1 = INFO_X1 +130;
            y1 = INFO_Y1 +140;
        }
        else
        {
            x1 = INFO_X1 +120;
            y1 = INFO_Y1 +142;
        }

        x1 += firmBitmap->offset_x;
        y1 += firmBitmap->offset_y;
        int x2 = x1 + bitmapPtr->get_width() -1;
        int y2 = y1 + bitmapPtr->get_height() -1;
        int srcX1 = max(x1, INFO_X1+15)-x1;
        int srcY1 = 0;

        if (config.building_size == 1)
        {
            srcX2 = min(x2, INFO_X2)-x1;
            srcY2 = min(y2, INFO_Y1+227)-y1;
        }
        else
        {
            srcX2 = min(x2, INFO_X2)-x1;
            srcY2 = min(y2, INFO_Y2)-y1;
        }

        vga.active_buf->put_bitmap_area_trans_remap_decompress(x1, y1, (char *) bitmapPtr, srcX1, srcY1, srcX2, srcY2, colorRemapTable);
    }
    /*
    	if (config.building_size == 1)
    		return;

    	firmBitmap = firm_res.get_bitmap(firmBuild->first_bitmap(firm_cur_frame[0]));
    	if( firmBitmap && firmBitmap->display_layer == 1 )
    	{
    		Bitmap* bitmapPtr = (Bitmap *) firmBuild->res_bitmap.read_imported(firmBitmap->bitmap_ptr);

    		int x1 = INFO_X1 +120 +firmBitmap->offset_x;
    		int y1 = INFO_Y1 +142 +firmBitmap->offset_y;
    		int x2 = x1 + bitmapPtr->get_width() -1;
    		int y2 = y1 + bitmapPtr->get_height() -1;
    		int srcX1 = max(x1, INFO_X1+15)-x1;
    		int srcY1 = 0;
    		int srcX2 = min(x2, INFO_X2)-x1;
    		int srcY2 = min(y2, INFO_Y2)-y1;

    		vga.active_buf->put_bitmap_area_trans_remap_decompress(x1, y1, (char *) bitmapPtr, srcX1, srcY1, srcX2, srcY2, colorRemapTable);

    	//	vga_back.put_bitmap_trans_remap_decompress(INFO_X1 +113 +firmBitmap->offset_x,
    	//		INFO_Y1 +158 +firmBitmap->offset_y, bitmapPtr, colorRemapTable);
    	}*/
}
Example #7
0
File: ofirm.cpp Project: 112212/7k2
//---------- Begin of function Firm::process_animation --------//
//
void Firm::process_animation()
{
   //-------- process animation ----------//

   FirmBuild* firmBuild  = firm_res.get_build(firm_build_id);
	FirmBitmap* firmBitmap;
   int frameCount = firmBuild->frame_count;
	int firstBitmap;
	int bitmapCount;

	if( hit_points < (max_hit_points() * 0.1))
	{
		if (misc.random(100) > 65)
		{
			int effectId = sprite_res.search_sprite( "FIRMDIE" );
			if( effectId )
			{
				Effect::create(effectId, 
					(loc_x1 + misc.random(20)%(loc_x2 -loc_x1 +1)) *LOCATE_WIDTH,
					(loc_y1 + misc.random(20)%(loc_y2 -loc_y1 +1)) *LOCATE_HEIGHT,
					SPRITE_DIE, 1, 2, 0); 
			}
		}
	}
	else
	if( hit_points < (max_hit_points() * 0.3))
	{
		if (misc.random(100) > 80)
		{	
			int effectId = sprite_res.search_sprite( "FIRMDIE" );
			if( effectId )
			{
				Effect::create(effectId, 
					(loc_x1 + misc.random(20)%(loc_x2 -loc_x1 +1)) *LOCATE_WIDTH,
					(loc_y1 + misc.random(20)%(loc_y2 -loc_y1 +1)) *LOCATE_HEIGHT,
					SPRITE_DIE, 1, 2, 0);
			}
		}
	}

   if( frameCount==1 )     // no animation for this firm
      return;

   //---------- next frame -----------//
	int aniPartCount = firmBuild->ani_part_count;
	for (int i = 0; i < aniPartCount ; i++)
	{
		firm_remain_frame_delay[i] --;
		if (firm_remain_frame_delay[i] < 0)
		{
			// animate_full_size only supports animation of looping
			// it does not support random animation and in fact
			// it is now only used for no animation buildings
			// but it support different frame different delay

			if( firmBuild->animate_full_size )
			{
				if( ++firm_cur_frame[i] > frameCount )
					firm_cur_frame[i] = 1;
				firm_remain_frame_delay[i] = (char) firmBuild->frame_delay(firm_cur_frame[i]);
			}
			else
			{
			// not animate_full_size supports animation of looping and
			// random animation and partial animation
			// however different frames of each parts must has same delay
		
				for ( int k=1; k <frameCount; k++ )
				{
					firstBitmap = firmBuild->first_bitmap(k+1);
					bitmapCount = firmBuild->bitmap_count(k+1);

					int j;
					for ( j=0; j <bitmapCount; j++ )
					{
						firmBitmap = firm_res.get_bitmap(firstBitmap + j);
						if( firmBitmap )
						{
							if (firmBitmap->ani_part == (i + 1))
							{
								// unlike the animate_full_size animation, it search starting
								// from the 2nd frame for bitmaps (since now 1 frame may has more 
								// than 1 bitmap) with same animation part no. of the currently
								// searching part no., i. This has no relationship with the 
								// current_frame. Then restore this animation part's delay and 
								// set its current_frame either randomly or sequentially
			
								firm_remain_frame_delay[i] = firmBitmap->delay;
								if (firmBitmap->random_flag)
									firm_cur_frame[i] = misc.random(100) % frameCount +1;
								else
								if( ++firm_cur_frame[i] > frameCount )
									firm_cur_frame[i] = 1;
								
								if((firm_cur_frame[i] == 1) && !( firmBuild->use_first_frame ))
									firm_cur_frame[i] = 2;
								break;
							}
						}
					}
					if (j < bitmapCount)
						break;
				}
			}
		}
	}
}
Example #8
0
File: ofirm.cpp Project: 112212/7k2
//--------- Begin of function Firm::deinit --------//
//
void Firm::deinit()
{
	if( !firm_recno )    // already deleted
		return;

	if( power.command_firm_recno == firm_recno )
		power.reset_command();

	// ##### begin Gilbert 30/10 ######//
//	mem_del(firm_cur_frame);
//	firm_cur_frame = NULL;
//	mem_del(firm_remain_frame_delay);
//	firm_remain_frame_delay = NULL;
	// ##### end Gilbert 30/10 ######//
	
	is_being_deleted = 1;	// whether the place is currently being deleted, if it is set to true, some functions will be executed in an exceptional way, it is set in deinit()

	Place::deinit();			// parent class deinit()

	deinit_derived();

	//------- delete AI info ----------//

	if( nation_recno )
	{
		Nation* nationPtr = nation_array[nation_recno];

		nationPtr->del_firm_info(firm_id, firm_recno);

		if(is_ai)
		{
			if( should_close_flag )
				nationPtr->firm_should_close_array[firm_id-1]--;

			err_when( nationPtr->firm_should_close_array[firm_id-1] < 0 );

		}
	}

	//--------- clean up related stuff -----------//

	restore_world_matrix();
	release_link();

	//-------- dynamic unloading of firm bitmaps ---------//

	FirmBuild* firmBuild = firm_res.get_build(firm_build_id);
	firmBuild->free_bitmap_res();

	//------ all workers and the overseer resign ------//

	if( !sys.signal_exit_flag )
	{
	//	char* name1 = "Wilde Lishorr";
	//	char* name2 = "Lishorr";
	//	if( !under_construction && hit_points < 1 && strcmp(name1, firm_name()) && strcmp(name2, firm_name()) )
		if( !under_construction && hit_points < 1 )
		{
			// -------- create a firm die record ------//
			// can be called as soon as restore_world_matrix

			static int effectId = sprite_res.search_sprite( "FIRE_EFF" );
			err_when( !effectId );
			Effect::create(effectId, loc_x1 *LOCATE_WIDTH, loc_y1 *LOCATE_HEIGHT, SPRITE_IDLE, 1, 8, 0);
					
			FirmDie firmDie3;
			if (firmBuild->loc_width == 3 && firmBuild->loc_height == 3)
				firmDie3.init(this, 6);
			else
			if (firmBuild->loc_width == 6 && firmBuild->loc_height == 6)
				firmDie3.init(this, 5);
			else
				firmDie3.init(this, 4);
			firm_die_array.add(&firmDie3);
		}
	}

	free_all_people();
	//--------- decrease firm counter -----------//

	if( nation_recno )
		nation_array[nation_recno]->nation_firm_count--;

	//------ update firm counter -------//

	FirmInfo* firmInfo = firm_res[firm_id];

	firmInfo->total_firm_count--;

	if( nation_recno )
		firmInfo->dec_nation_firm_count(nation_recno);

	//------- update town border ---------//

	loc_x1 = -1;      // mark deleted

	//------- if the current firm is the selected -----//

	if( firm_array.selected_recno == firm_recno )
	{
		firm_array.selected_recno = 0;
      info.disp();
   }

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

   firm_recno = 0;

	is_being_deleted = 0;


	//-------- dynamic unloading of firm bitmaps ---------//

//	FirmBuild* firmBuild = firm_res.get_build(firm_build_id);
	
	if( firm_id )
	{
//		firmBuild->free_bitmap_res();
		firm_id = 0;
	}
}
Example #9
0
File: ofirm.cpp Project: 112212/7k2
//--------- Begin of function Firm::init --------//
//
// It will initialize vars, and set the world matrix.
// Before calling init(), firm_recno should be set
//
// Note : it will set world matrix regardless the existing location content,
//        so you must ensure that the location is clean by calling
//        world.zoom_matrix->add_firm_test()
//
// <int> xLoc, yLoc  = the location of firm in the world map
// <int> nationRecno = the recno of nation which build this firm
// <int> firmId      = id(type) of the firm
// [char*] buildCode = the build code of the firm, no need to give if the firm just have one build type
// [short] builderRecno = recno of the builder unit
//
void Firm::init(int xLoc, int yLoc, int nationRecno, int firmId, char* buildCode, short builderRecno)
{
	FirmInfo* firmInfo = firm_res[firmId];

	firm_id = firmId;

	if( buildCode )
		firm_build_id = firmInfo->get_build_id(buildCode);
	
	if( !buildCode || !firm_build_id )					// some buildings like human offensive structures do not have different buildings for different nationality, so firm_build_id will be 0 
		firm_build_id = firmInfo->first_build_id;

	//----------- set vars -------------//

	nation_recno   = nationRecno;
	setup_date     = info.game_date;

	//----- set the firm's absolute positions on the map -----//

	FirmBuild* firmBuild = firm_res.get_build(firm_build_id);
	FirmBitmap* firmBitmap;
	
	race_id = firmInfo->get_race_id(buildCode);

	if( !race_id )			// some firms like human offensive structures do not have race_id.
		race_id = nation_array[nation_recno]->race_id;

	err_when( is_human() == (firmId >= FIRM_LAIR && firmId <= FIRM_MAGIC) );		// error when a human attempts to build a monster firm or a mosnter attempts to build a human firm

	loc_x1 = xLoc;
	loc_y1 = yLoc;
	loc_x2 = loc_x1 + firmBuild->loc_width  - 1;
	loc_y2 = loc_y1 + firmBuild->loc_height - 1;

	center_x = (loc_x1 + loc_x2) / 2;
	center_y = (loc_y1 + loc_y2) / 2;

	region_id = world.get_region_id( center_x, center_y );

	// get the height of the top left corner
	// altitude = world.get_corner(xLoc, yLoc)->get_altitude();
	altitude = world.get_corner(loc_x2+1, loc_y2+1)->get_altitude();

	abs_x1 = world.zoom_matrix->calc_abs_x(xLoc * LOCATE_WIDTH,
		yLoc * LOCATE_HEIGHT, altitude) + firmBuild->min_offset_x;
	abs_y1 = world.zoom_matrix->calc_abs_y(xLoc * LOCATE_WIDTH,
		yLoc * LOCATE_HEIGHT, altitude) + firmBuild->min_offset_y;
   abs_x2 = abs_x1 + firmBuild->max_bitmap_width  - 1;
   abs_y2 = abs_y1 + firmBuild->max_bitmap_height - 1;

   //--------- set animation frame vars ---------//

	int bitmapCount;
	int firstBitmap;
	int frameCount = firmBuild->frame_count;
	int aniPartCount = firmBuild->ani_part_count;
	// ##### begin Gilbert 30/10 ######//
	err_when( aniPartCount < 0 );
	err_when( aniPartCount > MAX_FRAME_COUNTERS );
	// firm_cur_frame = (char*) mem_add( sizeof(char) *aniPartCount);
	// firm_remain_frame_delay = (char*) mem_add( sizeof(char) *aniPartCount);
	// ##### end Gilbert 30/10 ######//
	
	// even not animation_full_size will have aniPartCount = 1 (set in firmres.cpp)
	for (int i = 0; i < aniPartCount ; i++)
	{
		firm_cur_frame[i] = 1;
		
		if( firmBuild->animate_full_size )
			// animate_full_size only supports animation of looping
			// it does not support random animation and in fact
			// it is now only used for no animation buildings
			firm_remain_frame_delay[i] = (char) firmBuild->frame_delay(1);
		else
		{
			// not animate_full_size supports animation of looping and
			// random animation and partial animation
			// unlike the animate_full_size animation, it search starting
			// from the 2nd frame for bitmaps (since now 1 frame may has more 
			// than 1 bitmap) with same animation part no. of the currently
			// searching part no., i. Then assign this animation part's delay and 
			// set its current_frame to the first found frame
			for ( int k=1; k <frameCount; k++ )
			{
				firstBitmap = firmBuild->first_bitmap(k+1);
				bitmapCount = firmBuild->bitmap_count(k+1);

				int j;
				for ( j=0; j <bitmapCount; j++ )
				{
					firmBitmap = firm_res.get_bitmap(firstBitmap + j);
					if( firmBitmap )
					{
						if (firmBitmap->ani_part == (i + 1))
						{
							firm_remain_frame_delay[i] = firmBitmap->delay;
							firm_cur_frame[i] = k + 1;
							break;
						}
					}
				}
				if (j < bitmapCount)
					break;
			}
		}
	}
		 
   //--------- initialize gaming vars ----------//

   hit_points     = (float) 0;
   place_max_hit_points = firmInfo->max_hit_points;

	// #### begin Gilbert 6/11 ######//
	defense_attribute = firmBuild->defense_attribute;
	// #### end Gilbert 6/11 ######//

	//------ set construction and builder -------//

	under_construction = firmInfo->buildable;       // whether the firm is under construction, if the firm is not buildable it is completed in the first place

	if( !under_construction )			// if this firm doesn't been to be constructed, set its hit points to the maximum
		hit_points = place_max_hit_points;

	if( builderRecno )
		set_builder(builderRecno);
	else
		builder_recno = 0;

	//------ update firm counter -------//

   firmInfo->total_firm_count++;
	
	if( nation_recno )
		firmInfo->inc_nation_firm_count(nation_recno);

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

   if( nation_recno > 0 )
   {
		Nation* nationPtr = nation_array[nation_recno];

      is_ai = nationPtr->is_ai();
		ai_processed = 1;

      //--------- increase firm counter -----------//

      nationPtr->nation_firm_count++;

      //-------- update last build date ------------//

      nationPtr->last_build_firm_date = info.game_date;
   }
   else
   {
      is_ai = 0;
      ai_processed = 0;
   }

   ai_status = FIRM_WITHOUT_ACTION;
   ai_link_checked = 1;       // check the connected firms if ai_link_checked = 0;

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

	active_link_town_recno = 0;

	setup_link();

	set_world_matrix();

	init_name();

	//----------- init AI -----------//

	if( nation_recno )
		nation_array[nation_recno]->add_firm_info(firm_id, firm_recno);

	//-------- init derived ---------//

	init_derived();         // init_derived() before set_world_matrix() so that init_derived has access to the original land info.

	
	//-------- dynamic loading of firm bitmaps ---------//
	firmBuild->load_bitmap_res();

}