~ubuntu-branches/ubuntu/saucy/lordsawar/saucy

« back to all changes in this revision

Viewing changes to src/gamebigmap.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese, Barry deFreese
  • Date: 2008-12-20 13:52:12 UTC
  • mfrom: (1.1.6 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20081220135212-noeb2w3y98ebo7o9
Tags: 0.1.4-1
[ Barry deFreese ]
* New upstream release.
* Move 0.0.8-2.1 changelog entry to correct point in changelog.
* Make lordsawar-data suggest lordsawar.
* Update my e-mail address.
* Add build-depends on intltool, uuid-dev, and libboost-dev.
* Don't install locales since there are no translations currently.
* Add simple man page for new lordsawar-pbm binary.
* Drop gcc4.3 patches as they have been fixed upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
#include "temple.h"
40
40
#include "road.h"
41
41
#include "playerlist.h"
42
 
#include "defs.h"
43
42
#include "File.h"
44
43
#include "GameMap.h"
45
44
#include "GraphicsCache.h"
 
45
#include "GraphicsLoader.h"
46
46
#include "game.h"
47
47
#include "FogMap.h"
 
48
#include "LocationBox.h"
48
49
 
49
50
#include "timing.h"
50
51
 
61
62
 
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)))
64
66
{
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;
69
 
  d_fighting = false;
70
71
 
71
72
  current_tile.x = current_tile.y = 0;
72
73
  mouse_state = NONE;
73
74
  input_locked = false;
74
75
 
75
 
  d_waypoints = File::getMiscPicture("waypoints.png");
 
76
  d_waypoints = GraphicsLoader::getMiscPicture("waypoints.png");
76
77
  prev_mouse_pos = Vector<int>(0, 0);
77
78
 
78
79
  // setup timeout
97
98
  if (!stack->getPath()->checkPath(stack))
98
99
    {
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";
101
102
    }
102
103
 
103
104
  stack_selected.emit(stack);
123
124
  if (input_locked)
124
125
    return;
125
126
 
 
127
  Player *active = Playerlist::getActiveplayer();
126
128
  Vector<int> tile = mouse_pos_to_tile(e.pos);
127
129
 
128
130
  if (e.button == MouseButtonEvent::LEFT_BUTTON
129
131
      && e.state == MouseButtonEvent::PRESSED)
130
132
    {
 
133
      if (active->getFogMap()->isCompletelyObscuredFogTile(tile) == true)
 
134
        return;
 
135
 
131
136
      Stack* stack = Playerlist::getActiveplayer()->getActivestack();
132
137
 
133
138
      if (stack)
175
180
 
176
181
          int dist = stack->getPath()->calculate(stack, p);
177
182
          if (dist == -2)
178
 
            cerr << _("error calculating path!");
 
183
            cerr << "error calculating path!";
179
184
 
180
185
          Vector<int>* dest = 0;
181
186
          if (!stack->getPath()->empty())
216
221
                    }
217
222
                  else
218
223
                    {
219
 
                      if (!stack->getPath()->empty() && 
 
224
                      if (stack->getPath()->empty() == false && 
220
225
                          stack->getPath()->getMovesExhaustedAtPoint() == 0)
221
226
                        deselect = true;
222
227
                      if ((d_cursor == GraphicsCache::SWORD ||
223
228
                           d_cursor == GraphicsCache::HEART) &&
224
229
                          stack->canMove() == false)
225
230
                        deselect = true;
 
231
                      if ((d_cursor == GraphicsCache::FEET ||
 
232
                           d_cursor == GraphicsCache::SHIP) &&
 
233
                          stack->canMove() == false)
 
234
                        deselect = true;
226
235
                    }
227
236
 
228
237
                  if (deselect)
249
258
            }
250
259
          else
251
260
            {
252
 
              if (City* c = Citylist::getInstance()->getObjectAt(tile.x, tile.y))
 
261
              if (City* c = Citylist::getInstance()->getObjectAt(tile))
253
262
                {
254
263
                  if (!c->isBurnt())
255
264
                    {
264
273
                }
265
274
              else if (Ruin *r = Ruinlist::getInstance()->getObjectAt(tile))
266
275
                {
267
 
                  ruin_queried (r, false);
 
276
                  if ((r->isHidden() == true && 
 
277
                       r->getOwner() == Playerlist::getActiveplayer()) ||
 
278
                      r->isHidden() == false)
 
279
                    ruin_queried (r, false);
268
280
                }
269
281
              else if (Temple *t = Templelist::getInstance()->getObjectAt(tile))
270
282
                {
311
323
    {
312
324
      if (e.state == MouseButtonEvent::PRESSED)
313
325
        {
314
 
          if (City* c = Citylist::getInstance()->getObjectAt(tile.x, tile.y))
 
326
          if (active->getFogMap()->isCompletelyObscuredFogTile(tile) == true)
 
327
            return;
 
328
          if (City* c = Citylist::getInstance()->getObjectAt(tile))
315
329
            {
316
330
              city_queried (c, true);
317
331
              mouse_state = SHOWING_CITY;
318
332
            }
319
 
          else if (Ruin* r = Ruinlist::getInstance()->getObjectAt(tile.x, tile.y))
 
333
          else if (Ruin* r = Ruinlist::getInstance()->getObjectAt(tile))
320
334
            {
321
335
              if ((r->isHidden() == true && 
322
336
                   r->getOwner() == Playerlist::getActiveplayer()) ||
326
340
                  mouse_state = SHOWING_RUIN;
327
341
                }
328
342
            }
329
 
          else if (Signpost* s = Signpostlist::getInstance()->getObjectAt(tile.x, tile.y))
 
343
          else if (Signpost* s = Signpostlist::getInstance()->getObjectAt(tile))
330
344
            {
331
345
              signpost_queried (s);
332
346
              mouse_state = SHOWING_SIGNPOST;
333
347
            }
334
 
          else if (Temple* t = Templelist::getInstance()->getObjectAt(tile.x, tile.y))
 
348
          else if (Temple* t = Templelist::getInstance()->getObjectAt(tile))
335
349
            {
336
350
              temple_queried.emit(t, true);
337
351
              mouse_state = SHOWING_TEMPLE;
338
352
            }
339
 
          else if (Stack *st = Stacklist::getObjectAt(tile.x, tile.y))
 
353
          else if (Stack *st = Stacklist::getObjectAt(tile))
340
354
            {
341
355
              if (d_see_opponents_stacks == true)
342
356
                {
397
411
          mouse_state = NONE;
398
412
        }
399
413
    }
 
414
  else if (e.button == MouseButtonEvent::WHEEL_UP)
 
415
    {
 
416
      zoom_in();
 
417
    }
 
418
  else if (e.button == MouseButtonEvent::WHEEL_DOWN)
 
419
    {
 
420
      zoom_out();
 
421
    }
 
422
}
 
423
 
 
424
void GameBigMap::zoom_in()
 
425
{
 
426
  if (input_locked)
 
427
    return;
 
428
  if ((zoom_step / 100.0) + magnification_factor <= max_magnification_factor / 100.0)
 
429
    {
 
430
      SDL_Surface *v = SDL_GetVideoSurface();
 
431
      int ts = GameMap::getInstance()->getTileset()->getTileSize();
 
432
      Rectangle new_view;
 
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);
 
440
    }
 
441
}
 
442
 
 
443
void GameBigMap::zoom_out()
 
444
{
 
445
  if (input_locked)
 
446
    return;
 
447
  if (magnification_factor - (zoom_step / 100.0) >= min_magnification_factor / 100.0)
 
448
    {
 
449
      SDL_Surface *v = SDL_GetVideoSurface();
 
450
      int ts = GameMap::getInstance()->getTileset()->getTileSize();
 
451
      Rectangle new_view;
 
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);
 
459
    }
400
460
}
401
461
 
402
462
void GameBigMap::determine_mouse_cursor(Stack *stack, Vector<int> tile)
403
463
{
404
 
  if (stack && mouse_state == DRAGGING_STACK)
 
464
  Player *active = Playerlist::getActiveplayer();
 
465
  if (active->getFogMap()->isCompletelyObscuredFogTile(tile))
 
466
    {
 
467
      d_cursor = GraphicsCache::HAND;
 
468
    }
 
469
  else if (stack && mouse_state == DRAGGING_STACK)
405
470
    {
406
471
      d_cursor = GraphicsCache::GOTO_ARROW;
407
472
    }
415
480
          City *c = Citylist::getInstance()->getObjectAt(tile);
416
481
          if (c)
417
482
            {
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;
454
519
            {
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)
458
523
                {
459
524
                  int delta = abs(stack->getPos().x - st->getPos().x);
460
525
                  if (delta <= 1)
507
572
      d_cursor = GraphicsCache::HAND;
508
573
      Stack *st;
509
574
 
510
 
      st = Playerlist::getActiveplayer()->getStacklist()->getObjectAt(tile);
 
575
      st = active->getStacklist()->getObjectAt(tile);
511
576
      if (st)
512
577
        {
513
 
          if (st->getOwner() == Playerlist::getActiveplayer())
 
578
          if (st->getOwner() == active)
514
579
            d_cursor = GraphicsCache::TARGET;
515
580
          else
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;
530
595
            }
531
596
          else if (t->getBuilding() == Maptile::RUIN)
532
 
            d_cursor = GraphicsCache::RUIN;
 
597
            {
 
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;
 
603
            }
533
604
          else if (t->getBuilding() == Maptile::TEMPLE)
534
605
            d_cursor = GraphicsCache::RUIN;
535
606
        }
536
607
 
537
608
    }
538
609
  cursor_changed.emit(d_cursor);
 
610
  //debugFogTile(tile.x, tile.y);
539
611
}
540
612
 
541
613
void GameBigMap::mouse_motion_event(MouseMotionEvent e)
544
616
  if (input_locked)
545
617
    return;
546
618
 
547
 
  Stack* stack = Playerlist::getActiveplayer()->getActivestack();
 
619
  Player *active = Playerlist::getActiveplayer();
 
620
  Stack* stack = active->getActivestack();
548
621
  Vector<int> tile = mouse_pos_to_tile(e.pos);
549
622
  if (tile.x < 0)
550
623
    tile.x = 0;
558
631
 
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)
562
635
    {
563
636
      //initial drag
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);
582
655
 
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);
585
658
 
586
659
      bool redraw_buffer = false;
587
660
 
606
679
 
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)
610
684
    {
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)
615
690
        {
616
691
          Vector<int> delta(0,0);
645
720
  last_tile = tile;
646
721
}
647
722
 
 
723
void GameBigMap::reset_zoom()
 
