Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
•All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
base_interface.cpp File Reference
#include "config.h"
#include <Python.h>
#include "base.h"
#include "gldrv/winsys.h"
#include "vsfilesystem.h"
#include "lin_time.h"
#include "audiolib.h"
#include "gfx/camera.h"
#include "gfx/cockpit_generic.h"
#include "python/init.h"
#include "python/python_compile.h"
#include "planet_generic.h"
#include <algorithm>
#include "base_util.h"
#include "config_xml.h"
#include "save_util.h"
#include "unit_util.h"
#include "networking/netclient.h"
#include "gfx/cockpit.h"
#include "gfx/ani_texture.h"
#include "music.h"
#include "load_mission.h"
#include "universe_util.h"
#include "gui/guidefs.h"
#include "main_loop.h"
#include "in_mouse.h"
#include "in_kb.h"
#include "audio/SceneManager.h"
#include "basecomputer.h"
#include "../gui/eventmanager.h"
#include "ai/communication.h"

Go to the source code of this file.

Classes

struct  BaseColor
 

Macros

#define NEW_GUI
 
#define mymin(a, b)   ( ( (a) < (b) ) ? (a) : (b) )
 

Functions

static unsigned intgetMouseButtonMask ()
 
static void biModifyMouseSensitivity (int &x, int &y, bool invert)
 
void ModifyMouseSensitivity (int &x, int &y)
 
static void CalculateRealXAndY (int xbeforecalc, int ybeforecalc, float *x, float *y)
 
static void SetupViewport ()
 
static FILTER BlurBases ()
 
void RunPython (const char *filnam)
 
bool RefreshGUI (void)
 
void base_main_loop ()
 
int shiftup (int)
 
static void base_keyboard_cb (unsigned int ch, unsigned int mod, bool release, int x, int y)
 
double compute_light_dot (Unit *base, Unit *un)
 
const char * compute_time_of_day (Unit *base, Unit *un)
 
void ExecuteDirector ()
 
void InitCallbacks (void)
 
void TerminateCurrentBase (void)
 
void CurrentBaseUnitSet (Unit *un)
 
void abletodock (int dock)
 
float aynrand (float min, float max)
 
QVector randyVector (float min, float max)
 
static void AnimationDraw ()
 

Variables

static bool createdbase = false
 
static int createdmusic = -1
 
const char * mission_key
 
std::vector< unsigned intbase_keyboard_queue
 
static std::vector
< BaseInterface::Room::BaseTalk * > 
active_talks
 

Macro Definition Documentation

#define mymin (   a,
  b 
)    ( ( (a) < (b) ) ? (a) : (b) )
#define NEW_GUI

Definition at line 88 of file base_interface.cpp.

Function Documentation

void abletodock ( int  dock)

Definition at line 1247 of file firekeyboard.cpp.

1248 {
1249  static bool play_anim = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "docking_comm_anim", "false" ) );
1250  switch (dock)
1251  {
1252  case 5:
1253  {
1254  static soundContainer reqsound;
1255  if (reqsound.sound == -2) {
1256  static string str = vs_config->getVariable( "cockpitaudio", "undocking_complete", "undocking_complete" );
1257  reqsound.loadsound( str );
1258  }
1259  reqsound.playsound();
1260  break;
1261  }
1262  case 4:
1263  {
1264  static soundContainer reqsound;
1265  if (reqsound.sound == -2) {
1266  static string str = vs_config->getVariable( "cockpitaudio", "undocking_failed", "undocking_failed" );
1267  reqsound.loadsound( str );
1268  }
1269  reqsound.playsound();
1270  break;
1271  }
1272  case 3:
1273  {
1274  static soundContainer reqsound;
1275  static string otherstr = vs_config->getVariable( "audio", "automatic_docking_zone", "automatic_landing_zone.wav" );
1276  if (otherstr != "" && rand() < RAND_MAX/2) {
1277  static int s = AUDCreateSoundWAV( otherstr, false );
1278  AUDPlay( s, QVector( 0, 0, 0 ), Vector( 0, 0, 0 ), 1 );
1279  } else {
1280  if (reqsound.sound == -2) {
1281  static string str = vs_config->getVariable( "cockpitaudio", "docking_complete", "docking_complete" );
1282  reqsound.loadsound( str );
1283  }
1284  reqsound.playsound();
1285  }
1286  break;
1287  }
1288  case 2:
1289  {
1290  static soundContainer reqsound;
1291  if (reqsound.sound == -2) {
1292  static string str = vs_config->getVariable( "cockpitaudio", "docking_failed", "docking_failed" );
1293  reqsound.loadsound( str );
1294  }
1295  reqsound.playsound();
1296  break;
1297  }
1298  case 1:
1299  {
1300  static soundContainer reqsound;
1301  if (reqsound.sound == -2) {
1302  static string str = vs_config->getVariable( "cockpitaudio", "docking_granted", "request_granted" );
1303  reqsound.loadsound( str );
1304  }
1305  reqsound.playsound();
1306  break;
1307  }
1308  case 0:
1309  {
1310  static soundContainer reqsound;
1311  if (reqsound.sound == -2) {
1312  static string str = vs_config->getVariable( "cockpitaudio", "docking_denied", "request_denied" );
1313  reqsound.loadsound( str );
1314  }
1315  reqsound.playsound();
1316  break;
1317  }
1318  }
1319 }
static void AnimationDraw ( )
static

