byte LunaticWorld(byte world, const char *worldName) { byte result; InitPlayer(INIT_WORLD, world, 0); if (!LoadWorld(&curWorld, worldName)) return WORLD_ABORT; worldNum = world; InitWorld(&curWorld, worldNum); mapNum = 0; while (1) { result = PlayALevel(mapNum); if (result == LEVEL_ABORT) { PlayerResetScore(); if (mapToGoTo < 255) mapNum = mapToGoTo; else break; } else if (result == LEVEL_RESET) { PlayerResetScore(); // don't do anything, play the same level } else if (result == LEVEL_WIN) { PlayerWinLevel(world, mapNum, curMapFlags & MAP_SECRET); mapNum = mapToGoTo; } else if (result == LEVEL_LOADING) { FreeWorld(&curWorld); PlayerResetScore(); return WORLD_LOAD; } else if (result == WORLD_QUITGAME) { FreeWorld(&curWorld); PlayerResetScore(); return WORLD_QUITGAME; } } FreeWorld(&curWorld); return WORLD_ABORT; }
void ac_ChooseWorld() { num_files = 0; memset(world_info, 0, sizeof(world_info)); scan_for_wwd("./world"); #ifdef __linux__ extern char homepath[256]; scan_for_wwd(homepath); #endif // Now choose the world SDL_Event event; MENU *m = &WorldMenu; m->num = num_files; m->sel = 0; done = 0; while(!done) { while(SDL_PollEvent(&event)) if(event.type == SDL_KEYDOWN) { if(event.key.keysym.sym == SDLK_LEFT) { if(m->sel > 0) { m->sel--; PlaySound(0); } } else if(event.key.keysym.sym == SDLK_RIGHT) { if(m->sel < m->num - 1) { m->sel++; PlaySound(0); } } else if(event.key.keysym.sym == SDLK_RETURN || event.key.keysym.sym == SDLK_LCTRL) { // reload new brave world FreeWorld(wwd); wwd = LoadWorld(world_info[m->sel].fullname); PlaySound(1); done = 1; } else if(event.key.keysym.sym == SDLK_ESCAPE) { done = 1; } } RedrawMenu(m); MPrint(world_info[m->sel].title, 130, 254, 252); MPrint(world_info[m->sel].author, 140, 254, 252); MPrint(world_info[m->sel].areas, 150, 254, 252); MPrint("PRESS LEFT/RIGHT TO SELECT", 170, 255, 252); MPrint("<START> TO CONFIRM", 180, 255, 252); BlitAndWait(1); } done = 0; }
void main (void) { worldADT world; int i; double time=InitialTimeInterval; int numcreature; speciesADT *speciesP; creatureADT *creatureP; while(TRUE) { Randomize(); InitGraphics(); InitWorldMap(NColumns,NRows); i=0; numcreature=0; world=NewWorld(NColumns,NRows); PrintInstructions1(); speciesP=SetSpecies(&numcreature); speciesP=Shuffle(speciesP,numcreature); creatureP=GetBlock( numcreature * sizeof (creatureADT) ); PlacingCreatures(world,creatureP,speciesP,numcreature); PrintInstructions2(); while ( !MouseButtonIsDown() || WantToContinue(creatureP,numcreature,&time) ) { TakeOneTurn(creatureP[i]); i=(i+1)%numcreature; Pause(time); } FreeWorld(world); FreeBlock(creatureP); if (!WantToPlayAgain()) {break;} } }
/* ================= idRenderWorldLocal::InitFromMap A NULL or empty name will make a world without a map model, which is still useful for displaying a bare model ================= */ bool idRenderWorldLocal::InitFromMap( const char* name ) { idLexer* src; idToken token; idRenderModel* lastModel; // if this is an empty world, initialize manually if( !name || !name[0] ) { FreeWorld(); mapName.Clear(); ClearWorld(); return true; } // load it idStrStatic< MAX_OSPATH > filename = name; filename.SetFileExtension( PROC_FILE_EXT ); // check for generated file idStrStatic< MAX_OSPATH > generatedFileName = filename; generatedFileName.Insert( "generated/", 0 ); generatedFileName.SetFileExtension( "bproc" ); // if we are reloading the same map, check the timestamp // and try to skip all the work ID_TIME_T currentTimeStamp = fileSystem->GetTimestamp( filename ); if( name == mapName ) { if( fileSystem->InProductionMode() || ( currentTimeStamp != FILE_NOT_FOUND_TIMESTAMP && currentTimeStamp == mapTimeStamp ) ) { common->Printf( "idRenderWorldLocal::InitFromMap: retaining existing map\n" ); FreeDefs(); TouchWorldModels(); AddWorldModelEntities(); ClearPortalStates(); return true; } common->Printf( "idRenderWorldLocal::InitFromMap: timestamp has changed, reloading.\n" ); } FreeWorld(); // see if we have a generated version of this static const byte BPROC_VERSION = 1; static const unsigned int BPROC_MAGIC = ( 'P' << 24 ) | ( 'R' << 16 ) | ( 'O' << 8 ) | BPROC_VERSION; bool loaded = false; idFileLocal file( fileSystem->OpenFileReadMemory( generatedFileName ) ); if( file != NULL ) { int numEntries = 0; int magic = 0; file->ReadBig( magic ); if( magic == BPROC_MAGIC ) { file->ReadBig( numEntries ); file->ReadString( mapName ); file->ReadBig( mapTimeStamp ); loaded = true; for( int i = 0; i < numEntries; i++ ) { idStrStatic< MAX_OSPATH > type; file->ReadString( type ); type.ToLower(); if( type == "model" ) { idRenderModel* lastModel = ReadBinaryModel( file ); if( lastModel == NULL ) { loaded = false; break; } renderModelManager->AddModel( lastModel ); localModels.Append( lastModel ); } else if( type == "shadowmodel" ) { idRenderModel* lastModel = ReadBinaryModel( file ); if( lastModel == NULL ) { loaded = false; break; } renderModelManager->AddModel( lastModel ); localModels.Append( lastModel ); } else if( type == "interareaportals" ) { ReadBinaryAreaPortals( file ); } else if( type == "nodes" ) { ReadBinaryNodes( file ); } else { idLib::Error( "Binary proc file failed, unexpected type %s\n", type.c_str() ); } } } } if( !loaded ) { src = new( TAG_RENDER ) idLexer( filename, LEXFL_NOSTRINGCONCAT | LEXFL_NODOLLARPRECOMPILE ); if( !src->IsLoaded() ) { common->Printf( "idRenderWorldLocal::InitFromMap: %s not found\n", filename.c_str() ); ClearWorld(); return false; } mapName = name; mapTimeStamp = currentTimeStamp; // if we are writing a demo, archive the load command if( common->WriteDemo() ) { WriteLoadMap(); } if( !src->ReadToken( &token ) || token.Icmp( PROC_FILE_ID ) ) { common->Printf( "idRenderWorldLocal::InitFromMap: bad id '%s' instead of '%s'\n", token.c_str(), PROC_FILE_ID ); delete src; return false; } int numEntries = 0; idFileLocal outputFile( fileSystem->OpenFileWrite( generatedFileName, "fs_basepath" ) ); if( outputFile != NULL ) { int magic = BPROC_MAGIC; outputFile->WriteBig( magic ); outputFile->WriteBig( numEntries ); outputFile->WriteString( mapName ); outputFile->WriteBig( mapTimeStamp ); } // parse the file while( 1 ) { if( !src->ReadToken( &token ) ) { break; } common->UpdateLevelLoadPacifier(); if( token == "model" ) { lastModel = ParseModel( src, name, currentTimeStamp, outputFile ); // add it to the model manager list renderModelManager->AddModel( lastModel ); // save it in the list to free when clearing this map localModels.Append( lastModel ); numEntries++; continue; } if( token == "shadowModel" ) { lastModel = ParseShadowModel( src, outputFile ); // add it to the model manager list renderModelManager->AddModel( lastModel ); // save it in the list to free when clearing this map localModels.Append( lastModel ); numEntries++; continue; } if( token == "interAreaPortals" ) { ParseInterAreaPortals( src, outputFile ); numEntries++; continue; } if( token == "nodes" ) { ParseNodes( src, outputFile ); numEntries++; continue; } src->Error( "idRenderWorldLocal::InitFromMap: bad token \"%s\"", token.c_str() ); } delete src; if( outputFile != NULL ) { outputFile->Seek( 0, FS_SEEK_SET ); int magic = BPROC_MAGIC; outputFile->WriteBig( magic ); outputFile->WriteBig( numEntries ); } } // if it was a trivial map without any areas, create a single area if( !numPortalAreas ) { ClearWorld(); } // find the points where we can early-our of reference pushing into the BSP tree CommonChildrenArea_r( &areaNodes[0] ); AddWorldModelEntities(); ClearPortalStates(); // done! return true; }
/* ================= idRenderWorldLocal::InitFromMap A NULL or empty name will make a world without a map model, which is still useful for displaying a bare model ================= */ bool idRenderWorldLocal::InitFromMap( const char *name ) { idLexer * src; idToken token; idStr filename; idRenderModel * lastModel; // if this is an empty world, initialize manually if ( !name || !name[0] ) { FreeWorld(); mapName.Clear(); ClearWorld(); return true; } // load it filename = name; filename.SetFileExtension( PROC_FILE_EXT ); // if we are reloading the same map, check the timestamp // and try to skip all the work ID_TIME_T currentTimeStamp; fileSystem->ReadFile( filename, NULL, ¤tTimeStamp ); if ( name == mapName ) { if ( currentTimeStamp != FILE_NOT_FOUND_TIMESTAMP && currentTimeStamp == mapTimeStamp ) { common->Printf( "idRenderWorldLocal::InitFromMap: retaining existing map\n" ); FreeDefs(); TouchWorldModels(); AddWorldModelEntities(); ClearPortalStates(); return true; } common->Printf( "idRenderWorldLocal::InitFromMap: timestamp has changed, reloading.\n" ); } FreeWorld(); src = new idLexer( filename, LEXFL_NOSTRINGCONCAT | LEXFL_NODOLLARPRECOMPILE ); if ( !src->IsLoaded() ) { common->Printf( "idRenderWorldLocal::InitFromMap: %s not found\n", filename.c_str() ); ClearWorld(); return false; } mapName = name; mapTimeStamp = currentTimeStamp; // if we are writing a demo, archive the load command if ( session->writeDemo ) { WriteLoadMap(); } if ( !src->ReadToken( &token ) || token.Icmp( PROC_FILE_ID ) ) { common->Printf( "idRenderWorldLocal::InitFromMap: bad id '%s' instead of '%s'\n", token.c_str(), PROC_FILE_ID ); delete src; return false; } // parse the file while ( 1 ) { if ( !src->ReadToken( &token ) ) { break; } if ( token == "model" ) { lastModel = ParseModel( src ); // add it to the model manager list renderModelManager->AddModel( lastModel ); // save it in the list to free when clearing this map localModels.Append( lastModel ); continue; } if ( token == "shadowModel" ) { lastModel = ParseShadowModel( src ); // add it to the model manager list renderModelManager->AddModel( lastModel ); // save it in the list to free when clearing this map localModels.Append( lastModel ); continue; } if ( token == "interAreaPortals" ) { ParseInterAreaPortals( src ); continue; } if ( token == "nodes" ) { ParseNodes( src ); continue; } src->Error( "idRenderWorldLocal::InitFromMap: bad token \"%s\"", token.c_str() ); } delete src; // if it was a trivial map without any areas, create a single area if ( !numPortalAreas ) { ClearWorld(); } // find the points where we can early-our of reference pushing into the BSP tree CommonChildrenArea_r( &areaNodes[0] ); AddWorldModelEntities(); ClearPortalStates(); // done! return true; }
/* ============== ProcessDemoCommand ============== */ bool idRenderWorldLocal::ProcessDemoCommand( idDemoFile* readDemo, renderView_t* renderView, int* demoTimeOffset ) { bool newMap = false; if( !readDemo ) { return false; } demoCommand_t dc; qhandle_t h; if( !readDemo->ReadInt( ( int& )dc ) ) { // a demoShot may not have an endFrame, but it is still valid return false; } switch( dc ) { case DC_LOADMAP: { // read the initial data demoHeader_t header; readDemo->ReadInt( header.version ); readDemo->ReadInt( header.sizeofRenderEntity ); readDemo->ReadInt( header.sizeofRenderLight ); for( int i = 0; i < 256; i++ ) readDemo->ReadChar( header.mapname[i] ); // the internal version value got replaced by DS_VERSION at toplevel if( header.version != 4 ) { common->Error( "Demo version mismatch.\n" ); } if( r_showDemo.GetBool() ) { common->Printf( "DC_LOADMAP: %s\n", header.mapname ); } // Clean up existing Renderer before loading the new map. FreeWorld(); // Load up the new map. InitFromMap( header.mapname ); newMap = true; // we will need to set demoTimeOffset break; } case DC_CACHE_SKINS: { int numSkins = 0; readDemo->ReadInt( numSkins ); for( int i = 0; i < numSkins; ++i ) { const char* declName = readDemo->ReadHashString(); declManager->FindSkin( declName, true ); } if( r_showDemo.GetBool() ) { common->Printf( "DC_CACHESKINS: %d\n", numSkins ); } break; } case DC_CACHE_PARTICLES: { int numDecls = 0; readDemo->ReadInt( numDecls ); for( int i = 0; i < numDecls; ++i ) { const char* declName = readDemo->ReadHashString(); declManager->FindType( DECL_PARTICLE, declName, true ); } if( r_showDemo.GetBool() ) { common->Printf( "DC_CACHE_PARTICLES: %d\n", numDecls ); } break; } case DC_CACHE_MATERIALS: { int numDecls = 0; readDemo->ReadInt( numDecls ); for( int i = 0; i < numDecls; ++i ) { const char* declName = readDemo->ReadHashString(); declManager->FindMaterial( declName, true ); } if( r_showDemo.GetBool() ) { common->Printf( "DC_CACHE_MATERIALS: %d\n", numDecls ); } break; } case DC_RENDERVIEW: { readDemo->ReadInt( renderView->viewID ); readDemo->ReadFloat( renderView->fov_x ); readDemo->ReadFloat( renderView->fov_y ); readDemo->ReadVec3( renderView->vieworg ); readDemo->ReadMat3( renderView->viewaxis ); readDemo->ReadBool( renderView->cramZNear ); readDemo->ReadBool( renderView->forceUpdate ); // binary compatibility with win32 padded structures char tmp; readDemo->ReadChar( tmp ); readDemo->ReadChar( tmp ); readDemo->ReadInt( renderView->time[0] ); readDemo->ReadInt( renderView->time[1] ); for( int i = 0; i < MAX_GLOBAL_SHADER_PARMS; i++ ) readDemo->ReadFloat( renderView->shaderParms[i] ); if( !readDemo->ReadInt( ( int& )renderView->globalMaterial ) ) { return false; } if( r_showDemo.GetBool() ) { // foresthale 2014-05-19: /analyze fix - was time, changed to time[0] common->Printf( "DC_RENDERVIEW: %i\n", renderView->time[ 0 ] ); } // possibly change the time offset if this is from a new map if( newMap && demoTimeOffset ) { *demoTimeOffset = renderView->time[1] - eventLoop->Milliseconds(); } return false; } case DC_UPDATE_ENTITYDEF: { ReadRenderEntity(); break; } case DC_DELETE_ENTITYDEF: { if( !readDemo->ReadInt( h ) ) { return false; } if( r_showDemo.GetBool() ) { common->Printf( "DC_DELETE_ENTITYDEF: %i\n", h ); } FreeEntityDef( h ); break; } case DC_UPDATE_LIGHTDEF: { ReadRenderLight(); break; } case DC_DELETE_LIGHTDEF: { if( !readDemo->ReadInt( h ) ) { return false; } if( r_showDemo.GetBool() ) { common->Printf( "DC_DELETE_LIGHTDEF: %i\n", h ); } FreeLightDef( h ); break; } case DC_CAPTURE_RENDER: { if( r_showDemo.GetBool() ) { common->Printf( "DC_CAPTURE_RENDER\n" ); } renderSystem->CaptureRenderToImage( readDemo->ReadHashString() ); break; } case DC_CROP_RENDER: { if( r_showDemo.GetBool() ) { common->Printf( "DC_CROP_RENDER\n" ); } int width, height; readDemo->ReadInt( width ); readDemo->ReadInt( height ); renderSystem->CropRenderSize( width, height ); break; } case DC_UNCROP_RENDER: { if( r_showDemo.GetBool() ) { common->Printf( "DC_UNCROP\n" ); } renderSystem->UnCrop(); break; } case DC_GUI_MODEL: { if( r_showDemo.GetBool() ) { common->Printf( "DC_GUI_MODEL\n" ); } break; } case DC_DEFINE_MODEL: { idRenderModel* model = renderModelManager->AllocModel(); model->ReadFromDemoFile( common->ReadDemo() ); // add to model manager, so we can find it renderModelManager->AddModel( model ); // save it in the list to free when clearing this map localModels.Append( model ); if( r_showDemo.GetBool() ) { common->Printf( "DC_DEFINE_MODEL\n" ); } break; } case DC_UPDATE_DECAL: { if( !readDemo->ReadInt( h ) ) { return false; } int data[ 2 ]; readDemo->ReadInt( data[ 0 ] ); readDemo->ReadInt( data[ 1 ] ); decals[ h ].entityHandle = data[ 0 ]; decals[ h ].lastStartTime = data[ 1 ]; decals[ h ].decals->ReadFromDemoFile( readDemo ); break; } case DC_DELETE_DECAL: { if( !readDemo->ReadInt( h ) ) { return false; } int data[ 2 ]; readDemo->ReadInt( data[ 0 ] ); readDemo->ReadInt( data[ 1 ] ); decals[ h ].entityHandle = data[ 0 ]; decals[ h ].lastStartTime = data[ 1 ]; decals[ h ].decals->ReUse(); break; } case DC_UPDATE_OVERLAY: { if( !readDemo->ReadInt( h ) ) { return false; } int data[ 2 ]; readDemo->ReadInt( data[ 0 ] ); readDemo->ReadInt( data[ 1 ] ); overlays[ h ].entityHandle = data[ 0 ]; overlays[ h ].lastStartTime = data[ 1 ]; overlays[ h ].overlays->ReadFromDemoFile( readDemo ); break; } case DC_DELETE_OVERLAY: { if( !readDemo->ReadInt( h ) ) { return false; } int data[ 2 ]; readDemo->ReadInt( data[ 0 ] ); readDemo->ReadInt( data[ 1 ] ); overlays[ h ].entityHandle = data[ 0 ]; overlays[ h ].lastStartTime = data[ 1 ]; overlays[ h ].overlays->ReUse(); break; } case DC_SET_PORTAL_STATE: { int data[2]; readDemo->ReadInt( data[0] ); readDemo->ReadInt( data[1] ); SetPortalState( data[0], data[1] ); if( r_showDemo.GetBool() ) { common->Printf( "DC_SET_PORTAL_STATE: %i %i\n", data[0], data[1] ); } break; } case DC_END_FRAME: { if( r_showDemo.GetBool() ) { common->Printf( "DC_END_FRAME\n" ); } return true; } default: common->Error( "Bad demo render command '%d' in demo stream", dc ); break; } return false; }
bool MD5Renderer::InitFromMap( const char *name ) { idLexer * src; idToken token; idStr filename; idRenderModel * lastModel; // if this is an empty world, initialize manually if ( !name || !name[0] ) { FreeWorld(); mapName.Clear(); ClearWorld(); return true; } // load it filename = name; filename.SetFileExtension( PROC_FILE_EXT ); FreeWorld(); src = new idLexer( filename, LEXFL_NOSTRINGCONCAT | LEXFL_NODOLLARPRECOMPILE ); if ( !src->IsLoaded() ) { //common->Printf( "idRenderWorldLocal::InitFromMap: %s not found\n", filename.c_str() ); ClearWorld(); return false; } mapName = name; if ( !src->ReadToken( &token ) || token.Icmp( PROC_FILE_ID ) ) { //common->Printf( "idRenderWorldLocal::InitFromMap: bad id '%s' instead of '%s'\n", token.c_str(), PROC_FILE_ID ); delete src; return false; } int num = 0; // parse the file while ( 1 ) { if ( !src->ReadToken( &token ) ) { break; } if ( token == "model" ) { //lastModel = ParseModel( src ); ParseModel( src ); num++; // add it to the model manager list //renderModelManager->AddModel( lastModel ); // save it in the list to free when clearing this map //localModels.Append( lastModel ); continue; } if ( token == "shadowModel" ) { //lastModel = ParseShadowModel( src ); // add it to the model manager list //renderModelManager->AddModel( lastModel ); // save it in the list to free when clearing this map //localModels.Append( lastModel ); continue; } if ( token == "interAreaPortals" ) { ParseInterAreaPortals( src ); continue; } if ( token == "nodes" ) { ParseNodes( src ); continue; } src->Error( "idRenderWorldLocal::InitFromMap: bad token \"%s\"", token.c_str() ); } delete src; // if it was a trivial map without any areas, create a single area if ( !numPortalAreas ) { ClearWorld(); } for (size_t i = 0; i < gameLocal.mCurrScene->Areas_.size(); ++i) { gameLocal.mCurrScene->Areas_.at(i)->CreateBuffers(); } // find the points where we can early-our of reference pushing into the BSP tree //CommonChildrenArea_r( &areaNodes[0] ); //AddWorldModelEntities(); //ClearPortalStates(); // done! return true; }