724
{
 
725
  magnification_factor = 1.0;
 
726
  screen_size_changed();
 
727
  draw(true);
 
728
  view_changed.emit(view);
 
729
}
 
730
 
 
731
void GameBigMap::zoom_view(double percent)
 
732
{
 
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();
 
740
  draw(true);
 
741
  view_changed.emit(view);
 
742
}
 
743
 
648
744
void GameBigMap::after_draw()
649
745
{
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)
 
765
        end--;
666
766
      for (list<Vector<int>*>::iterator it = stack->getPath()->begin();
667
 
           it != stack->getPath()->end(); it++)
 
767
           it != end; it++)
668
768
        {
669
769
          size_t wpsize = 40; //waypoint images are always 40x40
670
770
          pos = tile_to_buffer_pos(**it);
689
789
 
690
790
        }
691
791
 
 
792
      if (mouse_state == DRAGGING_STACK)
 
793
        {
 
794
          list<Vector<int>*>::iterator it = stack->getPath()->end();
 
795
          it--;
 
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);
 
801
          SDL_Rect r1, r2;
 
802
          r1.y = 0;
 
803
          r1.w = r1.h = tmp->w; 
 
804
          int offset = (tilesize - tmp->w) / 2;
 
805
          if (offset < 0)
 
806
            offset = 0;
 
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);
 