Definition at line 1397 of file base_interface.cpp.

References CULLFACE, GFXBegin(), GFXDisable(), GFXEnable(), GFXEnd(), GFXQUAD, GFXREPLACETEXTURE, GFXTexCoord2f(), GFXTextureEnv(), GFXVertex3f(), i, j, StreamTexture::MakeActive(), StreamTexture::Map(), NEAREST, TEXTURE0, TEXTURE1, and StreamTexture::UnMap().

Referenced by BaseInterface::Draw().

1398 {
1399 #ifdef RENDER_FROM_TEXTURE
1400  static StreamTexture T( 512, 256, NEAREST, NULL );
1401  BaseColor( *data )[512] = reinterpret_cast< BaseColor(*)[512] > ( T.Map() );
1402  bool counter = false;
1403  srand( time( NULL ) );
1404  for (int i = 0; i < 256; ++i)
1405  for (int j = 0; j < 512; ++j) {
1406  data[i][j].r = rand()&0xff;
1407  data[i][j].g = rand()&0xff;
1408  data[i][j].b = rand()&0xff;
1409  data[i][j].a = rand()&0xff;
1410  }
1411  T.UnMap();
1412  T.MakeActive();
1414  GFXEnable( TEXTURE0 );
1415  GFXDisable( TEXTURE1 );
1416  GFXDisable( CULLFACE );
1417  GFXBegin( GFXQUAD );
1418  GFXTexCoord2f( 0, 0 );
1419  GFXVertex3f( -1.0, -1.0, 0.0 );
1420  GFXTexCoord2f( 1, 0 );
1421  GFXVertex3f( 1.0, -1.0, 0.0 );
1422  GFXTexCoord2f( 1, 1 );
1423  GFXVertex3f( 1.0, 1.0, 0.0 );
1424  GFXTexCoord2f( 0, 1 );
1425  GFXVertex3f( -1.0, 1.0, 0.0 );
1426  GFXEnd();
1427 #endif
1428 }
float aynrand ( float  min,
float  max 
)
inline

Definition at line 1242 of file base_interface.cpp.

References min().

Referenced by randyVector().

1243 {
1244  return ( (float) ( rand() )/RAND_MAX )*(max-min)+min;
1245 }
static void base_keyboard_cb ( unsigned int  ch,
unsigned int  mod,
bool  release,
int  x,
int  y 
)
static

Definition at line 970 of file base_interface.cpp.

References base_keyboard_queue, BaseInterface::CallComp, BaseInterface::CurrentBase, KB_MOD_ALT, KB_MOD_CTRL, KB_MOD_SHIFT, BaseInterface::Key(), BaseInterface::ProcessKeyboardBuffer(), setActiveModifiers(), shiftup(), WSK_MOD_LALT, WSK_MOD_LCTRL, WSK_MOD_LSHIFT, WSK_MOD_RALT, WSK_MOD_RCTRL, and WSK_MOD_RSHIFT.

Referenced by BaseInterface::InitCallbacks().

