Advanced Strategic Command
pg_mapdisplay.cpp
Go to the documentation of this file.
1 
6 /***************************************************************************
7  mapdisplay.cpp - description
8  -------------------
9  begin : Wed Jan 24 2001
10  copyright : (C) 2001 by Martin Bickel
11  email : bickel@asc-hq.org
12  ***************************************************************************/
13 
14 /***************************************************************************
15  * *
16  * This program is free software; you can redistribute it and/or modify *
17  * it under the terms of the GNU General Public License as published by *
18  * the Free Software Foundation; either version 2 of the License, or *
19  * (at your option) any later version. *
20  * *
21  ***************************************************************************/
22 
23 // #define debugmapdisplay
24 
25 
26 #include <cmath>
27 #include <limits>
28 
29 #include "pgeventsupplier.h"
30 
31 #include "global.h"
32 #include "typen.h"
33 #include "mapdisplay.h"
34 #include "vehicletype.h"
35 #include "buildingtype.h"
36 #include "spfst.h"
37 #include "dialog.h"
38 #include "mainscreenwidget.h"
39 #include "sdl/sound.h"
40 #include "dialogs/attackpanel.h"
41 #include "spfst-legacy.h"
42 #include "gameoptions.h"
43 
44 extern bool tempsvisible;
46 
47 
48 #ifdef debugmapdisplay
49 #include <iostream>
50 #endif
51 
52 
54  MapDisplayPG* mapDisplayWidget;
55  public:
56  PG_MapDisplay( MapDisplayPG* mapDisplayWidget_ ) : mapDisplayWidget( mapDisplayWidget_ ) {};
57 
58  int displayMovingUnit ( const MapCoordinate3D& start, const MapCoordinate3D& dest, Vehicle* vehicle, int fieldnum, int totalmove, SoundStartCallback soundStart, int duration );
59  void deleteVehicle ( Vehicle* vehicle ) {};
60  void displayMap ( void );
61  void displayMap ( Vehicle* vehicle );
62  void displayPosition ( int x, int y );
63  void resetMovement ( void ) {};
64  void startAction ( void );
65  void stopAction ( void );
66  void cursor_goto ( const MapCoordinate& pos );
67  void displayActionCursor ( int x1, int y1, int x2, int y2 ) {};
68  void removeActionCursor ( void ) {
69  mapDisplayWidget->cursor.invisible = 1;
70  };
71  void updateDashboard ();
72  void repaintDisplay ();
73  void setTempView( bool view ) { tempsvisible = view; };
74  void showBattle( tfight& battle );
75  void playPositionalSound( const MapCoordinate& pos, Sound* snd );
77 };
78 
79 
80 
81 int PG_MapDisplay :: displayMovingUnit ( const MapCoordinate3D& start, const MapCoordinate3D& dest, Vehicle* vehicle, int fieldnum, int totalmove, SoundStartCallback soundStart, int duration )
82 {
83  if ( actmap->getPlayerView() == -2 )
84  return 0;
85 
86  MapCoordinate3D newstart = start;
87  MapCoordinate3D newdest = dest;
88 
89  if ( newdest.getNumericalHeight() == -1 )
90  newdest.setNumericalHeight( newstart.getNumericalHeight() );
91  else
92  if ( newstart.getNumericalHeight() == -1 )
93  newstart.setNumericalHeight( newdest.getNumericalHeight() );
94 
95  if ( newstart.getNumericalHeight() < newdest.getNumericalHeight() ) {
96  if ( fieldnum+1 < totalmove )
97  newdest.setNumericalHeight( newstart.getNumericalHeight() );
98  }
99 
100  if ( newstart.getNumericalHeight() > newdest.getNumericalHeight() ) {
101  if ( fieldnum > 0 )
102  newstart.setNumericalHeight( newdest.getNumericalHeight() );
103  }
104 
105  MapField* fld1 = actmap->getField ( start );
106  int view1 = fieldVisibility ( fld1, actmap->getPlayerView() );
107 
108  MapField* fld2 = actmap->getField ( dest );
109  int view2 = fieldVisibility ( fld2, actmap->getPlayerView() );
110 
111  bool shareView;
112  if ( actmap->getPlayerView() >= 0)
113  shareView = actmap->player[actmap->getPlayerView()].diplomacy.sharesView( vehicle->getOwner() );
114  else
115  shareView = false;
116 
117  if ( (view1 >= visible_now || view2 >= visible_now ) || ( vehicle->getOwner() == actmap->getPlayerView() ) || shareView || actmap->getPlayerView() == -1 )
118  if ( ((vehicle->height >= chschwimmend) && (vehicle->height <= chhochfliegend)) || (( view1 == visible_all) || ( view2 == visible_all )) || ( actmap->actplayer == actmap->getPlayerView() ) || shareView || actmap->getPlayerView() == -1 ) {
119  soundStart( 1 );
120  mapDisplayWidget->displayUnitMovement( actmap, vehicle, newstart, newdest, duration );
121  }
122 
123 
124  int result = 0;
125  if (view1 >= visible_now )
126  result +=1;
127 
128  if ( view2 >= visible_now )
129  result +=2;
130 
131  return result;
132 }
133 
135 {
136  showAttackAnimation( battle, actmap );
137 }
138 
139 
141 {
142  ::repaintMap();
143 }
144 
146 {
147  mapDisplayWidget->cursor.goTo( pos );
148 }
149 
150 
152 {
153  mapDisplayWidget->registerAdditionalUnit( vehicle );
154  ::repaintMap();
155  mapDisplayWidget->registerAdditionalUnit( NULL );
156 }
157 
158 
159 void PG_MapDisplay :: displayPosition ( int x, int y )
160 {
161  if ( !mapDisplayWidget->fieldInView( MapCoordinate(x,y) ))
162  mapDisplayWidget->centerOnField( MapCoordinate(x,y) );
163  else
164  mapDisplayWidget->Update();
165 }
166 
167 
169 {
170 }
171 
173 {
174 }
175 
177 {
178  updateFieldInfo();
179 }
180 
182 {
184 }
185 
187 {
188  snd->play();
189 }
190 
191 
193 {
194  static PG_MapDisplay* mapDisplay = NULL;
195  if ( !mapDisplay ) {
196  assert( theGlobalMapDisplay );
197  mapDisplay = new PG_MapDisplay( theGlobalMapDisplay );
198  }
199  return *mapDisplay;
200 }
201 
void showBattle(tfight &battle)
int movespeed
1/100 sec for a unit to move from one field to the next
Definition: gameoptions.h:63
void play(void)
Definition: sound.cpp:453
bool fieldInView(const MapCoordinate &mc)
map accessing and usage routines used by ASC and the mapeditor
#define chschwimmend
Definition: typen.h:412
Definition: sound.h:20
void displayPosition(int x, int y)
DiplomaticStateVector diplomacy
Definition: player.h:209
void updateDashboard()
int getOwner() const
returns the number of the player this vehicle/building belongs to
int displayMovingUnit(const MapCoordinate3D &start, const MapCoordinate3D &dest, Vehicle *vehicle, int fieldnum, int totalmove, SoundStartCallback soundStart, int duration)
void displayMap(void)
int getNumericalHeight() const
Definition: typen.h:242
sigc::signal< void > repaintMap
}@
Definition: spfst.cpp:45
bool sharesView(PlayerID receivingPlayer) const
Definition: player.h:81
void cursor_goto(const MapCoordinate &pos)
#define chhochfliegend
Definition: typen.h:416
Global platform dependant definitions. This file just branches to the platform specific files in thei...
void registerAdditionalUnit(Vehicle *veh)
PG_MapDisplay(MapDisplayPG *mapDisplayWidget_)
a single field of the map
Definition: mapfield.h:26
struct MapDisplayPG::Cursor cursor
int height
the current level of height ( BITMAPPED ! )
Definition: vehicle.h:118
int getUnitMovementDuration() const
void setNumericalHeight(int nh)
Definition: typen.h:243
int getPlayerView() const
the player which is currently viewing the map.
Definition: gamemap.cpp:1007
void displayUnitMovement(GameMap *actmap, Vehicle *veh, const MapCoordinate3D &from, const MapCoordinate3D &to, int duration)
void deleteVehicle(Vehicle *vehicle)
void setTempView(bool view)
void stopAction(void)
void showAttackAnimation(tfight &battle, GameMap *actmap, int ad, int dd)
Performs the calculation of the attack and displays the result on screen.
Loki::Functor< void, LOKI_TYPELIST_1(int) > SoundStartCallback
Coordinate on the twodimensional map.
Definition: typen.h:202
bool tempsvisible
Definition: mapdisplay.cpp:64
The interface for the buildingtype class.
void removeActionCursor(void)
sigc::signal< void > updateFieldInfo
Definition: spfst.cpp:47
signed char actplayer
the player who is currently making his moves (may be human or AI)
Definition: gamemap.h:232
void displayActionCursor(int x1, int y1, int x2, int y2)
Player player[9]
Definition: gamemap.h:253
VisibilityStates fieldVisibility(const MapField *pe)
}@
Definition: spfst.cpp:440
static CGameOptions * Instance()
returns the only Instance
Definition: gameoptions.cpp:38
Interface for all the dialog boxes used by the game and the mapeditor.
Definition: attack.h:83
Coordinate on the map including height.
Definition: typen.h:238
void goTo(const MapCoordinate &position)
void startAction(void)
GameMap * actmap
Definition: spfst.cpp:64
void resetMovement(void)
MapDisplayPG * theGlobalMapDisplay
Definition: mapdisplay.cpp:607
void playPositionalSound(const MapCoordinate &pos, Sound *snd)
MapDisplayInterface & getDefaultMapDisplay()
bool centerOnField(const MapCoordinate &mc)
Definition: mapdisplay.cpp:958
MapField * getField(int x, int y)
Definition: gamemap.h:465