frobcube.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #include "../idlib/precompiled.h"
  2. #pragma hdrstop
  3. #include "Game_local.h"
  4. CLASS_DECLARATION( idStaticEntity, idFrobCube )
  5. END_CLASS
  6. void idFrobCube::Save( idSaveGame *savefile ) const
  7. {
  8. savefile->WriteString(functionName);
  9. savefile->WriteString(masterName);
  10. }
  11. void idFrobCube::Restore( idRestoreGame *savefile )
  12. {
  13. savefile->ReadString(functionName);
  14. savefile->ReadString(masterName);
  15. //reinterpret_cast<idClass *&>(
  16. }
  17. void idFrobCube::Spawn( void )
  18. {
  19. if ( spawnArgs.GetBool( "solid", "0" ) )
  20. {
  21. this->GetPhysics()->SetContents( CONTENTS_SOLID );
  22. }
  23. functionName = NULL;
  24. functionName = spawnArgs.GetString("funcName");
  25. if (!functionName)
  26. {
  27. gameLocal.Warning( "idFrobCube '%s' at (%s): cannot find funcName.", name.c_str(), GetPhysics()->GetOrigin().ToString(0) );
  28. }
  29. masterName = NULL;
  30. masterName = spawnArgs.GetString("owner");
  31. if (!masterName)
  32. {
  33. gameLocal.Warning( "idFrobCube '%s' at (%s): cannot find owner.", name.c_str(), GetPhysics()->GetOrigin().ToString(0) );
  34. }
  35. }
  36. void idFrobCube::OnFrob( idEntity* activator )
  37. {
  38. //bc 3-28-2016 hide a specific thing.
  39. idStr hideName = spawnArgs.GetString("hidename");
  40. if (hideName)
  41. {
  42. idEntity *hideEnt = gameLocal.FindEntity( hideName );
  43. if (hideEnt)
  44. {
  45. hideEnt->Hide();
  46. }
  47. }
  48. //call script.
  49. idStr scriptName = spawnArgs.GetString( "call" );
  50. const function_t *scriptFunction;
  51. scriptFunction = gameLocal.program.FindFunction( scriptName );
  52. if ( scriptFunction )
  53. {
  54. idThread *thread;
  55. thread = new idThread( scriptFunction );
  56. thread->DelayedStart( 0 );
  57. }
  58. if (spawnArgs.GetBool("gettable"))
  59. {
  60. gameLocal.GetLocalPlayer()->StartSound( "snd_get", SND_CHANNEL_ANY, 0, false, NULL );
  61. this->Hide();
  62. idDict args;
  63. args.Clear();
  64. args.SetVector( "origin", this->GetPhysics()->GetOrigin() );
  65. args.Set( "model", "pickupdust.prt" );
  66. args.SetBool( "start_off", false );
  67. gameLocal.SpawnEntityType( idExplodable::Type, &args );
  68. return;
  69. }
  70. StartSound( "snd_frob", SND_CHANNEL_ANY, 0, false, NULL );
  71. idEntity *ownerEnt = gameLocal.FindEntity( masterName );
  72. if (!ownerEnt)
  73. {
  74. //gameLocal.Warning( "idFrobCube '%s' at (%s): owner '%s' doesn't exist.", name.c_str(), GetPhysics()->GetOrigin().ToString(0), masterName );
  75. return;
  76. }
  77. gameLocal.GetLocalPlayer()->UseFrob(ownerEnt, functionName);
  78. }