971 {
972  //Set modifiers
973  unsigned int amods = 0;
974  amods |= ( mod&(WSK_MOD_LSHIFT|WSK_MOD_RSHIFT) ) ? KB_MOD_SHIFT : 0;
975  amods |= ( mod&(WSK_MOD_LCTRL|WSK_MOD_RCTRL) ) ? KB_MOD_CTRL : 0;
976  amods |= ( mod&(WSK_MOD_LALT|WSK_MOD_RALT) ) ? KB_MOD_ALT : 0;
977  setActiveModifiers( amods );
978  unsigned int shiftedch =
979  ( ( WSK_MOD_LSHIFT == (mod&WSK_MOD_LSHIFT) ) || ( WSK_MOD_RSHIFT == (mod&WSK_MOD_RSHIFT) ) ) ? shiftup( ch ) : ch;
981  //Flush buffer
982  if ( base_keyboard_queue.size() )
984  //Send directly to base interface handlers
985  BaseInterface::CurrentBase->Key( shiftedch, amods, release, x, y );
986  } else
987  //Queue keystroke
988  if (!release) {
989  base_keyboard_queue.push_back( shiftedch );
990  }
991 }
void base_main_loop ( )

Definition at line 649 of file base_interface.cpp.

References _Universe, AUDStopAllSounds(), createdbase, createdmusic, BaseComputer::dirty, GFXBeginScene(), GFXEndScene(), micro_sleep, Music::MuzakCycle(), Network, Universe::numPlayers(), RefreshGUI(), restore_main_loop(), and UpdateTime().

Referenced by BaseInterface::InitCallbacks().

650 {
651  UpdateTime();
653  if (Network != NULL)
654  for (size_t jj = 0; jj < _Universe->numPlayers(); jj++)
655  Network[jj].checkMsg( NULL );
656  GFXBeginScene();
657  if (createdbase) {
658  createdbase = false;
660  }
661  if ( !RefreshGUI() ) {
663  } else {
664  GFXEndScene();
665  micro_sleep( 1000 );
666  }
667  BaseComputer::dirty = false;
668 }
static void biModifyMouseSensitivity ( int x,
int y,
bool  invert 
)
static

Definition at line 42 of file base_interface.cpp.

References g_game, VegaConfig::getVariable(), int, XMLSupport::parse_float(), XMLSupport::parse_int(), vs_config, game_data_t::x_resolution, and game_data_t::y_resolution.

Referenced by BaseInterface::Room::Click(), and ModifyMouseSensitivity().

43 {
44  int xrez = g_game.x_resolution;
45  static int whentodouble = XMLSupport::parse_int( vs_config->getVariable( "joystick", "double_mouse_position", "1280" ) );
46  static float factor = XMLSupport::parse_float( vs_config->getVariable( "joystick", "double_mouse_factor", "2" ) );
47  if (xrez >= whentodouble) {
48  x -= g_game.x_resolution/2;
49  y -= g_game.y_resolution/2;
50  if (invert) {
51  x = int(x/factor);
52  y = int(y/factor);
53  } else {
54  x = int(x*factor);
55  y = int(y*factor);
56  }
57  x += g_game.x_resolution/2;
58  y += g_game.y_resolution/2;
59  if (x > g_game.x_resolution)
61  if (y > g_game.y_resolution)
63  if (x < 0) x = 0;
64  if (y < 0) y = 0;
65  }
66 }
static FILTER BlurBases ( )
static

Definition at line 135 of file base_interface.cpp.

References BILINEAR, VegaConfig::getVariable(), NEAREST, XMLSupport::parse_bool(), and vs_config.

Referenced by BaseInterface::Room::BaseVSSprite::SetSprite().

136 {
137  static bool blur_bases = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "blur_bases", "true" ) );
138  return blur_bases ? BILINEAR : NEAREST;
139 }
static void CalculateRealXAndY ( int  xbeforecalc,
int  ybeforecalc,
float x,
float y 
)
static

Definition at line 95 of file base_interface.cpp.

References float, g_game, game_data_t::x_resolution, and game_data_t::y_resolution.

Referenced by BaseInterface::Click(), and BaseInterface::MouseOver().

