Advanced Strategic Command
replaymapdisplay.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * *
3  * This program is free software; you can redistribute it and/or modify *
4  * it under the terms of the GNU General Public License as published by *
5  * the Free Software Foundation; either version 2 of the License, or *
6  * (at your option) any later version. *
7  * *
8  ***************************************************************************/
9 
10 
11 #include "replaymapdisplay.h"
12 #include "spfst.h"
13 #include "viewcalculation.h"
14 #include "events.h"
15 #include "gameoptions.h"
16 #include "spfst-legacy.h"
17 
19 {
20  mapDisplay->displayPosition(x,y);
21  /*
22 
23  if ( x >= actmap->xsize )
24  x = actmap->xsize - 1;
25  if ( y >= actmap->ysize )
26  y = actmap->ysize - 1;
27 
28  int a = actmap->xpos;
29  int b = actmap->ypos;
30  int xss = idisplaymap.getscreenxsize();
31  int yss = idisplaymap.getscreenysize();
32 
33  if ((x < a) || (x >= a + xss )) {
34  if (x >= xss / 2)
35  actmap->xpos = (x - xss / 2);
36  else
37  actmap->xpos = 0;
38 
39  }
40 
41  if (y < b || y >= b + yss ) {
42  if (y >= yss / 2)
43  actmap->ypos = (y - yss / 2);
44  else
45  actmap->ypos = 0;
46  if ( actmap->ypos & 1 )
47  actmap->ypos--;
48 
49  }
50 
51  if (actmap->xpos + xss > actmap->xsize)
52  actmap->xpos = actmap->xsize - xss ;
53  if (actmap->ypos + yss > actmap->ysize)
54  actmap->ypos = actmap->ysize - yss ;
55 
56  if ((actmap->xpos != a) || (actmap->ypos != b))
57  return 1;
58  else
59  return 0;
60  */
61  return 0;
62 }
63 
64 
65 int ReplayMapDisplay :: displayMovingUnit ( const MapCoordinate3D& start, const MapCoordinate3D& dest, Vehicle* vehicle, int fieldnum, int totalmove, SoundStartCallback startSound, int duration )
66 {
67  if ( actmap->getPlayerView() < 0 )
68  return 0;
69 
70 
71  bool view1 = fieldvisiblenow ( getfield ( start.x, start.y ), actmap->getPlayerView() );
72 
73  int view2;
74  MapField* fld2 = actmap->getField ( dest );
75 
77  view2 = fieldVisibility ( fld2, actmap->getPlayerView() );
78  else {
79  // This is a workaround to estimate if the target field will be visible or not once the units is there
81  }
82 
83  /*
84  if ( vehicle->height >= chschwimmend && vehicle->height <= chhochfliegend ) {
85  visibility = fieldvisiblenow ( getfield ( start.x, start.y ), actmap->playerView) || fieldvisiblenow ( getfield ( dest.x, dest.y ), actmap->playerView);
86  } else {
87  // visibility = (fieldVisibility ( getfield ( start.x, start.y ), actmap->playerView) >= visible_all) && (fieldVisibility ( getfield ( dest.x, dest.y ), actmap->playerView) >= visible_now);
88  visibility = fieldvisiblenow ( getfield ( start.x, start.y ), actmap->playerView) || fieldvisiblenow ( getfield ( dest.x, dest.y ), actmap->playerView);
89  }
90  */
91 
92  if ( view1 || (view2 >= visible_now ) ) {
93  if ( checkMapPosition ( start.x, start.y ))
94  displayMap();
95 
96  int fc = mapDisplay->displayMovingUnit ( start, dest, vehicle, fieldnum, totalmove, startSound, duration );
97  if ( fc == 1 ) {
98  mapDisplay->resetMovement();
99  mapDisplay->displayMap();
100  }
101 
102  return fc;
103  } else
104  return 0;
105 }
106 
108 {
109  if ( fieldvisiblenow ( getfield ( x, y ), actmap->getPlayerView() )) {
110  checkMapPosition ( x, y );
111  mapDisplay->displayPosition ( x, y );
112  }
113 }
114 
116 {
117  mapDisplay->removeActionCursor();
118 
119 }
120 
121 void ReplayMapDisplay :: displayActionCursor ( int x1, int y1, int x2, int y2, int secondWait )
122 {
123  if ( x1 >= 0 && y1 >= 0 ) {
124  int i = fieldvisiblenow ( getfield ( x1, y1 ), actmap->getPlayerView() );
125  if( i ) {
126  cursor_goto( MapCoordinate( x1, y1 ));
127 
128  if ( x2 >= 0 && y2 >= 0 )
129  wait( 30 );
130  else
131  wait();
132  }
133  }
134 
135  if ( x2 >= 0 && y2 >= 0 ) {
136  int i = fieldvisiblenow ( getfield ( x2, y2 ), actmap->getPlayerView() );
137  if( i ) {
138  cursor_goto( MapCoordinate( x2, y2 ));
139  if ( secondWait )
140  wait();
141  }
142  }
143 }
144 
145 void ReplayMapDisplay :: wait ( int minTime )
146 {
147  int t = ticker;
148  while ( ticker < t + max ( cursorDelay, minTime ) )
150 }
151 
153 {
154  if ( fieldvisiblenow ( actmap->getField ( pos ), actmap->getPlayerView() )) {
155  mapDisplay->playPositionalSound( pos, snd );
156  }
157 }
158 
159 
161 {
162  int speed = CGameOptions::Instance()->movespeed;
163  int factor = max( 10, CGameOptions::Instance()->replayMoveSpeedFactor );
164  return speed * 100 / factor;
165 }
166 
int movespeed
1/100 sec for a unit to move from one field to the next
Definition: gameoptions.h:63
void playPositionalSound(const MapCoordinate &pos, Sound *snd)
VisibilityStates calcvisibilityfield(GameMap *gamemap, MapField *fld, int player, int add, int initial, int additionalEnemyJamming)
calculates the view on a given field.
map accessing and usage routines used by ASC and the mapeditor
Definition: sound.h:20
void cursor_goto(const MapCoordinate &pos)
virtual void displayPosition(int x, int y)=0
DiplomaticStateVector diplomacy
Definition: player.h:209
int getOwner() const
returns the number of the player this vehicle/building belongs to
int getUnitMovementDuration() const
int checkMapPosition(int x, int y)
bool sharesView(PlayerID receivingPlayer) const
Definition: player.h:81
a single field of the map
Definition: mapfield.h:26
int getPlayerView() const
the player which is currently viewing the map.
Definition: gamemap.cpp:1007
MapField * getfield(int x, int y)
returns the field at the given coordinates
Definition: spfst.cpp:199
virtual void playPositionalSound(const MapCoordinate &pos, Sound *snd)=0
virtual void resetMovement(void)=0
bool fieldvisiblenow(const MapField *pe, Vehicle *veh, int player)
{@
Definition: spfst.cpp:399
Loki::Functor< void, LOKI_TYPELIST_1(int) > SoundStartCallback
virtual int displayMovingUnit(const MapCoordinate3D &start, const MapCoordinate3D &dest, Vehicle *vehicle, int fieldnum, int totalmove, SoundStartCallback startSound, int duration)=0
Coordinate on the twodimensional map.
Definition: typen.h:202
int jamming
the radar jamming power
void displayActionCursor(int x1, int y1, int x2, int y2, int secondWait)
virtual void displayMap(void)=0
void removeActionCursor(void)
int releasetimeslice(void)
Definition: events.cpp:209
int displayMovingUnit(const MapCoordinate3D &start, const MapCoordinate3D &dest, Vehicle *vehicle, int fieldnum, int totalmove, SoundStartCallback startSound, int duration)
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
void displayMap(void)
int getgameparameter(GameParameter num) const
Definition: gamemap.cpp:1047
const VehicleType * typ
Definition: vehicle.h:83
virtual void removeActionCursor(void)=0
Coordinate on the map including height.
Definition: typen.h:238
GameMap * actmap
Definition: spfst.cpp:64
const T & max(const T &a, const T &b, const T &c)
Definition: misc.h:97
void displayPosition(int x, int y)
volatile int ticker
Definition: events.cpp:234
MapField * getField(int x, int y)
Definition: gamemap.h:465