static bool GetRadioSoundName(CGameRules *gr, const string &teamName, const int groupId, const int keyId, char **ppSoundName = 0, char **ppSoundText = 0, int *pVariations = 0)
{
	SmartScriptTable radioTable;

	if(!GetTeamRadioTable(gr, teamName, radioTable))
	{
		return false;
	}

	SmartScriptTable groupTable;

	if(!radioTable->GetAt(groupId, groupTable))
	{
		return false;
	}

	SmartScriptTable soundTable;

	if(!groupTable->GetAt(keyId, soundTable))
	{
		return false;
	}

	ScriptAnyValue soundName;
	ScriptAnyValue soundText;
	ScriptAnyValue soundVariations = 1;

	if(!soundTable->GetAtAny(1, soundName) || !soundTable->GetAtAny(2, soundText))
	{
		return false;
	}

	soundTable->GetAtAny(3, soundVariations);

	if(pVariations)
	{
		soundVariations.CopyTo(*pVariations);
	}

	if(ppSoundName)
	{
		if(!soundName.CopyTo(*ppSoundName))
		{
			return false;
		}
	}

	if(ppSoundText)
	{
		if(!soundText.CopyTo(*ppSoundText))
		{
			return false;
		}
	}

	return true;
}
Example #2
0
	bool Prologue( EntityId objID, bool bClient, uint8 funcID )
	{
		if (!InitGameMembers(objID))
			return false;

		SmartScriptTable dispatchTable;
		if (!m_pScriptTable->GetValue( bClient? CLIENT_DISPATCH_FIELD : SERVER_DISPATCH_FIELD, dispatchTable))
			return false;

		const char * funcData;
		if (!dispatchTable->GetAt( funcID+1, funcData ))
		{
			GameWarning( "No such function dispatch index %d on entity %s (class %s)", funcID,
				m_pEntity->GetName(), m_pEntity->GetClass()->GetName() );
			return false;
		}

		const char * colon = strchr(funcData, ':');
		if (colon == NULL)
			return false;
		if (colon - funcData > BUFFER)
			return false;
		memcpy( m_function, funcData, colon-funcData );
		m_function[colon-funcData] = 0;
		m_format = colon + 1;
		return true;
	}
bool CRadio::UpdatePendingGroup()
{
	// key used in menu request was already consumed by sub level,
	// or the menu is open, but sub level have not yet got a change to update.
	if (m_inputEventConsumedKey ||
			((m_currentGroup != -1) && m_waitForInputEvents))
	{
		m_inputEventConsumedKey = false;
		m_requestedGroup = -1;
		return false;
	}

	if (m_requestedGroup == -1)
	{
		return false;
	}

	if (m_requestedGroup == m_currentGroup)
	{
		CloseRadioMenu();
		m_currentGroup = -1;
		m_requestedGroup = -1;
		return true;
	}

	m_currentGroup = m_requestedGroup;
	m_requestedGroup = -1;
	m_menuOpenTime = gEnv->pTimer->GetCurrTime();
	PlaySound("Sounds/interface:menu:pop_up");

	if (gEnv->pInput)
	{
		gEnv->pInput->AddEventListener(this);
	}

	g_pGameActions->FilterMPRadio()->Enable(true);
	SmartScriptTable radioTable;

	if(!GetTeamRadioTable(m_pGameRules, m_TeamName, radioTable))
	{
		return false;
	}

	SmartScriptTable groupTable;

	if(!radioTable->GetAt(m_currentGroup + 1, groupTable))
	{
		return false;
	}

	return true;
}
Example #4
0
	template <class V> bool GetVarValue(SmartScriptTable& t, int idx, V& val) { return t->GetAt(idx, val); }
