11 #include "cmd/unit_factory.h"
16 #include "gfx/sprite.h"
20 #include "gfx/loc_select.h"
22 #include "cmd/collection.h"
24 #include "cmd/planet.h"
25 #include "gfx/sphere.h"
26 #include "gfx/coord_select.h"
27 #include "cmd/building.h"
28 #include "cmd/ai/fire.h"
29 #include "cmd/ai/aggressive.h"
30 #include "cmd/ai/navigation.h"
33 #include "gfx/matrix.h"
34 #include "cmd/ai/flyjoystick.h"
35 #include "cmd/ai/firekeyboard.h"
36 #include "cmd/ai/script.h"
37 #include "gfx/cockpit.h"
38 #include "gfx/aux_texture.h"
39 #include "gfx/background.h"
40 #include "cmd/music.h"
42 #include "cmd/music.h"
44 #include "cmd/nebula.h"
46 #include "cmd/script/mission.h"
49 #include "cmd/ai/missionscript.h"
50 #include "cmd/enhancement.h"
51 #include "cmd/cont_terrain.h"
52 #include "cmd/script/flightgroup.h"
55 #include "networking/netclient.h"
62 #include "audio/SceneManager.h"
65 #include "gldrv/gl_globals.h"
71 #define KEYDOWN( name, key ) (name[key]&0x80)
73 static Texture *tmpcockpittexture;
94 SphereMesh *
bg2 = NULL;
99 if (newState ==
PRESS) {
103 if (gain > 1) gain = 1;
105 Music::ChangeVolume( 0 );
113 if (newState ==
PRESS) {
117 if (gain < 0) gain = 0;
119 Music::ChangeVolume( 0 );
124 static void SwitchVDUTo( VDU::VDU_MODE v )
127 static int whichvdu = 1;
128 for (
int j = 0;
j < 3; ++
j) {
139 for (i = 0; i < 32; ++i) {
144 for (i = 0; i < 32; ++i) {
157 for (; view < 2; ++view)
160 for (; examine < 2; ++examine)
163 if ( (examine == 2) && (view == 2) )
164 SwitchVDUTo( VDU::TARGET );
168 namespace CockpitKeys
171 static bool waszero =
false;
176 gcp->editingTextMessage =
true;
178 && (waszero || ch == WSK_KP_ENTER || ch == WSK_ESCAPE) ) || ( release ==
false && (ch ==
']' || ch ==
'[') ) ) {
180 gcp->editingTextMessage =
false;
183 if ( release || (ch ==
']' || ch ==
'[') )
return;
185 ( ( WSK_MOD_LSHIFT == (mod&WSK_MOD_LSHIFT) ) || ( WSK_MOD_RSHIFT == (mod&WSK_MOD_RSHIFT) ) ) ?
shiftup(
187 if ( textmessager < _Universe->numPlayers() ) {
188 if (ch == WSK_BACKSPACE || ch == WSK_DELETE) {
189 gcp->textMessage = gcp->textMessage.substr( 0, gcp->textMessage.length()-1 );
190 }
else if (ch == WSK_RETURN || ch == WSK_KP_ENTER) {
191 if (gcp->textMessage.length() != 0) {
192 std::string name = gcp->savegame->GetCallsign();
194 Unit *par = gcp->GetParent();
198 }
else if (gcp->textMessage[0] ==
'/') {
201 std::string::size_type space = gcp->textMessage.find(
' ' );
203 cmd = gcp->textMessage.substr( 1, space-1 );
204 args = gcp->textMessage.substr( space+1 );
206 cmd = gcp->textMessage.substr( 1 );
212 }
else {waszero =
true; } gcp->textMessage =
"";
213 }
else if (code != 0 && code <= 127) {
214 char newstr[2] = {(char) code, 0};
215 gcp->textMessage += newstr;
219 gcp->editingTextMessage =
false;
225 if (newState ==
PRESS) {
226 static bool chat_only_in_network =
228 if ( (
Network == NULL) && chat_only_in_network )
255 if (newState ==
PRESS) {
256 printf(
"skipping\n" );
261 static void _PitchDown(
KBSTATE newState,
int fromCam = 0,
int toCam = NUM_CAM-1 )
265 for (
int i = fromCam; i <= toCam; i++) {
266 if (newState ==
PRESS) {
280 static void _PitchUp(
KBSTATE newState,
int fromCam = 0,
int toCam = NUM_CAM-1 )
284 for (
int i = fromCam; i <= toCam; i++) {
285 if (newState ==
PRESS) {
297 static void _YawLeft(
KBSTATE newState,
int fromCam = 0,
int toCam = NUM_CAM-1 )
301 for (
int i = fromCam; i <= toCam; i++) {
302 if (newState ==
PRESS) {
314 static void _YawRight(
KBSTATE newState,
int fromCam = 0,
int toCam = NUM_CAM-1 )
316 for (
int i = fromCam; i <= toCam; i++) {
319 if (newState ==
PRESS) {
333 _PitchDown(newState);
351 static void InitPanInside()
364 if (newState ==
PRESS || newState ==
DOWN) {
372 }
else if (newState ==
RELEASE) {
382 if (newState ==
PRESS || newState ==
DOWN) {
390 }
else if (newState ==
RELEASE) {
400 if (newState ==
PRESS || newState ==
DOWN) {
408 }
else if (newState ==
RELEASE) {
418 if (newState ==
PRESS || newState ==
DOWN) {
426 }
else if (newState ==
RELEASE) {
437 if (newState ==
PRESS) {
448 static int tmp = (game_options.
cockpit ? 1 : 0);
454 string cockpit =
"disabled-cockpit.cpt";
462 cockpit = u->getCockpit();
466 if (newState ==
PRESS || newState ==
DOWN) {
472 if (newState ==
PRESS || newState ==
DOWN)
476 static float scrolltime = 0;
480 if ( newState ==
PRESS || (newState ==
DOWN && scrolltime >= .5) ) {
482 printf(
"Enabling exceptions %d\n",
allexcept );
489 if ( newState ==
PRESS || (newState ==
DOWN && scrolltime >= .5) ) {
491 printf(
"Disabling exceptions\n" );
497 if (newState ==
PRESS || newState ==
DOWN)
503 if (newState ==
PRESS || newState ==
DOWN)
509 if (newState ==
PRESS || newState ==
DOWN) {
520 if (newState ==
PRESS || newState ==
DOWN) {
526 if (newState ==
PRESS || newState ==
DOWN) {
532 if (newState ==
PRESS || newState ==
DOWN) {
543 if (newState ==
PRESS || newState ==
DOWN) {
555 if (newState ==
PRESS || newState ==
DOWN) {
566 if (newState ==
PRESS) {
567 static soundContainer sc;
569 sc.loadsound( game_options.
comm );
571 SwitchVDUTo( VDU::COMM );
576 if (newState ==
PRESS) {
577 static soundContainer sc;
579 sc.loadsound( game_options.
scanning );
581 SwitchVDUTo( VDU::SCANNING );
586 if (newState ==
PRESS) {
587 static soundContainer sc;
592 SwitchVDUTo( VDU::OBJECTIVES );
597 if (newState ==
PRESS) {
598 static soundContainer sc;
600 sc.loadsound( game_options.
examine );
603 SwitchVDUTo( VDU::TARGET );
608 if (newState ==
PRESS) {
609 static soundContainer sc;
611 sc.loadsound( game_options.
view );
618 if (newState ==
PRESS) {
619 static soundContainer sc;
621 sc.loadsound( game_options.
repair );
624 SwitchVDUTo( VDU::DAMAGE );
629 if (newState ==
PRESS) {
630 static soundContainer sc;
632 sc.loadsound( game_options.
manifest );
635 SwitchVDUTo( VDU::MANIFEST );
640 if (newState ==
PRESS) SwitchVDUTo( VDU::WEAPON );
641 FireKeyboard::WeapSelKey( s, newState );
645 if (newState ==
PRESS) SwitchVDUTo( VDU::WEAPON );
646 FireKeyboard::ReverseWeapSelKey( s, newState );
650 if (newState ==
PRESS) SwitchVDUTo( VDU::WEAPON );
651 FireKeyboard::MisSelKey( s, newState );
655 if (newState ==
PRESS) SwitchVDUTo( VDU::WEAPON );
656 FireKeyboard::ReverseMisSelKey( s, newState );
660 if (newState ==
PRESS)
665 if (newState ==
PRESS)
670 if (newState ==
PRESS)
675 if (newState ==
PRESS)
680 if (newState ==
PRESS)
685 if (newState ==
PRESS)
691 if (newState ==
PRESS || newState ==
DOWN) {
702 if (newState ==
PRESS || newState ==
DOWN) {
713 using namespace CockpitKeys;
722 if (
mission->getVariable(
"savegame",
"" ).length() == 0)
730 var =
getSaveData( 0,
"436457r1K3574r7uP71m35", 0 );
731 putSaveData( 0,
"436457r1K3574r7uP71m35", 0, var+1 );
738 std::vector< StarSystem* > &ssys,
739 std::vector< QVector > &savedloc,
740 vector< vector< std::string > > &savefiles )
742 vector< std::string >fighter0mods;
743 vector< int > fighter0indices;
745 static Vector TerrainScale( game_options.
xscale, game_options.
yscale, game_options.
zscale );
748 std::string stdstr =
mission->getVariable(
"terrain",
"" );
749 if (stdstr.length() > 0) {
750 Terrain *terr =
new Terrain( stdstr.c_str(), TerrainScale, game_options.
mass, game_options.
radius );
752 ScaleMatrix( tmp, TerrainScale );
754 mission->GetOrigin( pos, stdstr );
756 terr->SetTransformation( tmp );
758 stdstr =
mission->getVariable(
"continuousterrain",
"" );
759 if (stdstr.length() > 0) {
760 myterrain =
new ContinuousTerrain( stdstr.c_str(), TerrainScale, game_options.
mass );
764 mission->GetOrigin( pos, stdstr );
768 BindKey( 1, CoordinateSelect::MouseMoveHandle );
773 int *tmptarget =
new int[
numf];
778 vsUMap< string, int >targetmap;
780 char fightername[1024] =
"hornet.xunit";
783 vector< Flightgroup* >::const_iterator siter;
784 vector< Flightgroup* >fg =
mission->flightgroups;
786 for (siter = fg.begin(); siter != fg.end(); siter++) {
787 Flightgroup *fg = *siter;
788 string fg_name = fg->name;
789 string fullname = fg->type;
790 strcpy( fightername, fullname.c_str() );
791 string ainame = fg->ainame;
792 float fg_radius = 0.0;
794 for (
int s = 0; s < fg->nr_ships; s++) {
795 if (a >=
mission->number_of_ships) {
797 printf(
"Error: in createObjects: more ships in flightgroups than in total for mission!\n"
798 "Variables a=%d, fg-number-of-ships=%d, total nr=%d, fact=%s, fgname=%s\n",
799 a, fg->nr_ships,
mission->number_of_ships, fg->faction.c_str(), fg->name.c_str() );
803 QVector pox( 1000+150*a, 100*a, 100 );
805 pox.i = fg->pos.i+s*fg_radius*3;
806 pox.j = fg->pos.j+s*fg_radius*3;
807 pox.k = fg->pos.k+s*fg_radius*3;
808 if (pox.i == pox.j && pox.j == pox.k && pox.k == 0) {
809 pox.i = rand()*10000./RAND_MAX-5000;
810 pox.j = rand()*10000./RAND_MAX-5000;
811 pox.k = rand()*10000./RAND_MAX-5000;
815 if ( fg_terrain == -1 || (fg_terrain == -2 &&
myterrain == NULL) ) {
816 string modifications(
"" );
817 if ( s == 0 && squadnum < (
int) fighter0name.size() ) {
819 cp->activeStarSystem = ssys[squadnum];
820 fighter0indices.push_back( a );
821 if (fighter0name[squadnum].length() == 0)
822 fighter0name[squadnum] = string( fightername );
824 strcpy( fightername, fighter0name[squadnum].c_str() );
825 if (
mission->getVariable(
"savegame",
"" ).length() > 0) {
826 if (savedloc[squadnum].i != FLT_MAX)
828 vector< std::string > *dat = &cp->savegame->getMissionStringData(
"jump_from" );
830 std::string srcsys = (*dat)[0];
832 for (un_iter ui = cp->activeStarSystem->gravitationalUnits().createIterator();
833 (grav = *ui) != NULL;
835 size_t siz = grav->GetDestinations().size();
836 for (
unsigned int i = 0; i < siz; ++i)
837 if (srcsys == grav->GetDestinations()[i]) {
838 QVector newpos = grav->LocalPosition()
844 if (grav->isUnit() != PLANETPTR)
846 cp->savegame->SetPlayerLocation( newpos );
852 fighter0mods.push_back( modifications = game_options.
getCallsign( squadnum ) );
857 fprintf( stderr,
"FOUND MODIFICATION = %s FOR PLAYER #%d\n", modifications.c_str(), squadnum );
859 fighter0mods.push_back(
"" );
863 if ( squadnum < (
int) fighter0name.size() ) {
868 if (
Network != NULL && squadnum < (
int) fighter0name.size() ) {
869 if (
Network[squadnum].getCallsign() != modifications) {
870 cout<<
"Not CREATING A NETWORK PLAYER "<<fightername<<
" FOR "<<modifications<<endl;
873 cout<<
"CREATING A NETWORK PLAYER : "<<fightername<<endl;
874 fighters[a] = UnitFactory::createUnit( fightername,
false, tmptarget[a],
"", fg, s, &savefiles[squadnum][1] );
880 cout<<
"Creating fighter["<<squadnum<<
"] from "<<modifications<<
" on Network["<<squadnum<<
"] named "
881 <<
Network[squadnum].getCallsign()<<endl;
883 cout<<
"Not CREATING A LOCAL SHIP : "<<fightername<<endl;
886 cout<<
"CREATING A LOCAL SHIP : "<<fightername<<endl;
887 fighters[a] = UnitFactory::createUnit( fightername,
false, tmptarget[a], modifications, fg, s );
890 if ( s == 0 && squadnum < (
int) fighter0name.size() ) {
893 fighter0mods[squadnum].c_str(), pox );
895 if ( squadnum < (
int) fighter0name.size() ) {
900 bool isvehicle =
false;
901 if (fg_terrain == -2) {
903 UnitFactory::createBuilding(
myterrain, isvehicle, fightername,
false, tmptarget[a],
string(
"" ), fg );
906 ContinuousTerrain *t;
911 fighters[a] = UnitFactory::createBuilding( t, isvehicle, fightername,
false, tmptarget[a],
string(
915 fighters[a] = UnitFactory::createBuilding( t, isvehicle, fightername,
false, tmptarget[a],
string(
921 printf(
"pox %lf %lf %lf\n", pox.i, pox.j, pox.k );
922 fighters[a]->SetPosAndCumPos( pox );
924 if (
benchmark > 0.0 || ( s != 0 || squadnum >= (
int) fighter0name.size() ) ) {
925 fighters[a]->LoadAIScript( ainame );
938 for (
unsigned int cnum = 0; cnum < fighter0indices.size(); cnum++) {
940 fighters[fighter0indices[cnum]]->EnqueueAI(
new FlyByJoystick( cnum ) );
941 fighters[fighter0indices[cnum]]->EnqueueAI(
new FireKeyboard( cnum, cnum ) );
943 fighters[fighter0indices[cnum]]->SetTurretAI();
944 fighters[fighter0indices[cnum]]->DisableTurretAI();
947 locSel =
new CoordinateSelect( QVector( 0, 0, 5 ) );
962 un->SetPosition( QVector( 0, 0, 0 ) );
967 un->EnqueueAI(
new Orders::AggressiveAI(
"default.agg.xml" ) );
971 +QVector( rand()*10000./RAND_MAX-5000, rand()*10000./RAND_MAX-5000, rand()*10000./RAND_MAX-5000 ) );
981 Terrain::DeleteAll();
982 delete tmpcockpittexture;
1015 Music::MuzakCycle();
1026 gl_vertices_this_frame,
1027 gl_batches_this_frame);
1028 gl_vertices_this_frame = 0;
1029 gl_batches_this_frame = 0;
1034 Audio::SceneManager::getSingleton()->commit();