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
ShipCommands Class Reference

Public Member Functions

virtual ~ShipCommands ()
 
 ShipCommands ()
 
void pymenu ()
 
void left (bool *isKeyDown)
 
void right (bool *isKeyDown)
 
void up (bool *isKeyDown)
 
void down (bool *isKeyDown)
 
void roll (bool *isKeyDown)
 
void setkps (const char *in)
 

Detailed Description

Definition at line 17 of file ship_commands.cpp.

Constructor & Destructor Documentation

virtual ShipCommands::~ShipCommands ( )
inlinevirtual

Definition at line 34 of file ship_commands.cpp.

References CommandInterpretor, and commandI::remCommand().

35  {
36  CommandInterpretor->remCommand( cpymenu );
37  CommandInterpretor->remCommand( csetkps );
38  }
ShipCommands::ShipCommands ( )
inline

Definition at line 39 of file ship_commands.cpp.

References commandI::addCommand(), commandI::addMenu(), commandI::addMenuItem(), mItem::autoreprint, CommandInterpretor, mItem::display, mItem::func2call, mItem::inputbit, mItem::inputbit2, mItem::Name, pymenu(), mItem::selectstring, and setkps().

40  {
41  //create some functors, register them with the command interp {{{
42  cpymenu = new Functor< ShipCommands > ( this, &ShipCommands::pymenu );
43  CommandInterpretor->addCommand( cpymenu, "pymenu" );
44  csetkps = new Functor< ShipCommands > ( this, &ShipCommands::setkps );
45  CommandInterpretor->addCommand( csetkps, "setspeed" );
46  //}}}
47  //set some local bools false {{{
48  broll = false;
49  bleft = false;
50  bright = false;
51  bup = false;
52  bdown = false;
53  //}}}
54  //a test menu {{{
55  {
56  static char const python_test[20] = "python test";
57  static char const test_string[40] = "This is a test of the menusystem";
58  menu *m = new menu( python_test, test_string, "\r\n" );
60  {
61  mItem *mi = new mItem;
62  mi->autoreprint = true;
63  mi->Name.append( "1" ); //argument to access menu
64  mi->display.append( "Python One Line input" ); //menu's display name
65  mi->func2call.append( "python" );
66  mi->inputbit = true; //set single-line input mode
67  mi->selectstring.append( "Type a single line of Python" ); //call function "Display" with this string
69  }
70  {
71  mItem *mi = new mItem;
72  mi->autoreprint = true; //auto-re-print the
73  //menu after this menuitem is finished
74  mi->Name.append( "2" ); //argument to access menu
75  mi->display.append( "(Python Multi-Line input)" ); //menu's display name
76  mi->func2call.append( "python" ); //call this function when this menuitem is called and input is all recieved, user input is appened with a space, along with the action string if there is one. (string generated: "func2call action userinput")
77  mi->inputbit2 = true; //set single-line input mode
78  mi->selectstring.append( "Type multiple lines of python input. Use <ENTER> on a line ALONE to finish" ); //Call function "Display" with this string
80  }
81  }
82  }

Member Function Documentation

void ShipCommands::down ( bool isKeyDown)

Definition at line 110 of file ship_commands.cpp.

111 {
112  bdown = isKeyDown;
113 }
void ShipCommands::left ( bool isKeyDown)

Definition at line 98 of file ship_commands.cpp.

99 {
100  bleft = isKeyDown;
101 }
void ShipCommands::pymenu ( )

Definition at line 93 of file ship_commands.cpp.

References CommandInterpretor, RText::conoutf(), and commandI::setMenu().

Referenced by ShipCommands().

94 {
95  std::string response( CommandInterpretor->setMenu( "python test" ) );
96  CommandInterpretor->conoutf( response );
97 }
void ShipCommands::right ( bool isKeyDown)

Definition at line 102 of file ship_commands.cpp.

103 {
104  bright = isKeyDown;
105 }
void ShipCommands::roll ( bool isKeyDown)

Definition at line 114 of file ship_commands.cpp.

115 {
116  broll = isKeyDown;
117 }
void ShipCommands::setkps ( const char *  in)

Definition at line 121 of file ship_commands.cpp.

References fmin(), Unit::GetComputerData(), UniverseUtil::getPlayer(), VegaConfig::getVariable(), Unit::Computer::max_speed(), XMLSupport::parse_bool(), XMLSupport::parse_float(), Unit::Computer::set_speed, and vs_config.

Referenced by ShipCommands().

122 {
123  if (in == NULL) throw "What speed?";
124  float kps = XMLSupport::parse_float( std::string( in ) );
125  Unit *player = UniverseUtil::getPlayer();
126  if (player) {
127  static float game_speed = XMLSupport::parse_float( vs_config->getVariable( "physics", "game_speed", "1" ) );
128  static bool display_in_meters = XMLSupport::parse_bool( vs_config->getVariable( "physics", "display_in_meters", "true" ) );
129  static bool lie = XMLSupport::parse_bool( vs_config->getVariable( "physics", "game_speed_lying", "true" ) );
130  if (lie)
131  kps *= game_speed;
132 
133  else
134  kps /= display_in_meters ? 1.0f : 3.6f;
135  player->GetComputerData().set_speed = fmin( player->GetComputerData().max_speed(), kps );
136  }
137 }
void ShipCommands::up ( bool isKeyDown)

Definition at line 106 of file ship_commands.cpp.

107 {
108  bup = isKeyDown;
109 }

The documentation for this class was generated from the following file: