123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- #include <COLOR.h>
- #include <OVGABUF.h>
- #include <OWORLD.h>
- #include <OWARPT.h>
- #include <ALL.h>
- #define WARPOINT_ZONE_SIZE 8
- #define WARPOINT_ZONE_COLUMN ((MAX_MAP_WIDTH + WARPOINT_ZONE_SIZE -1) / WARPOINT_ZONE_SIZE)
- #define WARPOINT_ZONE_ROW ((MAX_MAP_HEIGHT + WARPOINT_ZONE_SIZE -1) / WARPOINT_ZONE_SIZE)
- #define WARPOINT_STRENGTH 0x100000
- #define WARPOINT_STRENGTH_MAX 0x1000000
- #define DRAW_PHASE_PERIOD 16
- void WarPoint::inc()
- {
- if( (strength += WARPOINT_STRENGTH) > WARPOINT_STRENGTH_MAX )
- strength = WARPOINT_STRENGTH_MAX;
- }
- inline void WarPoint::decay()
- {
- strength >>= 1;
- }
- WarPointArray::WarPointArray()
- {
- war_point = NULL;
- init_flag = 0;
- }
- WarPointArray::~WarPointArray()
- {
- deinit();
- }
- void WarPointArray::init()
- {
- deinit();
-
- war_point = (WarPoint *)mem_add( sizeof(WarPoint) * WARPOINT_ZONE_COLUMN * WARPOINT_ZONE_ROW );
- memset(war_point, 0, sizeof(WarPoint) * WARPOINT_ZONE_COLUMN * WARPOINT_ZONE_ROW );
- draw_phase = 0;
- init_flag = 1;
- }
- void WarPointArray::deinit()
- {
- if( init_flag )
- {
- mem_del(war_point);
- init_flag = 0;
- }
- }
- void WarPointArray::draw_dot()
- {
- if( ++draw_phase >= DRAW_PHASE_PERIOD )
- draw_phase = 0;
- if( draw_phase & 1)
- return;
- static unsigned char dotColor[DRAW_PHASE_PERIOD/2] =
- { 0xa0, 0xa4, 0xa8, 0x00, 0xb0, 0xb4, 0xb8, 0x00 };
- unsigned char color = dotColor[draw_phase / 2];
- int x,y;
- short mapY;
- unsigned char *writePtr;
- unsigned char *vgaBufPtr = (unsigned char *)vga_back.buf_ptr();
- int vgaBufPitch = vga_back.buf_pitch();
- for( y = 0, mapY=MAP_Y1; y < WARPOINT_ZONE_ROW; ++y, mapY+=WARPOINT_ZONE_SIZE)
- {
- WarPoint *warPt = war_point + y * WARPOINT_ZONE_COLUMN;
- writePtr = vgaBufPtr + vgaBufPitch * mapY + MAP_X1;
- for( x = 0; x < WARPOINT_ZONE_COLUMN; ++x, ++warPt, writePtr+=WARPOINT_ZONE_SIZE)
- {
- if( warPt->strength > 0 )
- {
-
- unsigned char *map1Ptr = writePtr;
- unsigned char *map2Ptr = writePtr + WARPOINT_ZONE_SIZE-2;
- for( int i = 1; i < WARPOINT_ZONE_SIZE; ++i )
- {
- *map1Ptr = color;
- *map2Ptr = color;
- map1Ptr += vgaBufPitch + 1;
- map2Ptr += vgaBufPitch - 1;
- }
- }
- }
- }
- }
- void WarPointArray::process()
- {
- WarPoint *warPt = war_point;
- for( int i = WARPOINT_ZONE_COLUMN * WARPOINT_ZONE_ROW; i > 0; --i, warPt++)
- {
- warPt->decay();
- }
- }
- WarPoint *WarPointArray::get_ptr(int xLoc, int yLoc)
- {
- err_when(!init_flag);
- int c = xLoc / WARPOINT_ZONE_SIZE;
- int r = yLoc / WARPOINT_ZONE_SIZE;
- err_when( c < 0 || c >= WARPOINT_ZONE_COLUMN);
- err_when( r < 0 || r >= WARPOINT_ZONE_ROW);
- return war_point+ (r * WARPOINT_ZONE_COLUMN + c);
- }
- void WarPointArray::add_point(int xLoc, int yLoc)
- {
- get_ptr(xLoc, yLoc)->inc();
- }
|