26 #ifdef RENDER_FROM_TEXTURE
38 static unsigned int mask = 0;
47 if (xrez >= whentodouble) {
80 #endif //tells VCC not to generate min/max macros
83 static char makingstate = 0;
87 using namespace VSFileSystem;
92 #include "../gui/eventmanager.h"
100 #define mymin( a, b ) ( ( (a) < (b) ) ? (a) : (b) )
105 if (base_max_width && base_max_height) {
110 glViewport( offsetx, offsety, xrez, yrez );
117 for (i = 0; i < links.size(); i++)
120 for (i = 0; i < objs.size(); i++)
149 if (soundsource.get() != NULL)
151 spr.ClearTimeSource();
190 float x,
y, w,
h, rot;
191 spr.GetPosition( x, y );
193 spr.GetRotation( rot );
200 if (soundsource.get() != NULL)
202 soundscene =
"video";
206 spr.SetTimeSource( soundsource );
214 return spr.getTexture()->curTime();
219 spr.getTexture()->setTime( t );
224 static float AlphaTestingCutoff =
233 if (soundsource.get() != NULL) {
234 if (!soundsource->isPlaying())
235 soundsource->startPlaying();
241 if (soundsource.get() == NULL) {
253 if (hidePointerTime < 0.0) {
254 hidePointerTime = time + 1.0;
255 }
else if (time > hidePointerTime) {
257 hidePointerTime = -1.0;
263 if (soundsource.get() == NULL) {
266 if (!getCallback().empty() && spr.Done()) {
275 return soundsource.get() != NULL
276 && soundsource->isPlaying();
295 Matrix cam( p.i, p.j, p.k, q.i, q.j, q.k, r.i, r.j, r.k, pos );
298 newmat.
p.k *= un->
rSize();
300 newmat.
p.i *= newmat.
p.k;
301 newmat.
p.j *= newmat.
p.k;
321 (un)->DrawNow(
final, FLT_MAX );
340 for (i = 0; i <
objs.size(); i++)
343 objs[i]->Draw( base );
359 static bool enable_markers =
362 static bool draw_always =
364 static float y_lower = -0.9;
365 static float base_text_background_alpha =
367 if (enable_markers) {
368 float x,
y, text_wid, text_hei;
370 static float text_offset_x =
372 static float text_offset_y =
374 static float text_color_r =
376 static float text_color_g =
378 static float text_color_b =
380 for (
size_t i = 0; i <
links.size(); i++)
382 if ( (
links[i]->alpha < 1) || (draw_always) ) {
383 if (draw_always)
links[i]->alpha = 1;
388 static string spritefile_marker =
vs_config->
getVariable(
"graphics",
"base_locationmarker_sprite",
"" );
389 if ( spritefile_marker.length() &&
links[i]->text.find(
"XXX") != 0 ) {
392 spr_marker->
GetSize( wid, hei );
394 if ( ( x+(wid/2) ) >= 1 ) x = ( 1-(wid/2) );
395 if ( ( y+(hei/2) ) >= 1 ) y = ( 1-(hei/2) );
396 if ( ( x-(wid/2) ) <= -1 ) x = ( -1+(wid/2) );
397 if ( ( y-(hei/2) ) <= y_lower ) y = ( y_lower+(hei/2) );
409 float text_pos_x = x+text_offset_x;
410 float text_pos_y = y+text_offset_y+text_hei;
411 text_wid = text_wid*
links[i]->text.length()*0.25;
412 if ( (text_pos_x+text_offset_x+text_wid) >= 1 )
413 text_pos_x = (x-fabs( text_offset_x )-text_wid);
414 if ( (text_pos_y+text_offset_y) >= 1 )
415 text_pos_y = ( y-fabs( text_offset_y ) );
416 if ( (text_pos_y+text_offset_y-text_hei) <= y_lower )
417 text_pos_y = (y+fabs( text_offset_y )+text_hei);
418 text_marker.
col =
GFXColor( text_color_r, text_color_g, text_color_b,
links[i]->alpha );
419 text_marker.
SetPos( text_pos_x, text_pos_y );
420 if (
links[i]->pythonfile !=
"#" && text_marker.
GetText().find(
"XXX" ) != 0) {
422 bool automatte = (0 == tmpbg.
a);
423 if (automatte) text_marker.
bgcol =
GFXColor( 0, 0, 0, base_text_background_alpha );
424 text_marker.
Draw( text_marker.
GetText(), 0,
true,
false, automatte );
425 text_marker.
bgcol = tmpbg;
437 if (draw_borders || debug_markers) {
438 float x,
y, text_wid, text_hei;
440 static float text_offset_x =
442 static float text_offset_y =
444 for (
size_t i = 0; i <
links.size(); i++)
454 float text_pos_x = x+text_offset_x;
455 float text_pos_y = y+text_offset_y+text_hei;
456 text_wid = text_wid*
links[i]->text.length()*0.25;
457 if ( (text_pos_x+text_offset_x+text_wid) >= 1 )
458 text_pos_x = (x-fabs( text_offset_x )-text_wid);
459 if ( (text_pos_y+text_offset_y) >= 1 )
460 text_pos_y = ( y-fabs( text_offset_y ) );
461 if ( (text_pos_y+text_offset_y-text_hei) <= y_lower )
462 text_pos_y = (y+fabs( text_offset_y )+text_hei);
464 text_pos_y += text_hei;
466 text_marker.
SetPos( text_pos_x, text_pos_y );
470 bool automatte = (0 == tmpbg.
a);
471 if (automatte) text_marker.
bgcol =
GFXColor( 0, 0, 0, base_text_background_alpha );
472 text_marker.
Draw( text_marker.
GetText(), 0,
true,
false, automatte );
473 text_marker.
bgcol = tmpbg;
480 Vector c2( c1.i, c3.j, 0 );
481 Vector c4( c3.i, c1.j, 0 );
514 if (base_max_width && base_max_height) {
515 if (base_max_width < tmpx)
517 if (base_max_height < tmpy)
520 static float base_text_background_alpha =
523 bool automatte = (0 == tmpbg.a);
525 text.bgcol =
GFXColor( 0, 0, 0, base_text_background_alpha );
526 if ( !automatte && text.GetText().empty() ) {
527 float posx, posy, wid, hei;
528 text.GetPos( posy, posx );
529 text.GetSize( wid, hei );
539 text.Draw( text.GetText(), 0,
true,
false, automatte );
548 #ifdef DEBUG_RUN_PYTHON
549 printf(
"Run python:\n%s\n", filnam );
552 if (filnam[0] ==
'#' && filnam[1] !=
'\0') {
553 ::Python::reseterrors();
554 PyRun_SimpleString( const_cast< char* > (filnam) );
555 ::Python::reseterrors();
565 if (timeleft >= maxtime) {
581 if (hastalked)
return;
586 || ( curchar >= message.size() && curtime > ( ( delay*message.size() )+2 ) ) ) {
588 std::vector< BaseObj* >::iterator ind = std::find( base->
rooms[base->
curroom]->objs.begin(),
600 if ( curchar < message.size() ) {
602 if (curtime > inbetween) {
612 for (
size_t i = 0;
i <
links.size();
i++)
614 if ( x >=
links[i]->x
637 return RefreshInterface();
677 link->
Click( base, x, y, button, state );
685 str =
"Please create a file named stdin.txt and type\nin the sprite file that you wish to use.";
688 "Please create a file named stdin.txt and type\nin the type of room followed by arguments for the room followed by text in quotations:\n1 ROOM# \"TEXT\"\n2 \"TEXT\"\n3 vector<MODES>.size vector<MODES> \"TEXT\"";
692 int ret = MessageBox( NULL, str,
"Input", MB_OKCANCEL );
694 printf(
"\n%s\n", str );
721 links.push_back(
new Goto(
"linkind",
"link" ) );
725 links.push_back(
new Launch(
"launchind",
"launch" ) );
728 links.push_back(
new Comp(
"compind",
"comp" ) );
738 MessageBox( NULL,
"warning: invalid basemaker option",
"Error", MB_OK );
740 printf(
"warning: invalid basemaker option: %d", rmtyp );
744 input[200] = input[199] =
'\0';
745 links.back()->text = string( input );
751 input[200] = input[199] =
'\0';
758 links.back()->wid = 0;
759 links.back()->hei = 0;
763 if (
links.back()->wid < 0)
766 if (
links.back()->hei < 0)
775 while ( count++ <
links.size() ) {
800 if ( lastmouseindex >= 0 && lastmouseindex < static_cast<int>(
rooms[
curroom]->
links.size()) )
802 if ( hotlink && (lastmouseindex != i) )
804 if ( link && (lastmouseindex != i) )
809 static float overcolor[4] = {1, .666666667, 0, 1};
810 static float inactivecolor[4] = {0, 1, 0, 1};
812 curtext.SetText( link->
text );
816 curtext.col =
GFXColor( overcolor[0], overcolor[1], overcolor[2], overcolor[3] );
819 curtext.col =
GFXColor( inactivecolor[0], inactivecolor[1], inactivecolor[2], inactivecolor[3] );
822 static bool draw_always =
824 static float defined_distance =
829 for (i = 0; i < static_cast<int>(
rooms[
curroom]->links.size()); i++) {
832 dist_cur2link =
sqrt( pow( (cx-x), 2 )+pow( (cy-y), 2 ) );
833 if (dist_cur2link < defined_distance)
834 rooms[
curroom]->links[i]->alpha = ( 1-(dist_cur2link/defined_distance) );
863 ProcessMouseClick( button, state, x, y );
883 ProcessMousePassive( x, y );
903 ProcessMouseActive( x, y );
915 const std::string *evtype;
917 static const std::string release_evtype(
"keyup" );
918 evtype = &release_evtype;
920 static const std::string press_evtype(
"keydown" );
921 evtype = &press_evtype;
931 if (static_cast<int>(
rooms.size()) > linknum && linknum >= 0) {
941 while (
rooms.size() <= linknum) {
944 sprintf( roomnum,
"Room #%d", linknum );
945 rooms.back()->deftext = roomnum;
963 for (
size_t i = 0;
i <
rooms.size();
i++)
973 unsigned int amods = 0;
978 unsigned int shiftedch =
1001 static bool simulate_while_at_base =
1013 vector< std::string >who;
1016 who.push_back(
"bar" );
1020 string::size_type
first = newmsg.find_first_of(
"[" );
1022 string::size_type last = newmsg.find_first_of(
"]" );
1023 if ( first != string::npos && (first+1) < newmsg.size() ) {
1024 newsound = newmsg.substr( first+1, last-first-1 );
1025 newmsg = newmsg.substr( 0, first );
1028 this->
say.push_back( newmsg );
1039 Unit *base_owner = NULL;
1043 for (; (st = *ui); ++ui)
1045 if ( ( (
Planet*) st )->hasLights() ) {
1049 double dot = v1.Dot( v2 );
1058 for (; (ownz = *ui); ++ui)
1064 }
else {
return 1; }
if (base_owner == NULL || base->
isUnit() ==
PLANETPTR)
1096 terminate_scheduled =
false;
1111 if (base && fac ==
"neutral")
1116 vector< string >vec;
1117 vec.push_back( base->
name );
1122 if ( !
rooms.size() ) {
1124 "ERROR: there are no rooms in basefile \"%s%s%s\" ...\n",
1129 rooms.back()->deftext =
"ERROR: No rooms specified...";
1131 rooms.back()->objs.push_back(
new Room::BaseShip( -1, 0, 0, 0, 0, -1, 0, 1, 0,
QVector( 0, 0, 2 ),
"default room" ) );
1132 BaseUtil::Launch( 0,
"default room", -1, -1, 1, 2,
"ERROR: No rooms specified... - Launch" );
1133 BaseUtil::Comp( 0,
"default room", 0, -1, 1, 2,
"ERROR: No rooms specified... - Computer",
1134 "Cargo Upgrade Info ShipDealer News Missions" );
1139 for (
unsigned int i = 0;
i < 16; ++
i)
1179 UpgradeCompInterface( un, baseun,
modes );
1188 terminate_scheduled =
true;
1192 if (un && cpt >= 0) {
1193 vector< string >vec;
1194 vec.push_back(
string() );
1211 bool auto_undock = auto_undock_var;
1214 if (
Network != NULL && auto_undock && playa && bas) {
1215 cerr<<
"Sending an undock notification"<<endl;
1217 if (playernum >= 0) {
1219 auto_undock =
false;
1223 if ( ( (playa->
name ==
"eject") || (playa->
name ==
"ejecting") || (playa->
name ==
"pilot")
1225 playa->
name =
"return_to_cockpit";
1227 if ( (playa && bas) && ( auto_undock || (playa->
name ==
"return_to_cockpit") ) ) {
1234 if (playa->
name ==
"return_to_cockpit")
1244 return ( (
float) ( rand() )/RAND_MAX )*(max-
min)+min;
1262 if (playa->
name ==
"return_to_cockpit") {
1263 playa->
name =
"ejecting";
1265 if (tmpvel.MagnitudeSquared() < .00001) {
1266 tmpvel =
randyVector( -( bas->rSize() ), bas->rSize() ).Cast();
1267 if (tmpvel.MagnitudeSquared() < .00001)
1268 tmpvel =
Vector( 1, 1, 1 );
1284 if ( (playa->
name ==
"return_to_cockpit") || (playa->
name ==
"ejecting") || (playa->
name ==
"eject")
1285 || (playa->
name ==
"Eject") || (playa->
name ==
"Pilot") || (playa->
name ==
"pilot") )
1309 }
else if ( say.size() ) {
1311 int sayindex = rand()%say.size();
1313 if (soundfiles[sayindex].
size() > 0) {
1333 if (eventMask&UpEvent) {
1334 static std::string evtype(
"up" );
1341 if (eventMask&ClickEvent) {
1342 static std::string evtype(
"click" );
1348 if (eventMask&DownEvent) {
1349 static std::string evtype(
"down" );
1362 if (eventMask&MoveEvent) {
1363 static std::string evtype(
"move" );
1371 if (eventMask&EnterEvent) {
1372 static std::string evtype(
"enter" );
1380 if (eventMask&LeaveEvent) {
1381 static std::string evtype(
"leave" );
1399 #ifdef RENDER_FROM_TEXTURE
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;
1446 static float base_text_background_alpha =
1449 curtext.GetCharSize( x, y );
1450 curtext.SetPos( -.99, -1+(y*1.5) );
1452 if (curtext.GetText().find(
"XXX" ) != 0) {
1454 bool automatte = (0 == tmpbg.
a);
1455 if (automatte) curtext.bgcol =
GFXColor( 0, 0, 0, base_text_background_alpha );
1456 curtext.Draw( curtext.GetText(), 0,
true,
false, automatte );
1457 curtext.bgcol = tmpbg;
1463 bool automatte = (0 == tmpbg.
a);
1473 if ( un && (!base) ) {
1475 mission->
msgcenter->
add(
"game",
"all",
"[Computer] Docking unit destroyed. Emergency launch initiated." );
1489 if (terminate_scheduled)