96 {
97  (*x) = ( ( (float) (xbeforecalc*2) )/g_game.x_resolution )-1;
98  (*y) = -( ( (float) (ybeforecalc*2) )/g_game.y_resolution )+1;
99 }
double compute_light_dot ( Unit base,
Unit un 
)

Definition at line 1034 of file base_interface.cpp.

References _Universe, UnitCollection::createIterator(), Unit::getStarSystem(), StarSystem::getUnitList(), Unit::isPlanet(), Unit::isUnit(), PLANETPTR, Universe::popActiveStarSystem(), Unit::Position(), Universe::pushActiveStarSystem(), QVector, and VSFileSystem::vs_fprintf().

Referenced by compute_time_of_day().

1035 {
1036  StarSystem *ss = base->getStarSystem();
1037  double ret = -1;
1038  Unit *st;
1039  Unit *base_owner = NULL;
1040  if (ss) {
1042  un_iter ui = ss->getUnitList().createIterator();
1043  for (; (st = *ui); ++ui)
1044  if ( st->isPlanet() ) {
1045  if ( ( (Planet*) st )->hasLights() ) {
1046  QVector v1 = ( un->Position()-base->Position() ).Normalize();
1047  QVector v2 = ( st->Position()-base->Position() ).Normalize();
1048 #ifdef VS_DEBUG
1049  double dot = v1.Dot( v2 );
1050  if (dot > ret) {
1051  VSFileSystem::vs_fprintf( stderr, "dot %lf", dot );
1052  ret = dot;
1053  }
1054 #endif
1055  } else {
1056  un_iter ui = ( (Planet*) st )->satellites.createIterator();
1057  Unit *ownz = NULL;
1058  for (; (ownz = *ui); ++ui)
1059  if (ownz == base)
1060  base_owner = st;
1061  }
1062  }
1064  } else {return 1; } if (base_owner == NULL || base->isUnit() == PLANETPTR)
1065  return ret;
1066  else
1067  return compute_light_dot( base_owner, un );
1068 }
const char* compute_time_of_day ( Unit base,
Unit un 
)

Definition at line 1070 of file base_interface.cpp.

References compute_light_dot().

Referenced by BaseInterface::BaseInterface().

1071 {
1072  if (!base || !un)
1073  return "day";
1074  float rez = compute_light_dot( base, un );
1075  if (rez > .2)
1076  return "day";
1077  if (rez < -.1)
1078  return "night";
1079  return "sunset";
1080 }
void CurrentBaseUnitSet ( Unit un)

Definition at line 1159 of file base_interface.cpp.

References BaseInterface::caller, BaseInterface::CurrentBase, and UnitContainer::SetUnit().

Referenced by buyShip().

1160 {
1163 }
void ExecuteDirector ( )

Definition at line 617 of file star_system_generic.cpp.

Referenced by BaseInterface::BaseInterface(), Unit::ForceDock(), NetServer::start(), and StarSystem::Update().

618 {
619  unsigned int curcockpit = _Universe->CurrentCockpit();
620  {
621  for (unsigned int i = 0; i < active_missions.size(); ++i)
622  if (active_missions[i]) {
623  _Universe->SetActiveCockpit( active_missions[i]->player_num );
625  if (ss) _Universe->pushActiveStarSystem( ss );
627  active_missions[i]->DirectorLoop();
628  if (ss) _Universe->popActiveStarSystem();
629  }
630  }
631  _Universe->SetActiveCockpit( curcockpit );
634  {
635  for (unsigned int i = 1; i < active_missions.size();) {
636  if (active_missions[i]) {
637  if (active_missions[i]->runtime.pymissions) {
638  ++i;
639  } else {
640  unsigned int w = active_missions.size();
641  active_missions[i]->terminateMission();
642  if ( w == active_missions.size() ) {
643  printf( "MISSION NOT ERASED\n" );
644  break;
645  }
646  }
647  } else {
648  active_missions.Get()->erase( active_missions.Get()->begin()+i );
649  }
650  }
651  }
652 }
static unsigned int& getMouseButtonMask ( )
static

Definition at line 36 of file base_interface.cpp.

Referenced by BaseInterface::Room::Link::Click(), BaseInterface::ClickWin(), and BaseInterface::MouseOver().

