void CProjectile::Update(CTime elapsedTime) { mShape.move(mVelocity * elapsedTime.asSeconds()); if (!IsActive()) { mDeathTime -= elapsedTime; if (mDeathTime <= CTime::Zero) { MarkAsDead(); } } }
void CProjectile::ReactToCollision(CGameObject *theOtherObject, CVector2f correctionVector) { if (theOtherObject->IsA("Wall")) { if (IsActive()) { KillAfterTime(CTime::Seconds(2.0f)); mVelocity = CVector2f(0.0f, 0.0f); } } else if (theOtherObject->IsA("Player") && IsActive()) { MarkAsDead(); } }
bool CObject::CallMemberFunction( uint32 Checksum, Script::CScriptStructure *pParams, Script::CScript *pScript ) { Dbg_MsgAssert(pScript,("NULL pScript")); switch(Checksum) { case CRCC(0x3611c136, "GetTags"): CopyTagsToScriptStruct(pScript->GetParams()); break; case CRCC( 0xa58079eb, "SetTags" ): SetTagsFromScript( pParams ); break; case 0xc6870028:// "Die" MarkAsDead( ); break; case 0xb3c262ec:// "DisassociateFromObject" pScript->DisassociateWithObject(this); break; // @script | Obj_GetId | case 0x500eb224: // Obj_GetId Dbg_Assert( pScript && pScript->GetParams() ); pScript->GetParams()->AddChecksum( "objId", m_id ); break; // @script | Obj_FlagSet | Check to see if a flag has been set. Flags can // be defined anywhere, but you should keep them in your personal scripts file. // It is important that you prefix all flags with your initials to ensure that // there are no conflicts with the other designers. // <nl>Example 1: // <nl>MJD_LAMP_GOT_BROKEN = 14 // <nl>MJD_LAMP_GOT_HIT = 15 // <nl>MJD_LAMP_GOT_DISABLED = 16 // <nl>if Obj_FlagSet 15 // <nl> Obj_ClearFlag MJD_LAMP_GOT_HIT // <nl> WiggleProfusely // <nl>endif // <nl>Example 2: // <nl>if Obj_FlagSet MJD_LAMP_GOT_HIT clear // <nl> WiggleProfusely // <nl>endif // <nl>Example 3: // <nl>If Obj_FlagSet JKU_FLAG_PED_START // JKU_FLAG_PED_START would be defined in JKU_Scripts.q // <nl> Printf “Yes” // <nl>endif // @flag all | Clear all flags // @flag clear | Clear the flag // @flag reset | I just added a 'reset' flag you can send in to clear // the flag after checking it, if it's set case 0x4babc987: // Obj_FlagSet { uint32 scriptFlags = mScriptFlags; uint32 Flags = 0; Flags = GetFlags( pParams, pScript ); if ( !Flags ) { Dbg_MsgAssert( 0,( "\n%s\nObj_FlagSet command requires a flag to be specified.\n(Either an integer or a name defined to be an integer)",pScript->GetScriptInfo())); return ( false ); } if ( pParams->ContainsFlag( 0x1a4e0ef9 ) ) // clear { mScriptFlags &= ~( Flags ); } if ( scriptFlags & Flags ) { return true; } else { return false; } break; } // @script | Obj_FlagNotSet | Check to see if a flag has not been set. case 0x53ebee03: // Obj_FlagNotSet { uint32 Flags = 0; Flags = GetFlags( pParams, pScript ); if ( !Flags ) { Dbg_MsgAssert( 0,( "\n%s\nObj_FlagNotSet command requires a flag to be specified.\n(Either an integer or a name defined to be an integer)",pScript->GetScriptInfo())); return ( false ); } if ( mScriptFlags & ( Flags ) ) { return false; } else { return true; } break; } // @script | Obj_ClearFlag | Object member function which clears the specified flag or flags. // <nl>There are 3 ways of using it, it can clear just one flag, or an array of flags, // or all the flags. // <nl>Example 1: // <nl>Obj_ClearFlag JKU_FLAG_PED_START // Set the flag to 0 // <nl>Example 2: // <nl>Obj_ClearFlag [ JKU_FLAG_PED_START JKU_FLAG_PED_STOP ] // Clears an array of flags // <nl>Example 3: // <nl>Obj_ClearFlag All // Clears all the flags. // @flag all | Clear all the flags case 0x6c2b67f9: // Obj_ClearFlag { if (pParams->ContainsFlag(0xc4e78e22/*All*/)) { mScriptFlags=0; return true; } uint32 Flags = 0; Flags = GetFlags( pParams, pScript ); if ( !Flags ) { Dbg_MsgAssert( 0,( "\n%s\nObj_ClearFlag command requires a flag to be specified.\n(Either an integer or a name defined to be an integer)",pScript->GetScriptInfo())); return ( false ); } mScriptFlags &= ~Flags; break; } // @script | Obj_SetFlag | Sets the flag (or an array of flags) on an object. // <nl>Same parameters as Obj_ClearFlag (except doesn't recognize the // 'all' parameter). case 0xbe563426: // Obj_SetFlag { uint32 Flags = 0; Flags = GetFlags( pParams, pScript ); if ( !Flags ) { Dbg_MsgAssert( 0,( "\n%s\nObj_SetFlag command requires a flag to be specified.\n(Either an integer or a name defined to be an integer)",pScript->GetScriptInfo())); return ( false ); } mScriptFlags |= Flags; break; } // @script | Obj_KillSpawnedScript | Kills a spawned script. Can be passeed a name or id. // @parm name | name | Name of the script you want to spawn (no quotes) // @parm name | id | id of the script you want to spawn (no quotes) case 0xfbd89cd5: // Obj_KillSpawnedScript { uint32 ScriptChecksum=0; if (pParams->GetChecksum(CRCD(0xa1dc81f9,"Name"),&ScriptChecksum)) { // Got a script name, so kill all spawned scripts that ran that script. // BUT NOT THE SCRIPT CALLING THIS! Script::KillSpawnedScriptsWithObjectAndName( this, ScriptChecksum, pScript ); return true; } uint32 Id=0; if (pParams->GetChecksum(CRCD(0x40c698af,"Id"),&Id)) { // They specified an Id, so kill all spawned scripts with this Id, // BUT NOT THE SCRIPT CALLING THIS! Script::KillSpawnedScriptsWithObjectAndId( this, Id, pScript ); return ( true ); } Dbg_MsgAssert( 0,( "\n%s\nMust specify Name or ID on Obj_KillSpawnedScript", pScript->GetScriptInfo() )); return true; break; } // @script | Obj_SpawnScript | Causes the object to run a script, in parallel // to whatever script is running on the object. // @flag ScriptName | Name of the script you want to spawn (no quotes) // @parmopt name | Params | {} | Any parameters you want to pass to the script being // spawned. Must surround params in { } case 0x23a4e5c2: // Obj_SpawnScript { Script::CComponent* p_component = pParams->GetNextComponent(); if ( p_component && p_component->mType == ESYMBOLTYPE_NAME ) { uint32 scriptChecksum = p_component->mChecksum; // The spawned script can optionally be given an Id, so that it can be deleted // by KillSpawnedScript. uint32 Id=0; // keep the same ID as the parent if not specified... Id = Script::FindSpawnedScriptID(pScript); pParams->GetChecksum("Id",&Id); Script::CScriptStructure *pScriptParams = NULL; pParams->GetStructure( "Params", &pScriptParams ); #ifdef __NOPT_ASSERT__ Script::CScript *p_script=SpawnScriptPlease( scriptChecksum, pScriptParams, Id, pParams->ContainsFlag(CRCD(0x8757d0bb, "PauseWithObject")) ); p_script->SetCommentString("Created by Obj_SpawnScript"); p_script->SetOriginatingScriptInfo(pScript->GetCurrentLineNumber(),pScript->mScriptChecksum); #else SpawnScriptPlease( scriptChecksum, pScriptParams, Id ); #endif } break; } // @script | Obj_SwitchScript | Causes the object to replace the current script // attached to it with the script specified by ScriptName. <nl> // Can use the pass params just like Obj_SpawnScript. // @flag ScriptName | Name of the script you want to spawn (no quotes) case 0x714937c7: // Obj_SwitchScript { uint32 scriptChecksum; if ( pParams->GetChecksum( NONAME, &scriptChecksum ) ) { Script::CScriptStructure *pScriptParams = NULL; pParams->GetStructure( "Params", &pScriptParams ); SwitchScript( scriptChecksum, pScriptParams ); } break; } // case CRCC(0x6df6caef,"SetProperties"): case CRCC(0x6c63c7c5,"SetProps"): { // Lowest level SetProperties, allowing ANY object to set event handlers SetProperties(pParams); break; } /* case CRCC(0x1127430c, "ClearEventHandler"): { uint32 type; pParams->GetChecksum(NO_NAME, &type, Script::ASSERT); RemoveEventHandler(type); break; } case CRCC(0x8968da7f, "ClearEventHandlerGroup"): { uint32 group = CEventHandlerTable::vDEFAULT_GROUP; pParams->GetChecksum(NO_NAME, &group); RemoveEventHandlerGroup(group); break; } // @script | OnExceptionRun | run the specified script on exception // @uparm name | script name to run // can be called without a parameter to clear it // case 0x2c0c9e7b: // OnExceptionRun case CRCC(0x2c0c9e7b,"OnExceptionRun"): { uint32 OnExceptionScriptChecksum = 0; pParams->GetChecksum( NONAME, &OnExceptionScriptChecksum); #ifdef __SCRIPT_EVENT_TABLE__ if (mp_script) { mp_script->SetOnExceptionScriptChecksum(OnExceptionScriptChecksum); } #else SetOnExceptionScriptChecksum(OnExceptionScriptChecksum); #endif break; } case CRCC(0xbefaa466,"OnExitRun"): { uint32 OnExitScriptChecksum = 0; pParams->GetChecksum( NONAME, &OnExitScriptChecksum); #ifdef __SCRIPT_EVENT_TABLE__ if (mp_script) { mp_script->SetOnExitScriptChecksum(OnExitScriptChecksum); } #else SetOnExitScriptChecksum(OnExitScriptChecksum); #endif break; } */ case 0x20d125d7: // Obj_Visible m_object_flags &= ~vINVISIBLE; break; case 0x3578e5a9: // Obj_Invisible m_object_flags |= vINVISIBLE; break; default: Dbg_MsgAssert(0,("\n%s\nNo CObject member function found for '%s'",pScript->GetScriptInfo(),Script::FindChecksumName(Checksum))); } return true; }