Example #5
0
bool CScriptBind_Boids::ReadParamsTable(IScriptTable *pTable, struct SBoidContext &bc,SBoidsCreateContext &ctx )
{
	pTable->BeginSetGetChain();
	float fval;
	const char *str;

	ctx.models.clear();
	ctx.boidsCount = 0;
	pTable->GetValueChain( "count",ctx.boidsCount );
	if (pTable->GetValueChain( "model",str ))
	{
		ctx.models.push_back(str);
	}
	if (pTable->GetValueChain( "model1",str ))
	{
		if (str[0])
			ctx.models.push_back(str);
	}
	if (pTable->GetValueChain( "model2",str ))
	{
		if (str[0])
			ctx.models.push_back(str);
	}
	if (pTable->GetValueChain( "model3",str ))
	{
		if (str[0])
			ctx.models.push_back(str);
	}
	if (pTable->GetValueChain( "model4",str ))
	{
		if (str[0])
			ctx.models.push_back(str);
	}
	if (pTable->GetValueChain( "character",str ))
	{
		ctx.characterModel = str;
	}
	if (pTable->GetValueChain( "animation",str ))
	{
		ctx.animation = str;
	}

	pTable->GetValueChain( "behavior",bc.behavior );

	pTable->GetValueChain( "boid_mass",bc.fBoidMass);

	pTable->GetValueChain( "boid_size",bc.boidScale );
	pTable->GetValueChain( "boid_size_random",bc.boidRandomScale );
	pTable->GetValueChain( "min_height",bc.MinHeight );
	pTable->GetValueChain( "max_height",bc.MaxHeight );
	pTable->GetValueChain( "min_attract_distance",bc.MinAttractDistance );
	pTable->GetValueChain( "max_attract_distance",bc.MaxAttractDistance );
	
	if(bc.MinAttractDistance <=0.05f)
		bc.MinAttractDistance = 0.05f;
	if(bc.MaxAttractDistance <=bc.MinAttractDistance)
		bc.MaxAttractDistance =bc.MinAttractDistance +0.05f;

	pTable->GetValueChain( "min_speed",bc.MinSpeed );
	pTable->GetValueChain( "max_speed",bc.MaxSpeed );
	
	pTable->GetValueChain( "factor_align",bc.factorAlignment );
	pTable->GetValueChain( "factor_cohesion",bc.factorCohesion );
	pTable->GetValueChain( "factor_separation",bc.factorSeparation );
	pTable->GetValueChain( "factor_origin",bc.factorAttractToOrigin );
	pTable->GetValueChain( "factor_keep_height",bc.factorKeepHeight );
	pTable->GetValueChain( "factor_avoid_land",bc.factorAvoidLand );
	pTable->GetValueChain( "factor_random_accel",bc.factorRandomAccel );
	pTable->GetValueChain( "flight_time",bc.flightTime );
	pTable->GetValueChain( "factor_take_off",bc.factorTakeOff );
	pTable->GetValueChain( "land_deceleration_height",bc.landDecelerationHeight);

	pTable->GetValueChain( "max_anim_speed",bc.MaxAnimationSpeed );
	pTable->GetValueChain( "follow_player",bc.followPlayer );
	pTable->GetValueChain( "no_landing",bc.noLanding );
	pTable->GetValueChain( "start_on_ground",bc.bStartOnGround );
	pTable->GetValueChain( "avoid_water",bc.bAvoidWater );
	pTable->GetValueChain( "avoid_obstacles",bc.avoidObstacles );
	pTable->GetValueChain( "max_view_distance",bc.maxVisibleDistance );
	pTable->GetValueChain( "max_animation_distance",bc.animationMaxDistanceSq);
	bc.animationMaxDistanceSq *= bc.animationMaxDistanceSq;
	pTable->GetValueChain( "spawn_from_point", bc.bSpawnFromPoint );
	pTable->GetValueChain( "pickable_alive", bc.bPickableWhenAlive );
	pTable->GetValueChain( "pickable_dead", bc.bPickableWhenDead );
	pTable->GetValueChain( "pickable_message", bc.pickableMessage );
	pTable->GetValueChain( "spawn_radius",bc.fSpawnRadius);
	//pTable->GetValueChain( "boid_radius",bc.fBoidRadius);
	pTable->GetValueChain( "gravity_at_death",bc.fGravity);
	pTable->GetValueChain( "boid_mass",bc.fBoidMass);
	if (pTable->GetValueChain( "fov_angle",fval ))
	{
		fval = fval/2.0f; // Half angle used for cos of fov.
		bc.cosFovAngle = cos_tpl(fval*gf_PI/180.0f);
	}

	pTable->GetValueChain("invulnerable", bc.bInvulnerable);

	SmartScriptTable groundTable;
	if (pTable->GetValueChain("ground",groundTable))
	{
		groundTable->BeginSetGetChain();
		groundTable->GetValueChain( "factor_align",bc.factorAlignmentGround );
		groundTable->GetValueChain( "factor_cohesion",bc.factorCohesionGround );
		groundTable->GetValueChain( "factor_separation",bc.factorSeparationGround );
		groundTable->GetValueChain( "factor_origin",bc.factorAttractToOriginGround );
		groundTable->GetValueChain( "walk_speed",bc.walkSpeed);
		groundTable->GetValueChain( "offset",bc.groundOffset);
		groundTable->GetValueChain( "walk_to_idle_duration",bc.fWalkToIdleDuration);
		groundTable->GetValueChain( "on_ground_idle_duration_min",bc.fOnGroundIdleDurationMin);
		groundTable->GetValueChain( "on_ground_idle_duration_max",bc.fOnGroundIdleDurationMax);
		groundTable->GetValueChain( "on_ground_walk_duration_min",bc.fOnGroundWalkDurationMin);
		groundTable->GetValueChain( "on_ground_walk_duration_max",bc.fOnGroundWalkDurationMax);

		groundTable->EndSetGetChain();
	}

	SmartScriptTable audio;
	if (pTable->GetValueChain("Audio", audio))
	{
		bc.audio.clear();
		for (int i = 1; i < audio->Count(); ++i)
		{
			str = "";
			if (audio->GetAt(i, str))
			{
				TAudioControlID audioControlID = INVALID_AUDIO_CONTROL_ID;
				gEnv->pAudioSystem->GetAudioTriggerID(str, audioControlID);
				bc.audio.push_back(audioControlID);
			}
		}
	}

	SmartScriptTable animations;
	if (pTable->GetValueChain("Animations",animations))
	{
		bc.animations.clear();	// related to CE-1736: clear contents from a previous call
		for (int i = 1; i < 100; i++)
		{
			str = "";
			if (animations->GetAt(i,str))
			{
				bc.animations.push_back(str);
			}
			else
				break;
		}
	}

	pTable->EndSetGetChain();

	return true;
}
Example #6
0
// build a script dispatch table - this table is the metatable for all
// dispatch proxy tables used (onClient, allClients, otherClients)
bool CScriptRMI::BuildDispatchTable( 
	SmartScriptTable methods, 
	SmartScriptTable classMethodTable, 
	SmartScriptTable cls, 
	const char * name )
{
	IScriptSystem * pSS = methods->GetScriptSystem();
	SmartScriptTable dispatch( pSS );

	uint8 funcID = 0;

	IScriptTable::SUserFunctionDesc fd;
	SFunctionInfo info;

	IScriptTable::Iterator iter = methods->BeginIteration();
	while (methods->MoveNext(iter))
	{
		if (iter.sKey)
		{
			const char * function = iter.sKey;

			if (strlen(function)>=2 && function[0] == '_' && function[1] == '_')
			{
				methods->EndIteration(iter);
				pSS->RaiseError( "In Net.Expose: can't expose functions beginning with '__' (function was %s)",
					function );
				return false;
			}

			SmartScriptTable specTable;
			if (!methods->GetValue(function, specTable))
			{
				methods->EndIteration(iter);
				pSS->RaiseError( "In Net.Expose: function %s entry is not a table (in %s)", 
					function, name );
				return false;
			}

			// fetch format
			int count = specTable->Count();
			if (count < 1)
			{
				methods->EndIteration(iter);
				pSS->RaiseError( "In Net.Expose: function %s entry is an empty table (in %s)", 
					function, name );
				return false;
			}
			else if (count-1 > MaxRMIParameters)
			{
				methods->EndIteration(iter);
				pSS->RaiseError( "In Net.Expose: function %s has too many parameters (%d) (in %s)", 
					function, count-1, name );
				return false;
			}
			int tempReliability;
			if (!specTable->GetAt(1, tempReliability) || tempReliability < 0 || tempReliability >= eNRT_NumReliabilityTypes)
			{
				methods->EndIteration(iter);
				pSS->RaiseError( "In Net.Expose: function %s has invalid reliability type %d (in %s)", 
					function, tempReliability, name );
				return false;
			}
			ENetReliabilityType reliability = (ENetReliabilityType) tempReliability;
			if (!specTable->GetAt(2, tempReliability) || tempReliability < 0 || tempReliability >= eRAT_NumAttachmentTypes)
			{
				methods->EndIteration(iter);
				pSS->RaiseError( "In Net.Expose: function %s has invalid attachment type %d (in %s)", 
					function, tempReliability, name );
			}
			ERMIAttachmentType attachment = (ERMIAttachmentType) tempReliability;
			string format;
			format.reserve(count-1);
			for (int i=3; i<=count; i++)
			{
				int type = 666;
				if (!specTable->GetAt( i, type ) || type<-128 || type>127)
				{
					methods->EndIteration(iter);
					pSS->RaiseError( "In Net.Expose: function %s has invalid serialization policy %d at %d (in %s)", 
						function, type, i, name );
					return false;
				}
				format.push_back( (char) type );
			}

			CRY_ASSERT( format.length() <= MaxRMIParameters );
			strcpy( info.format, format.c_str() );
			info.funcID = funcID;
			info.reliability = reliability;
			info.attachment = attachment;

			fd.pUserDataFunc = ProxyFunction;
			fd.sFunctionName = function;
			fd.nDataSize = sizeof(SFunctionInfo);
			fd.pDataBuffer = &info;
			fd.sGlobalName = "<net-dispatch>";
			fd.sFunctionParams = "(...)";

			dispatch->AddFunction( fd );

			string lookupData = function;
			lookupData += ":";
			lookupData += format;
			dispatch->SetAt( funcID+1, lookupData.c_str() );


			funcID ++;
			if (funcID == 0)
			{
				funcID--;
				methods->EndIteration(iter);
				pSS->RaiseError( "Too many functions... max is %d", funcID );
				return false;
			}
		}
		else
		{
			GameWarning( "In Net.Expose: non-string key ignored" );
		}
	}
	methods->EndIteration(iter);

	dispatch->SetValue( VALIDATED_FIELD, false );
	cls->SetValue( name, dispatch );

	return true;
}
Example #7
0
bool CScriptBind_Boids::ReadParamsTable(IScriptTable *pTable, struct SBoidContext &bc,SBoidsCreateContext &ctx )
{
	pTable->BeginSetGetChain();
	float fval;
	const char *str;

	ctx.models.clear();
	ctx.boidsCount = 0;
	pTable->GetValueChain( "count",ctx.boidsCount );
	if (pTable->GetValueChain( "model",str ))
	{
		ctx.models.push_back(str);
	}
	if (pTable->GetValueChain( "model1",str ))
	{
		if (str[0])
			ctx.models.push_back(str);
	}
	if (pTable->GetValueChain( "model2",str ))
	{
		if (str[0])
			ctx.models.push_back(str);
	}
	if (pTable->GetValueChain( "model3",str ))
	{
		if (str[0])
			ctx.models.push_back(str);
	}
	if (pTable->GetValueChain( "model4",str ))
	{
		if (str[0])
			ctx.models.push_back(str);
	}
	if (pTable->GetValueChain( "character",str ))
	{
		ctx.characterModel = str;
	}
	if (pTable->GetValueChain( "animation",str ))
	{
		ctx.animation = str;
	}

	pTable->GetValueChain( "behavior",bc.behavior );

	pTable->GetValueChain( "boid_mass",bc.fBoidMass);

	pTable->GetValueChain( "boid_size",bc.boidScale );
	pTable->GetValueChain( "boid_size_random",bc.boidRandomScale );
	pTable->GetValueChain( "min_height",bc.MinHeight );
	pTable->GetValueChain( "max_height",bc.MaxHeight );
	pTable->GetValueChain( "min_attract_distance",bc.MinAttractDistance );
	pTable->GetValueChain( "max_attract_distance",bc.MaxAttractDistance );
	
	if(bc.MinAttractDistance <=0.05f)
		bc.MinAttractDistance = 0.05f;
	if(bc.MaxAttractDistance <=bc.MinAttractDistance)
		bc.MaxAttractDistance =bc.MinAttractDistance +0.05f;

	pTable->GetValueChain( "min_speed",bc.MinSpeed );
	pTable->GetValueChain( "max_speed",bc.MaxSpeed );
	
	pTable->GetValueChain( "factor_align",bc.factorAlignment );
	pTable->GetValueChain( "factor_cohesion",bc.factorCohesion );
	pTable->GetValueChain( "factor_separation",bc.factorSeparation );
	pTable->GetValueChain( "factor_origin",bc.factorAttractToOrigin );
	pTable->GetValueChain( "factor_keep_height",bc.factorKeepHeight );
	pTable->GetValueChain( "factor_avoid_land",bc.factorAvoidLand );
	pTable->GetValueChain( "factor_random_accel",bc.factorRandomAccel );
	pTable->GetValueChain( "flight_time",bc.flightTime );
	pTable->GetValueChain( "factor_take_off",bc.factorTakeOff );
	pTable->GetValueChain( "land_deceleration_height",bc.landDecelerationHeight);

	pTable->GetValueChain( "max_anim_speed",bc.MaxAnimationSpeed );
	pTable->GetValueChain( "follow_player",bc.followPlayer );
	pTable->GetValueChain( "no_landing",bc.noLanding );
	pTable->GetValueChain( "start_on_ground",bc.bStartOnGround );
	pTable->GetValueChain( "avoid_water",bc.bAvoidWater );
	pTable->GetValueChain( "avoid_obstacles",bc.avoidObstacles );
	pTable->GetValueChain( "max_view_distance",bc.maxVisibleDistance );
	pTable->GetValueChain( "max_animation_distance",bc.animationMaxDistanceSq);
	bc.animationMaxDistanceSq *= bc.animationMaxDistanceSq;
	pTable->GetValueChain( "spawn_from_point", bc.bSpawnFromPoint );

	pTable->GetValueChain( "spawn_radius",bc.fSpawnRadius);
	//pTable->GetValueChain( "boid_radius",bc.fBoidRadius);
	pTable->GetValueChain( "gravity_at_death",bc.fGravity);
	pTable->GetValueChain( "boid_mass",bc.fBoidMass);
	if (pTable->GetValueChain( "fov_angle",fval ))
	{
		fval = fval/2.0f; // Half angle used for cos of fov.
		bc.cosFovAngle = cry_cosf(fval*gf_PI/180.0f);
	}

	SmartScriptTable groundTable;
	if (pTable->GetValueChain("ground",groundTable))
	{
		groundTable->BeginSetGetChain();
		groundTable->GetValueChain( "factor_align",bc.factorAlignmentGround );
		groundTable->GetValueChain( "factor_cohesion",bc.factorCohesionGround );
		groundTable->GetValueChain( "factor_separation",bc.factorSeparationGround );
		groundTable->GetValueChain( "factor_origin",bc.factorAttractToOriginGround );
		groundTable->GetValueChain( "walk_speed",bc.walkSpeed);
		groundTable->GetValueChain( "offset",bc.groundOffset);

		groundTable->EndSetGetChain();
	}

	SmartScriptTable sounds;
	if (pTable->GetValueChain("Sounds",sounds))
	{
		for (int i = 1; i < 100; i++)
		{
			str = "";
			if (sounds->GetAt(i,str))
			{
				bc.sounds.push_back(str);
			}
			else
				break;
		}
	}
	SmartScriptTable animations;
	if (pTable->GetValueChain("Animations",animations))
	{
		for (int i = 1; i < 100; i++)
		{
			str = "";
			if (animations->GetAt(i,str))
			{
				bc.animations.push_back(str);
			}
			else
				break;
		}
	}

	pTable->EndSetGetChain();

	return true;
}