Example #1
0
File: ow_plant.cpp Project: 7k2/7k2
//------------ begin of function World::plant_init ------------//
// plantTrial = number of places that randomly selected to plant a forest
// scanRadius = radius of the search area for killing a tree for subroutine plant_death()
//					remove a tree if the area has more than 3 trees
//
void World::plant_init(int plantTrial, int scanRadius)
{
    plant_count = 0;
    for( int trial = plantTrial; trial > 0; --trial )
    {
        // ------- randomly select a place to seed plant
        int y = 1+misc.random(max_y_loc-2);
        int x = 1+misc.random(max_x_loc-2);

        Location *l = get_loc(x,y);
        int build_flag = 1;
        char teraType = terrain_res[l->terrain_id]->average_type;

        // ------- all square around are the same terrain type and empty
        for( int y1 = y-1; y1 <= y+1; ++y1)
            for( int x1 = x-1; x1 <= x+1; ++x1)
            {
                l = get_loc(x1,y1);
                // #### begin Gilbert 6/3 #######//
                if( !l->can_add_plant() || terrain_res[l->terrain_id]->average_type != teraType)
                    build_flag = 0;
                // #### end Gilbert 6/3 #######//
            }

        if( build_flag )
        {
            short plantBitmap = plant_res.scan( 0, teraType, 0);
            short plantArray[PLANT_ARRAY_SIZE];
            for( int i = 0; i < PLANT_ARRAY_SIZE; ++i)
            {
                plantArray[i] = plant_res.plant_recno(plant_res.scan(0, teraType, 0));
            }
            if( plantArray[0] )
            {
                plant_spray(plantArray, 1 + misc.random(3), 1 + misc.random(2), x, y);
            }
        }
    }
    int xLoc, yLoc;
    short plantBitmap = plant_res.scan( 0, 0, 0);
    short plantArray[PLANT_ARRAY_SIZE];
    for( int i = 0; i < PLANT_ARRAY_SIZE; ++i)
        plantArray[i] = plant_res.plant_recno(plant_res.scan(0, 0, 0));

    for( yLoc = 0; yLoc < max_y_loc; ++yLoc )
    {
        for( xLoc = 0; xLoc < max_x_loc; ++xLoc )
        {
            Location* locPtr = get_loc( xLoc, yLoc );
            if(locPtr->has_dirt())
            {
                Rock *dirtPtr = dirt_array[locPtr->dirt_recno()];
                RockInfo *dirtInfo = rock_res.get_rock_info(dirtPtr->rock_recno);
                if (dirtInfo->rock_type == 'P')
                {
                    if( plantArray[0] )
                        plant_spray(plantArray, 0, misc.random(3), xLoc, yLoc);
                }
            }
        }
    }
    // ------- kill some plant ----------//
    plant_death(1, scanRadius);
}
Example #2
0
//---------- Begin of function MapMatrix::draw_map ------------//
// see also World::explore
//
void MapMatrix::draw_map()
{
	//----------- draw map now ------------//

	sys.yield();

	short	fireColor = vga_back.translate_color(FIRE_COLOR);
	short plantColor = vga_back.translate_color(plant_res.plant_map_color);
	short	seaColor = vga_back.translate_color(0x32);
	short rockColor = vga_back.translate_color( 0x59 );
	short mapModeColor = vga_back.translate_color( VGA_GRAY+10 );
	short unexploredColor = vga_back.translate_color(UNEXPLORED_COLOR);
	short shadowColor = vga_back.translate_color( VGA_GRAY+2 );
	short roadColor = vga_back.translate_color( VGA_GRAY+12 );
	short	nationColorArray[MAX_NATION+2];
	for( int n = 0; n < MAX_NATION+2; ++n )
		nationColorArray[n] = vga_back.translate_color(nation_array.nation_power_color_array[n]);
	// #### begin Ban 8/12 #######//
	int temp3 = vga_back.buf_true_pitch() -2;
	short *temp6 = vga_back.buf_ptr((image_x1 + image_x2)/2, image_y1);
#ifdef ASM_FOR_MSVC
	_asm
	{
		MOV AX , DS
		MOV	ES , AX
		MOV	EDX, temp3		
		MOV	EDI, temp6
		CLD                 
		MOV	AX, word ptr UNEXPLORED_COLOR
		MOV	CX, AX				// processing the color for drawing
		SHL	EAX, 16
		MOV	AX, CX
		MOV	EBX, 100
		XOR ECX, ECX
PutLineUpper:					// draw upper triangle
		INC	ECX
		REP	STOSD
		MOV ECX, 101			// restore ECX after STOSD for updating EDI
		SUB ECX, EBX
		ADD	EDI, EDX			// updating EDI to start point of next line
		SUB EDI, ECX
		SUB EDI, ECX
		SUB EDI, ECX
		SUB EDI, ECX
		DEC	EBX					// decrease the remain height
		JNZ	PutLineUpper		// loop
		MOV	EBX, 99				// ready parameters for drawing lower triangle
		ADD EDX, 4
		ADD EDI, 4
PutLineLower:					// draw lower triangle
		MOV ECX, EBX
		REP	STOSD
		ADD	EDI, EDX			// updating EDI to start point of next line
		SUB EDI, EBX
		SUB EDI, EBX
		SUB EDI, EBX
		SUB EDI, EBX
		DEC	EBX					// decrease the remain height
		JNZ	PutLineLower		// loop
	}
#else
		int lineDiff = temp3 / 2;
		int lineLength = 2;
		// Blacken upper half of minimap.
		for ( int i = 0; i < 100; ++i )
		{
			for ( int j = 0; j < lineLength; ++j )
			{
				*temp6 = UNEXPLORED_COLOR;
				++temp6;
			}
			temp6 += lineDiff - lineLength;
			lineLength += 2;
		}
		// Blacken lower half of minimap.
		lineLength = 99 * 2;
		lineDiff += 2;
		temp6 += 2;
		for ( int i = 0; i < 99; ++i )
		{
			for ( int j = 0; j < lineLength; ++j )
			{
				*temp6 = UNEXPLORED_COLOR;
				++temp6;
			}
			temp6 += lineDiff - lineLength;
			lineLength -= 2;
		}
#endif
	// #### end Ban 8/12 #######//
//	{	// traversal of location in MapMatrix
//		int pixelX = (image_x1 + image_x2 + 1) / 2;
//		int pixelY = image_y1;
//		int xLoc, yLoc;
//		int writePtrInc = vga_back.buf_pitch() + 1;
//		for( yLoc = 0; yLoc < max_y_loc; (yLoc&1?++pixelY:--pixelX) , ++yLoc )
//		{
//			short* writePtr  = vga_back.buf_ptr(pixelX, pixelY);
//			xLoc = 0;
//			Location *locPtr = get_loc( xLoc, yLoc );
//			for( xLoc = 0; xLoc < max_x_loc; (xLoc += 2), (writePtr += writePtrInc), (locPtr+=2) )
//			{
//			}
//		}
//	}

	switch(map_mode)
	{
	case MAP_MODE_TERRAIN:
		{
			int pixelX = (image_x1 + image_x2 + 1) / 2;
			int pixelY = image_y1;
			int xLoc, yLoc;
			int writePtrInc = vga_back.buf_pitch() + 1;
			for( yLoc = 0; yLoc < max_y_loc; (yLoc&1?++pixelY:--pixelX) , ++yLoc )
			{
				short* writePtr  = vga_back.buf_ptr(pixelX, pixelY);
				int tileYOffset = (yLoc & TERRAIN_TILE_Y_MASK) * TERRAIN_TILE_WIDTH;
				xLoc = 0;
				Location* locPtr = get_loc( xLoc, yLoc );
				for( ; xLoc < max_x_loc; (xLoc += 2), (locPtr += 2), (writePtr += writePtrInc) )
				{
					if( locPtr->explored() )
					{
						// ##### begin Gilbert 10/2 #######//
						if( filter_object_flag || filter_nation_flag )		// do not anything except filtered objects when filters are on
							*writePtr = mapModeColor;
						else if( locPtr->fire_str() > 0)
						// ##### end Gilbert 10/2 #######//
							*writePtr = fireColor;
						else if( locPtr->is_plant() || xLoc+1<max_x_loc && locPtr[1].is_plant() )
							*writePtr = plantColor;
						else if( locPtr->is_rock() )
							*writePtr = rockColor;
						else if( locPtr->has_dirt() )
						{
							Rock *dirtPtr = dirt_array[locPtr->dirt_recno()];
							RockInfo *dirtInfo = rock_res.get_rock_info(dirtPtr->rock_recno);
							if (dirtInfo->rock_type == 'P')
								*writePtr = seaColor;
							else
								*writePtr = rockColor;
						}

						else if( locPtr->is_road() )
							*writePtr = vga_back.translate_color(terrain_res.get_map_tile(locPtr->road_terrain_id)[tileYOffset + (xLoc & TERRAIN_TILE_X_MASK)]);
						else
						{
							if( xLoc < 2 || 
								terrain_res[locPtr->terrain_id]->average_type >=
								terrain_res[(locPtr-2)->terrain_id]->average_type )
							{
								// get terrain pixel from terrain_res
								*writePtr = vga_back.translate_color(terrain_res.get_map_tile(locPtr->terrain_id)[tileYOffset + (xLoc & TERRAIN_TILE_X_MASK)]);
							}
							else
							{
								*writePtr = shadowColor;
							}
						}
					}
					//else 	// not needed because filled black already
					//{
					//	*writePtr = unexploredColor;
					//}
				}
			}
		}
		break;


	// ##### begin Gilbert 2/11 #####//
	case MAP_MODE_TRADE:
	// ##### end Gilbert 2/11 #####//
	case MAP_MODE_SPOT:
		{	// traversal of location in MapMatrix
			int pixelX = (image_x1 + image_x2 + 1) / 2;
			int pixelY = image_y1;
			int xLoc, yLoc;
			int writePtrInc = vga_back.buf_pitch() + 1;
			for( yLoc = 0; yLoc < max_y_loc; (yLoc&1?++pixelY:--pixelX) , ++yLoc )
			{
				short* writePtr  = vga_back.buf_ptr(pixelX, pixelY);
				xLoc = 0;
				Location* locPtr = get_loc( xLoc, yLoc );
				for( ; xLoc < max_x_loc; (xLoc += 2), (locPtr +=2), (writePtr += writePtrInc) )
				{
					if( locPtr->explored() )
					{
						*writePtr = mapModeColor;
					}
				}
			}
		}
		break;

	case MAP_MODE_POWER:
		{
			int pixelX = (image_x1 + image_x2 + 1) / 2;
			int pixelY = image_y1;
			int xLoc, yLoc;
			int writePtrInc = vga_back.buf_pitch() + 1;
			for( yLoc = 0; yLoc < max_y_loc; (yLoc&1?++pixelY:--pixelX) , ++yLoc )
			{
				short* writePtr  = vga_back.buf_ptr(pixelX, pixelY);
				xLoc = 0;
				Location *locPtr = get_loc( xLoc, yLoc );
				for( xLoc = 0; xLoc < max_x_loc; (xLoc += 2), (locPtr +=2), (writePtr += writePtrInc) )
				{
					if( locPtr->explored() )
					{
						// ####### begin Gilbert 10/2 #########//
						if( filter_object_flag || filter_nation_flag )		// do not anything except filtered objects when filters are on
							*writePtr = mapModeColor;
						else if( locPtr->sailable() )
						// ####### end Gilbert 10/2 #########//
							*writePtr = seaColor;
						else if( locPtr->is_rock() || locPtr[1].is_rock() )
							*writePtr = rockColor;
/*						else if( locPtr->has_dirt() )
						{
							Rock *dirtPtr = dirt_array[locPtr->dirt_recno()];
							RockInfo *dirtInfo = rock_res.get_rock_info(dirtPtr->rock_recno);
							if (dirtInfo->rock_type == 'P')
								*writePtr = seaColor;
							else
								*writePtr = rockColor;
						}

						else if( locPtr->is_plant() || xLoc+1<max_x_loc && locPtr[1].is_plant() )
							*writePtr = plantColor;
*/						else
						// ###### begin Gilbert 21/12 ########//
						{
							if( power_mode )
								*writePtr = nationColorArray[locPtr->power_nation_recno];
							else
								*writePtr = nationColorArray[0];
						}
						// ###### end Gilbert 21/12 ########//
					}
				}
			}
		}
		break;

	case MAP_MODE_ALTITUDE:
		{
			int pixelX = (image_x1 + image_x2 + 1) / 2;
			int pixelY = image_y1;
			int xLoc, yLoc;
			int writePtrInc = vga_back.buf_pitch() + 1;
			for( yLoc = 0; yLoc < max_y_loc; (yLoc&1?++pixelY:--pixelX) , ++yLoc )
			{
				short* writePtr  = vga_back.buf_ptr(pixelX, pixelY);
				xLoc = 0;
				for( xLoc = 0; xLoc < max_x_loc; (xLoc += 2), (writePtr += writePtrInc) )
				{
					Corner *cornerPtr = get_corner( xLoc, yLoc );
					short alt = cornerPtr->get_altitude();
					if( alt > 255 )
						alt = 255;
					else if( alt < 0 )
						alt = 0;
					*writePtr = vga.make_pixel((BYTE)alt, 128, 32);
				}
			}
		}
		break;
	}

	sys.yield();
}