37 {
38  static unsigned int mask = 0;
39  return mask;
40 }
void InitCallbacks ( void  )
QVector randyVector ( float  min,
float  max 
)
inline

Definition at line 1247 of file base_interface.cpp.

References aynrand(), and QVector.

Referenced by BaseInterface::Room::Eject::Click().

1248 {
1249  return QVector( aynrand( min, max ),
1250  aynrand( min, max ),
1251  aynrand( min, max ) );
1252 }
bool RefreshGUI ( void  )

Definition at line 625 of file base_interface.cpp.

References _Universe, Universe::AccessCockpit(), BaseInterface::CallComp, BaseInterface::caller, BaseInterface::CurrentBase, WindowManager::draw(), BaseInterface::Draw(), Cockpit::GetParent(), UnitContainer::GetUnit(), and globalWindowManager().

Referenced by base_main_loop(), and GameUniverse::StartDraw().

626 {
627  bool retval = false;
628  if ( _Universe->AccessCockpit() ) {
631  if (BaseInterface::CurrentBase->CallComp) {
632 #ifdef NEW_GUI
634  return true;
635 
636 #else
637  return RefreshInterface();
638 #endif
639  } else {
641  }
642  retval = true;
643  }
644  }
645  }
646  return retval;
647 }
void RunPython ( const char *  filnam)

Definition at line 546 of file base_interface.cpp.

References CompileRunPython().

Referenced by BaseInterface::Room::Link::Click(), BaseInterface::Room::BasePython::Draw(), BaseInterface::Room::BaseVSMovie::Draw(), BaseInterface::Key(), BaseInterface::Room::Link::MouseEnter(), BaseInterface::Room::Link::MouseLeave(), BaseInterface::Room::Link::MouseMove(), and BaseUtil::VideoAudioStreamListener::onEndOfStream().

547 {
548 #ifdef DEBUG_RUN_PYTHON
549  printf( "Run python:\n%s\n", filnam );
550 #endif
551  if (filnam[0]) {
552  if (filnam[0] == '#' && filnam[1] != '\0') {
553  ::Python::reseterrors();
554  PyRun_SimpleString( const_cast< char* > (filnam) );
555  ::Python::reseterrors();
556  } else {
557  CompileRunPython( filnam );
558  }
559  }
560 }
static void SetupViewport ( )
static

Definition at line 101 of file base_interface.cpp.

References g_game, VegaConfig::getVariable(), mymin, XMLSupport::parse_int(), vs_config, game_data_t::x_resolution, and game_data_t::y_resolution.

Referenced by BaseInterface::Room::BaseShip::Draw(), and BaseInterface::Draw().

102 {
103  static int base_max_width = XMLSupport::parse_int( vs_config->getVariable( "graphics", "base_max_width", "0" ) );
104  static int base_max_height = XMLSupport::parse_int( vs_config->getVariable( "graphics", "base_max_height", "0" ) );
105  if (base_max_width && base_max_height) {
106  int xrez = mymin( g_game.x_resolution, base_max_width );
107  int yrez = mymin( g_game.y_resolution, base_max_height );
108  int offsetx = (g_game.x_resolution-xrez)/2;
109  int offsety = (g_game.y_resolution-yrez)/2;
110  glViewport( offsetx, offsety, xrez, yrez );
111  }
112 }
int shiftup ( int  )

Definition at line 72 of file in_kb.cpp.

Referenced by base_keyboard_cb(), gamemenu_keyboard_handler(), glut_keyboard_cb(), nav_keyboard_cb(), and CockpitKeys::TextMessageCallback().

73 {
74  if ( ch == (ch&0xFF) ) {
75  const char *c = strchr( _lomap, ch );
76  if (c)
77  return _himap[c-_lomap];
78 
79  else
80  return toupper( ch );
81  } else {return ch; }}

Variable Documentation

std::vector< BaseInterface::Room::BaseTalk* > active_talks
static
std::vector< unsigned int > base_keyboard_queue
bool createdbase = false
static

Definition at line 68 of file base_interface.cpp.

Referenced by base_main_loop(), and BaseInterface::BaseInterface().

int createdmusic = -1
static

Definition at line 69 of file base_interface.cpp.

Referenced by base_main_loop(), and BaseInterface::BaseInterface().

const char* mission_key