WorldSpawn.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. /*
  21. game_worldspawn.cpp
  22. Worldspawn class. Each map has one worldspawn which handles global spawnargs.
  23. */
  24. #include "../idlib/precompiled.h"
  25. #pragma hdrstop
  26. #include "Game_local.h"
  27. /*
  28. ================
  29. idWorldspawn
  30. Every map should have exactly one worldspawn.
  31. ================
  32. */
  33. CLASS_DECLARATION( idEntity, idWorldspawn )
  34. EVENT( EV_Remove, idWorldspawn::Event_Remove )
  35. EVENT( EV_SafeRemove, idWorldspawn::Event_Remove )
  36. END_CLASS
  37. /*
  38. ================
  39. idWorldspawn::Spawn
  40. ================
  41. */
  42. void idWorldspawn::Spawn( void ) {
  43. idStr scriptname;
  44. idThread *thread;
  45. const function_t *func;
  46. const idKeyValue *kv;
  47. assert( gameLocal.world == NULL );
  48. gameLocal.world = this;
  49. g_gravity.SetFloat( spawnArgs.GetFloat( "gravity", va( "%f", DEFAULT_GRAVITY ) ) );
  50. // disable stamina on hell levels
  51. if ( spawnArgs.GetBool( "no_stamina" ) ) {
  52. pm_stamina.SetFloat( 0.0f );
  53. }
  54. // load script
  55. scriptname = gameLocal.GetMapName();
  56. scriptname.SetFileExtension( ".script" );
  57. if ( fileSystem->ReadFile( scriptname, NULL, NULL ) > 0 ) {
  58. gameLocal.program.CompileFile( scriptname );
  59. // call the main function by default
  60. func = gameLocal.program.FindFunction( "main" );
  61. if ( func != NULL ) {
  62. thread = new idThread( func );
  63. thread->DelayedStart( 0 );
  64. }
  65. }
  66. // call any functions specified in worldspawn
  67. kv = spawnArgs.MatchPrefix( "call" );
  68. while( kv != NULL ) {
  69. func = gameLocal.program.FindFunction( kv->GetValue() );
  70. if ( func == NULL ) {
  71. gameLocal.Error( "Function '%s' not found in script for '%s' key on worldspawn", kv->GetValue().c_str(), kv->GetKey().c_str() );
  72. }
  73. thread = new idThread( func );
  74. thread->DelayedStart( 0 );
  75. kv = spawnArgs.MatchPrefix( "call", kv );
  76. }
  77. }
  78. /*
  79. =================
  80. idWorldspawn::Save
  81. =================
  82. */
  83. void idWorldspawn::Save( idRestoreGame *savefile ) {
  84. }
  85. /*
  86. =================
  87. idWorldspawn::Restore
  88. =================
  89. */
  90. void idWorldspawn::Restore( idRestoreGame *savefile ) {
  91. assert( gameLocal.world == this );
  92. g_gravity.SetFloat( spawnArgs.GetFloat( "gravity", va( "%f", DEFAULT_GRAVITY ) ) );
  93. // disable stamina on hell levels
  94. if ( spawnArgs.GetBool( "no_stamina" ) ) {
  95. pm_stamina.SetFloat( 0.0f );
  96. }
  97. }
  98. /*
  99. ================
  100. idWorldspawn::~idWorldspawn
  101. ================
  102. */
  103. idWorldspawn::~idWorldspawn() {
  104. if ( gameLocal.world == this ) {
  105. gameLocal.world = NULL;
  106. }
  107. }
  108. /*
  109. ================
  110. idWorldspawn::Event_Remove
  111. ================
  112. */
  113. void idWorldspawn::Event_Remove( void ) {
  114. gameLocal.Error( "Tried to remove world" );
  115. }