811
        }
692
812
    }
693
813
 
694
 
  if (stack)
 
814
  if (stack && d_fighting.getPos() == Vector<int>(-1,-1))
695
815
    {
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)
700
820
        {
701
821
          static int bigframe = -1;
702
822
          static int smallframe = -1;
703
823
 
704
824
          bigframe++;
705
 
          if (bigframe > 5)
 
825
          if (bigframe >= (int)gc->getNumberOfLargeSelectorFrames())
706
826
            bigframe = 0;
707
827
 
708
828
          smallframe++;
709
 
          if (smallframe > 3)
 
829
          if (smallframe >= (int)gc->getNumberOfSmallSelectorFrames())
710
830
            smallframe = 0;
711
831
 
712
832
          p = tile_to_buffer_pos(p);
724
844
 
725
845
          draw_stack (stack);
726
846
 
727
 
          if (d_fighting)
728
 
            {
729
 
              tmp = gc->getExplosionPic();
730
 
              SDL_BlitSurface(tmp, 0, buffer, &r);
731
 
            }
732
 
          else
 
847
          if (input_locked == false)
733
848
            {
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);
739
854
            }
740
 
 
741
855
        }
742
856
    }
 
857
 
 
858
  if (d_fighting.getPos() != Vector<int>(-1,-1))
 
859
    {
 
860
      Vector<int> p = tile_to_buffer_pos(d_fighting.getPos());
 
861
      SDL_Rect r;
 
862
      r.x = p.x;
 
863
      r.y = p.y;
 
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);
 
875
    }
743
876
}
744
877
 
745
878
void GameBigMap::set_shift_key_down (bool down)