Пример #1
0
//------------------------------------------------------------------------
int CScriptBind_Actor::CheckVirtualInventoryRestrictions(IFunctionHandler *pH, SmartScriptTable inventory, const char *itemClassName)
{
	CActor *pActor = GetActor(pH);
	if (!pActor)
		return pH->EndFunction();

	static std::vector<string> virtualInventory;
	virtualInventory.reserve(inventory->Count());

	IScriptTable::Iterator it=inventory->BeginIteration();
	while(inventory->MoveNext(it))
	{
		const char *itemClass=0;
		it.value.CopyTo(itemClass);

		if (itemClass && itemClass[0])
			virtualInventory.push_back(itemClass);
	}

	inventory->EndIteration(it);

	bool result=pActor->CheckVirtualInventoryRestrictions(virtualInventory, itemClassName);
	virtualInventory.resize(0);

	if (result)
		return pH->EndFunction(1);

	return pH->EndFunction();
}
Пример #2
0
IWriteXMLSourcePtr CXmlScriptSaver::BeginArray( const char * name, size_t * numElems, const XmlNodeRef& definition )
{
	SmartScriptTable childTable;
	if (!CurTable()->GetValue(name, childTable))
		return NULL;
	*numElems = childTable->Count();
	m_tables.push( childTable );
	return this;
}
Пример #3
0
//------------------------------------------------------------------------
bool SUIToLuaConversationHelper::LuaTableToUIArgs(SmartScriptTable table, SUIArguments &args)
{
	for (int i = 0; i <= table->Count(); ++i)
	{
		if (i == 0 && table->GetAtType(0) == svtNull)
			continue; // if passing {arg1, arg2, arg3} to scriptbind first entry will be nil

		TUIData val;
		if (!SUIConvHelperTmpl::LuaArgToUIArgImpl(table, i, val))
			return false;
		args.AddArgument( val );
	}
	return true;
}
Пример #4
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;
}
Пример #5
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;
}