62
63
GameBigMap::GameBigMap(bool intense_combat, bool see_opponents_production,
63
64
bool see_opponents_stacks, bool military_advisor)
65
:d_fighting(LocationBox(Vector<int>(-1,-1)))
65
67
d_intense_combat = intense_combat;
66
68
d_see_opponents_production = see_opponents_production;
67
69
d_see_opponents_stacks = see_opponents_stacks;
68
70
d_military_advisor = military_advisor;
71
72
current_tile.x = current_tile.y = 0;
72
73
mouse_state = NONE;
73
74
input_locked = false;
75
d_waypoints = File::getMiscPicture("waypoints.png");
76
d_waypoints = GraphicsLoader::getMiscPicture("waypoints.png");
76
77
prev_mouse_pos = Vector<int>(0, 0);
97
98
if (!stack->getPath()->checkPath(stack))
99
100
//error handling is required here, up to now we only barf on cerr
100
cerr << _("original path of stack was blocked\n");
101
cerr << "original path of stack was blocked\n";
103
104
stack_selected.emit(stack);
123
124
if (input_locked)
127
Player *active = Playerlist::getActiveplayer();
126
128
Vector<int> tile = mouse_pos_to_tile(e.pos);
128
130
if (e.button == MouseButtonEvent::LEFT_BUTTON
129
131
&& e.state == MouseButtonEvent::PRESSED)
133
if (active->getFogMap()->isCompletelyObscuredFogTile(tile) == true)
131
136
Stack* stack = Playerlist::getActiveplayer()->getActivestack();
176
181
int dist = stack->getPath()->calculate(stack, p);
178
cerr << _("error calculating path!");
183
cerr << "error calculating path!";
180
185
Vector<int>* dest = 0;
181
186
if (!stack->getPath()->empty())
219
if (!stack->getPath()->empty() &&
224
if (stack->getPath()->empty() == false &&
220
225
stack->getPath()->getMovesExhaustedAtPoint() == 0)
222
227
if ((d_cursor == GraphicsCache::SWORD ||
223
228
d_cursor == GraphicsCache::HEART) &&
224
229
stack->canMove() == false)
231
if ((d_cursor == GraphicsCache::FEET ||
232
d_cursor == GraphicsCache::SHIP) &&
233
stack->canMove() == false)
265
274
else if (Ruin *r = Ruinlist::getInstance()->getObjectAt(tile))
267
ruin_queried (r, false);
276
if ((r->isHidden() == true &&
277
r->getOwner() == Playerlist::getActiveplayer()) ||
278
r->isHidden() == false)
279
ruin_queried (r, false);
269
281
else if (Temple *t = Templelist::getInstance()->getObjectAt(tile))
312
324
if (e.state == MouseButtonEvent::PRESSED)
314
if (City* c = Citylist::getInstance()->getObjectAt(tile.x, tile.y))
326
if (active->getFogMap()->isCompletelyObscuredFogTile(tile) == true)
328
if (City* c = Citylist::getInstance()->getObjectAt(tile))
316
330
city_queried (c, true);
317
331
mouse_state = SHOWING_CITY;
319
else if (Ruin* r = Ruinlist::getInstance()->getObjectAt(tile.x, tile.y))
333
else if (Ruin* r = Ruinlist::getInstance()->getObjectAt(tile))
321
335
if ((r->isHidden() == true &&
322
336
r->getOwner() == Playerlist::getActiveplayer()) ||
326
340
mouse_state = SHOWING_RUIN;
329
else if (Signpost* s = Signpostlist::getInstance()->getObjectAt(tile.x, tile.y))
343
else if (Signpost* s = Signpostlist::getInstance()->getObjectAt(tile))
331
345
signpost_queried (s);
332
346
mouse_state = SHOWING_SIGNPOST;
334
else if (Temple* t = Templelist::getInstance()->getObjectAt(tile.x, tile.y))
348
else if (Temple* t = Templelist::getInstance()->getObjectAt(tile))
336
350
temple_queried.emit(t, true);
337
351
mouse_state = SHOWING_TEMPLE;
339
else if (Stack *st = Stacklist::getObjectAt(tile.x, tile.y))
353
else if (Stack *st = Stacklist::getObjectAt(tile))
341
355
if (d_see_opponents_stacks == true)
397
411
mouse_state = NONE;
414
else if (e.button == MouseButtonEvent::WHEEL_UP)
418
else if (e.button == MouseButtonEvent::WHEEL_DOWN)
424
void GameBigMap::zoom_in()
428
if ((zoom_step / 100.0) + magnification_factor <= max_magnification_factor / 100.0)
430
SDL_Surface *v = SDL_GetVideoSurface();
431
int ts = GameMap::getInstance()->getTileset()->getTileSize();
433
double mag = magnification_factor + (zoom_step / 100.0);
434
new_view.w = v->w / (ts * mag) + 1;
435
new_view.h = v->h / (ts * mag) + 1;
436
if (new_view.w <= GameMap::getWidth() &&
437
new_view.h <= GameMap::getHeight() &&
438
new_view.w >= 0 && new_view.h >= 0)
439
zoom_view(zoom_step);
443
void GameBigMap::zoom_out()
447
if (magnification_factor - (zoom_step / 100.0) >= min_magnification_factor / 100.0)
449
SDL_Surface *v = SDL_GetVideoSurface();
450
int ts = GameMap::getInstance()->getTileset()->getTileSize();
452
double mag = magnification_factor - (zoom_step / 100.0);
453
new_view.w = v->w / (ts * mag) + 1;
454
new_view.h = v->h / (ts * mag) + 1;
455
if (new_view.w <= GameMap::getWidth() &&
456
new_view.h <= GameMap::getHeight() &&
457
new_view.w >= 0 && new_view.h >= 0)
458
zoom_view(-zoom_step);
402
462
void GameBigMap::determine_mouse_cursor(Stack *stack, Vector<int> tile)
404
if (stack && mouse_state == DRAGGING_STACK)
464
Player *active = Playerlist::getActiveplayer();
465
if (active->getFogMap()->isCompletelyObscuredFogTile(tile))
467
d_cursor = GraphicsCache::HAND;
469
else if (stack && mouse_state == DRAGGING_STACK)
406
471
d_cursor = GraphicsCache::GOTO_ARROW;
415
480
City *c = Citylist::getInstance()->getObjectAt(tile);
418
if (c->getOwner() == Playerlist::getActiveplayer())
483
if (c->getOwner() == active)
419
484
d_cursor = GraphicsCache::FEET;
420
485
else if (c->isBurnt() == true)
421
486
d_cursor = GraphicsCache::FEET;
455
520
Maptile *t = GameMap::getInstance()->getTile(tile);
456
521
Stack *st = Stacklist::getObjectAt(tile);
457
if (st && st->getOwner() != Playerlist::getActiveplayer())
522
if (st && st->getOwner() != active)
459
524
int delta = abs(stack->getPos().x - st->getPos().x);
507
572
d_cursor = GraphicsCache::HAND;
510
st = Playerlist::getActiveplayer()->getStacklist()->getObjectAt(tile);
575
st = active->getStacklist()->getObjectAt(tile);
513
if (st->getOwner() == Playerlist::getActiveplayer())
578
if (st->getOwner() == active)
514
579
d_cursor = GraphicsCache::TARGET;
516
581
d_cursor = GraphicsCache::HAND;
523
588
City *c = Citylist::getInstance()->getObjectAt(tile);
524
589
if (c->isBurnt() == true)
525
590
d_cursor = GraphicsCache::HAND;
526
else if (c->getOwner() == Playerlist::getActiveplayer())
591
else if (c->getOwner() == active)
527
592
d_cursor = GraphicsCache::ROOK;
528
593
else if (d_see_opponents_production == true)
529
594
d_cursor = GraphicsCache::ROOK;
531
596
else if (t->getBuilding() == Maptile::RUIN)
532
d_cursor = GraphicsCache::RUIN;
598
Ruin *ruin = Ruinlist::getInstance()->getObjectAt(tile);
599
if (ruin->isHidden() == true && ruin->getOwner() == active)
600
d_cursor = GraphicsCache::RUIN;
601
else if (ruin->isHidden() == false)
602
d_cursor = GraphicsCache::RUIN;
533
604
else if (t->getBuilding() == Maptile::TEMPLE)
534
605
d_cursor = GraphicsCache::RUIN;
538
609
cursor_changed.emit(d_cursor);
610
//debugFogTile(tile.x, tile.y);
541
613
void GameBigMap::mouse_motion_event(MouseMotionEvent e)
559
632
if (e.pressed[MouseMotionEvent::LEFT_BUTTON]
560
633
&& (mouse_state == NONE || mouse_state == SHOWING_STACK) &&
561
stack && stack->getPos() == tile)
634
stack && stack->getPos() == tile && active->getFogMap()->isCompletelyObscuredFogTile(tile) == false)
564
637
mouse_state = DRAGGING_STACK;
578
651
Vector<int> screen_dim(screen->w, screen->h);
579
652
view_pos = clip(Vector<int>(0, 0),
580
653
view_pos + delta,
581
GameMap::get_dim() * ts - screen_dim);
654
GameMap::get_dim() * ts *magnification_factor - screen_dim);
583
656
// calculate new view position in tiles, rounding up
584
Vector<int> new_view = (view_pos + Vector<int>(ts - 1, ts - 1)) / ts;
657
Vector<int> new_view = (view_pos + Vector<int>(ts * magnification_factor - 1, ts * magnification_factor - 1)) / (ts * magnification_factor);
586
659
bool redraw_buffer = false;
607
680
// drag stack with left mouse button
608
681
if (e.pressed[MouseMotionEvent::LEFT_BUTTON]
609
&& (mouse_state == DRAGGING_STACK))
682
&& (mouse_state == DRAGGING_STACK) &&
683
active->getFogMap()->isCompletelyObscuredFogTile(tile) == false)
611
685
//subsequent dragging
612
686
//alright. calculate the path, and show it but don't move
613
687
//be careful that we don't drop our path on bad objects
688
//also, slide the whole view if we drag out of view
614
689
if (is_inside(view, tile) == false)
616
691
Vector<int> delta(0,0);
645
720
last_tile = tile;
723
void GameBigMap::reset_zoom()
725
magnification_factor = 1.0;
726
screen_size_changed();
728
view_changed.emit(view);
731
void GameBigMap::zoom_view(double percent)
733
magnification_factor += percent / 100.0;
734
//call with +2, or -2
735
//Rectangle new_view = view;
736
//new_view.dim += Vector<int>(tiles, tiles);
737
//new_view.pos += Vector<int>(tiles*-1/2, tiles*-1/2);
738
//set_view (new_view);
739
screen_size_changed();
741
view_changed.emit(view);
648
744
void GameBigMap::after_draw()
650
746
GraphicsCache *gc = GraphicsCache::getInstance();
663
759
// draw all waypoints
664
760
Uint32 pathcount = 0;
665
761
bool canMoveThere = true;
762
list<Vector<int>*>::iterator end = stack->getPath()->end();
763
//if we're dragging, we don't draw the last waypoint circle
764
if (stack->getPath()->size() > 0 && mouse_state == DRAGGING_STACK)
666
766
for (list<Vector<int>*>::iterator it = stack->getPath()->begin();
667
it != stack->getPath()->end(); it++)
669
769
size_t wpsize = 40; //waypoint images are always 40x40
670
770
pos = tile_to_buffer_pos(**it);
792
if (mouse_state == DRAGGING_STACK)
794
list<Vector<int>*>::iterator it = stack->getPath()->end();
796
//this is where the ghosted army unit picture goes.
797
Army *a = *stack->begin();
798
SDL_Surface *tmp = gc->getArmyPic(a);
799
size_t wpsize = tmp->w;
800
pos = tile_to_buffer_pos(**it);
803
r1.w = r1.h = tmp->w;
804
int offset = (tilesize - tmp->w) / 2;
807
r2.x = pos.x + offset;
808
r2.y = pos.y + offset;
809
r2.w = r2.h = wpsize;
810
SDL_BlitSurface(tmp, 0, buffer, &r2);
814
if (stack && d_fighting.getPos() == Vector<int>(-1,-1))
696
816
// draw the selection
697
817
Vector<int> p = stack->getPos();
698
818
if (is_inside(buffer_view, Vector<int>(p.x, p.y)) &&
699
FogMap::isFogged(p) == false)
819
FogMap::isFogged(p, Playerlist::getActiveplayer()) == false)
701
821
static int bigframe = -1;
702
822
static int smallframe = -1;
825
if (bigframe >= (int)gc->getNumberOfLargeSelectorFrames())
829
if (smallframe >= (int)gc->getNumberOfSmallSelectorFrames())
712
832
p = tile_to_buffer_pos(p);
725
845
draw_stack (stack);
729
tmp = gc->getExplosionPic();
730
SDL_BlitSurface(tmp, 0, buffer, &r);
847
if (input_locked == false)
734
849
if (num_selected > 1)
735
850
tmp = gc->getSelectorPic(0, bigframe, stack->getOwner());
737
852
tmp = gc->getSelectorPic(1, smallframe, stack->getOwner());
738
853
SDL_BlitSurface(tmp, 0, buffer, &r);
858
if (d_fighting.getPos() != Vector<int>(-1,-1))
860
Vector<int> p = tile_to_buffer_pos(d_fighting.getPos());
864
r.w = r.h = tilesize * d_fighting.getSize();
865
SDL_Surface *tmp = gc->getExplosionPic();
866
SDL_SetAlpha(tmp, 0, 0);
867
SDL_PixelFormat* fmt = tmp->format;
868
SDL_Surface *explode = SDL_CreateRGBSurface
869
(SDL_SWSURFACE, d_fighting.getSize() * tilesize,
870
d_fighting.getSize() * tilesize,
871
fmt->BitsPerPixel, fmt->Rmask, fmt->Gmask, fmt->Bmask, fmt->Amask);
872
SDL_SoftStretch(tmp, 0, explode, 0);
873
SDL_BlitSurface(explode, 0, buffer, &r);
874
SDL_FreeSurface(explode);
745
878
void GameBigMap::set_shift_key_down (bool down)