示例#1
0
//============================================================================
// Reads an escape character.
//
// Parameter:               script      : script to read from
//                              ch              : place to store the read escape character
// Returns:                 -
// Changes Globals:     -
//============================================================================
int PS_ReadEscapeCharacter(script_t* script, char* ch) {
    int c, val, i;

    //step over the leading '\\'
    script->script_p++;
    //determine the escape character
    switch (*script->script_p) {
        case '\\': c = '\\'; break;
        case 'n': c = '\n'; break;
        case 'r': c = '\r'; break;
        case 't': c = '\t'; break;
        case 'v': c = '\v'; break;
        case 'b': c = '\b'; break;
        case 'f': c = '\f'; break;
        case 'a': c = '\a'; break;
        case '\'': c = '\''; break;
        case '\"': c = '\"'; break;
        case '\?': c = '\?'; break;
        case 'x': {
            script->script_p++;
            for (i = 0, val = 0; ; i++, script->script_p++) {
                c = *script->script_p;
                if (c >= '0' && c <= '9') c = c - '0';
                else if (c >= 'A' && c <= 'Z') c = c - 'A' + 10;
                else if (c >= 'a' && c <= 'z') c = c - 'a' + 10;
                else break;
                val = (val << 4) + c;
            } //end for
            script->script_p--;
            if (val > 0xFF) {
                ScriptWarning(script, "too large value in escape character");
                val = 0xFF;
            } //end if
            c = val;
            break;
        } //end case
        default: { //NOTE: decimal ASCII code, NOT octal
            if (*script->script_p < '0' || *script->script_p > '9') ScriptError(script, "unknown escape char");
            for (i = 0, val = 0; ; i++, script->script_p++) {
                c = *script->script_p;
                if (c >= '0' && c <= '9') c = c - '0';
                else break;
                val = val * 10 + c;
            } //end for
            script->script_p--;
            if (val > 0xFF) {
                ScriptWarning(script, "too large value in escape character");
                val = 0xFF;
            } //end if
            c = val;
            break;
        } //end default
    } //end switch
    //step over the escape character or the last digit of the number
    script->script_p++;
    //store the escape character
    *ch = c;
    //successfully read escape character
    return 1;
} //end of the function PS_ReadEscapeCharacter
示例#2
0
//////////////////////////////////////////////////////////////////////////
// Delete a timer from the list.
void CScriptTimerMgr::RemoveTimer(int nTimerID)
{
	if (nTimerID == m_nTimerIDCurrentlyBeingCalled)
	{
		ScriptWarning("[CScriptTimerMgr::RemoveTimer] Trying to remove the timer (ID = %d, Lua function = %s) currently being called.", 			
			nTimerID,
			m_mapTimers.find(nTimerID)->second->sFuncName);
		return;
	}

	ScriptTimerMapItor it = m_mapTimers.find(nTimerID);

	if (it != m_mapTimers.end())
	{
		ScriptTimer* timer = it->second;
		DeleteTimer(timer);
		m_mapTimers.erase(it);
	}
	else
	{
		it = m_mapTempTimers.find(nTimerID);

		if (it != m_mapTempTimers.end())
		{
			ScriptTimer* timer = it->second;
			DeleteTimer(timer);
			m_mapTempTimers.erase(it);
		}
	}
}
示例#3
0
//============================================================================
//
// Parameter:               -
// Returns:                 -
// Changes Globals:     -
//============================================================================
int PS_ReadLiteral(script_t* script, token_t* token) {
    token->type = TT_LITERAL;
    //first quote
    token->string[0] = *script->script_p++;
    //check for end of file
    if (!*script->script_p) {
        ScriptError(script, "end of file before trailing \'");
        return 0;
    } //end if
    //if it is an escape character
    if (*script->script_p == '\\') {
        if (!PS_ReadEscapeCharacter(script, &token->string[1])) return 0;
    } //end if
    else {
        token->string[1] = *script->script_p++;
    } //end else
    //check for trailing quote
    if (*script->script_p != '\'') {
        ScriptWarning(script, "too many characters in literal, ignored");
        while (*script->script_p &&
                *script->script_p != '\'' &&
                *script->script_p != '\n') {
            script->script_p++;
        } //end while
        if (*script->script_p == '\'') script->script_p++;
    } //end if
    //store the trailing quote
    token->string[2] = *script->script_p++;
    //store trailing zero to end the string
    token->string[3] = '\0';
    //the sub type is the integer literal value
    token->subtype = token->string[1];
    //
    return 1;
} //end of the function PS_ReadLiteral
int CScriptBind_Physics::RegisterExplosionCrack(IFunctionHandler *pH,const char *sGeometryFile,int nIdMaterial )
{
	IStatObj *pObj = gEnv->p3DEngine->LoadStatObj( sGeometryFile,"#ForceBreakable",NULL,false);
	if (!pObj || pObj->IsDefaultObject())
	{
		ScriptWarning( "<RegisterExplosionCrack> Object file %s not found",sGeometryFile );
		return pH->EndFunction();
	}
	pObj->AddRef();
	Vec3 vtx[3] = { pObj->GetHelperPos("1"),pObj->GetHelperPos("2"),pObj->GetHelperPos("3") };
	//@TODO: restore it.
	m_pPhysicalWorld->GetGeomManager()->RegisterCrack( pObj->GetPhysGeom()->pGeom,vtx,0 );
	return pH->EndFunction();
}
int CScriptBind_Physics::RegisterExplosionShape(IFunctionHandler *pH,const char *sGeometryFile,float fSize,int nIdMaterial,float fProbability,
																								const char *sSplintersFile, float fSplintersOffset, const char *sSplintersCloudEffect)
{
	//////////////////////////////////////////////////////////////////////////
	// Remove all this.
	//////////////////////////////////////////////////////////////////////////
	IStatObj *pObj = gEnv->p3DEngine->LoadStatObj( sGeometryFile,"#ForceBreakable",NULL,false );
	if (!pObj || pObj->IsDefaultObject())
	{
		ScriptWarning( "<RegisterExplosionShape> Object file %s not found",sGeometryFile );
		return pH->EndFunction();
	}
	pObj->AddRef();
	pObj->GetIndexedMesh(true); // prepare idxMesh now 

	if(sSplintersFile && *sSplintersFile!=0)			// if sSplintersFile was specified
	{
		IStatObj *pSplinters = gEnv->p3DEngine->LoadStatObj(sSplintersFile,NULL,NULL,false);
		if (pSplinters)
		{
			pObj->SetSubObjectCount(pObj->GetSubObjectCount()+1);
			IStatObj::SSubObject *pSubObj = pObj->GetSubObject(pObj->GetSubObjectCount()-1);
			pSubObj->nType = STATIC_SUB_OBJECT_MESH;
			pSubObj->bHidden = true;
			pSubObj->name = "splinters";
			(pSubObj->pStatObj = pSplinters)->AddRef();
			pSubObj->helperSize.x = fSplintersOffset;
			nIdMaterial |= 1<<16;

			if (*sSplintersCloudEffect)
			{
				pSplinters->SetSubObjectCount(pSplinters->GetSubObjectCount()+1);
				pSplinters->SetFlags(pSplinters->GetFlags() & ~STATIC_OBJECT_COMPOUND);
				pSubObj = pSplinters->GetSubObject(pSplinters->GetSubObjectCount()-1);
				pSubObj->nType = STATIC_SUB_OBJECT_DUMMY;
				pSubObj->bHidden = true;
				pSubObj->name = "splinters_cloud";
				pSubObj->properties = sSplintersCloudEffect;
			}
		}
	}

	phys_geometry *pPhysGeom = pObj->GetPhysGeom();
	if (pPhysGeom)
	{
		m_pPhysicalWorld->AddExplosionShape( pPhysGeom->pGeom,fSize,nIdMaterial,fProbability );
	}
	return pH->EndFunction();
}
bool CFunctionHandler::GetParamAny( int nIdx,ScriptAnyValue &any )
{
	int nRealIdx = nIdx+m_paramIdOffset;
	bool bRes = m_pSS->ToAny(any,nRealIdx);
	if (!bRes)
	{
		ScriptVarType paramType = GetParamType(nIdx);
		const char *sParamType = ScriptVarTypeAsCStr(paramType);
		const char *sType = ScriptAnyTypeToString(any.type);
		// Report wrong param.
		ScriptWarning( "[Script Error] Wrong parameter type. Function %s expect parameter %d of type %s (Provided type %s)",m_sFuncName,nIdx,sType,sParamType );
		m_pSS->LogStackTrace();
	}
	return bRes;
}
示例#7
0
void CScriptTable::PushRef()
{
    if (m_nRef != DELETED_REF && m_nRef != NULL_REF)
        lua_getref(L,m_nRef);
    else
    {
        lua_pushnil(L);
        if (m_nRef == DELETED_REF)
        {
            assert(0 && "Access to deleted script object" );
            CryFatalError( "Access to deleted script object %x",(unsigned int)(UINT_PTR)this );
        }
        else
        {
            assert(0 && "Pushing Nil table reference");
            ScriptWarning( "Pushing Nil table reference" );
        }
    }
}
示例#8
0
文件: script.cpp 项目: janisl/jlquake
// Reads an escape character.
static bool PS_ReadEscapeCharacter( script_t* script, char* ch ) {
	//step over the leading '\\'
	script->script_p++;
	//determine the escape character
	int c;
	switch ( *script->script_p ) {
	case '\\': c = '\\'; break;
	case 'n': c = '\n'; break;
	case 'r': c = '\r'; break;
	case 't': c = '\t'; break;
	case 'v': c = '\v'; break;
	case 'b': c = '\b'; break;
	case 'f': c = '\f'; break;
	case 'a': c = '\a'; break;
	case '\'': c = '\''; break;
	case '\"': c = '\"'; break;
	case '\?': c = '\?'; break;
	case 'x':
	{
		script->script_p++;
		int val = 0;
		for ( int i = 0;; i++, script->script_p++ ) {
			c = *script->script_p;
			if ( c >= '0' && c <= '9' ) {
				c = c - '0';
			} else if ( c >= 'A' && c <= 'Z' ) {
				c = c - 'A' + 10;
			} else if ( c >= 'a' && c <= 'z' ) {
				c = c - 'a' + 10;
			} else {
				break;
			}
			val = ( val << 4 ) + c;
		}
		script->script_p--;
		if ( val > 0xFF ) {
			ScriptWarning( script, "too large value in escape character" );
			val = 0xFF;
		}
		c = val;
		break;
	}
	default:	//NOTE: decimal ASCII code, NOT octal
	{
		if ( *script->script_p < '0' || *script->script_p > '9' ) {
			ScriptError( script, "unknown escape char" );
		}
		int val = 0;
		for ( int i = 0;; i++, script->script_p++ ) {
			c = *script->script_p;
			if ( c >= '0' && c <= '9' ) {
				c = c - '0';
			} else {
				break;
			}
			val = val * 10 + c;
		}
		script->script_p--;
		if ( val > 0xFF ) {
			ScriptWarning( script, "too large value in escape character" );
			val = 0xFF;
		}
		c = val;
		break;
	}
	}
	//step over the escape character or the last digit of the number
	script->script_p++;
	//store the escape character
	*ch = c;
	//succesfully read escape character
	return true;
}