Beispiel #1
0
		private void Init()
		{
			if(this.Disposed == true)
			{
				throw new ObjectDisposedException(this.GetType().Name);
			}

			idConsole.Warning("TODO: idPlayer.Init");

			string value;
			// TODO
			// TODO: idKeyValue kv;
			/*
const idKeyValue	*kv;

noclip					= false;
godmode					= false;

oldButtons				= 0;
oldFlags				= 0;

currentWeapon			= -1;
idealWeapon				= -1;
previousWeapon			= -1;
weaponSwitchTime		= 0;
weaponEnabled			= true;
weapon_soulcube			= SlotForWeapon( "weapon_soulcube" );
weapon_pda				= SlotForWeapon( "weapon_pda" );
weapon_fists			= SlotForWeapon( "weapon_fists" );
showWeaponViewModel		= GetUserInfo()->GetBool( "ui_showGun" );


lastDmgTime				= 0;
lastArmorPulse			= -10000;
lastHeartAdjust			= 0;
lastHeartBeat			= 0;
heartInfo.Init( 0, 0, 0, 0 );

bobCycle				= 0;
bobFrac					= 0.0f;
landChange				= 0;
landTime				= 0;
zoomFov.Init( 0, 0, 0, 0 );
centerView.Init( 0, 0, 0, 0 );
fxFov					= false;

influenceFov			= 0;
influenceActive			= 0;
influenceRadius			= 0.0f;
influenceEntity			= NULL;
influenceMaterial		= NULL;
influenceSkin			= NULL;

currentLoggedAccel		= 0;

focusTime				= 0;
focusGUIent				= NULL;
focusUI					= NULL;
focusCharacter			= NULL;
talkCursor				= 0;
focusVehicle			= NULL;

// remove any damage effects
playerView.ClearEffects();

// damage values
fl.takedamage			= true;
ClearPain();

// restore persistent data
RestorePersistantInfo();

bobCycle		= 0;
stamina			= 0.0f;
healthPool		= 0.0f;
nextHealthPulse = 0;
healthPulse		= false;
nextHealthTake	= 0;
healthTake		= false;

SetupWeaponEntity();
currentWeapon = -1;
previousWeapon = -1;

heartRate = BASE_HEARTRATE;
AdjustHeartRate( BASE_HEARTRATE, 0.0f, 0.0f, true );

idealLegsYaw = 0.0f;
legsYaw = 0.0f;
legsForward	= true;
oldViewYaw = 0.0f;*/

			// set the pm_ cvars
			if((idR.Game.IsMultiplayer == false) || (idR.Game.IsServer == true))
			{
				foreach(KeyValuePair<string, string> kvp in this.SpawnArgs.MatchPrefix("pm_"))
				{
					idR.CvarSystem.SetString(kvp.Key, kvp.Value);
				}
			}

			// disable stamina on hell levels
			if((idR.Game.World != null) && (idR.Game.World.SpawnArgs.GetBool("no_stamina") == true))
			{
				idR.CvarSystem.SetFloat("pm_stamina", 0.0f);
			}

			// TODO
			// stamina always initialized to maximum
			/*stamina = pm_stamina.GetFloat();

			// air always initialized to maximum too
			airTics = pm_airTics.GetFloat();
			airless = false;

			gibDeath = false;
			gibsLaunched = false;
			gibsDir.Zero();*/

			// set the gravity
			_physicsObject.Gravity = idR.Game.Gravity;

			// start out standing
			/*SetEyeHeight(pm_normalviewheight.GetFloat());

			stepUpTime = 0;
			stepUpDelta = 0.0f;*/

			_viewBob = Vector3.Zero;
			_viewBobAngles = new idAngles();

			value = this.SpawnArgs.GetString("model", "");

			if(value != string.Empty)
			{
				SetModel(value);
			}

			if(_cursor != null)
			{
				_cursor.State.Set("talkcursor", 0);
				_cursor.State.Set("combatcursor", "1");
				_cursor.State.Set("itemcursor", "0");
				_cursor.State.Set("guicursor", "0");
			}

			if(((idR.Game.IsMultiplayer == true) || (idR.CvarSystem.GetBool("g_testDeath") == true)) && (_skin != null))
			{
				this.Skin = _skin;
				this.RenderEntity.MaterialParameters[6] = 0.0f;
			}
			else
			{
				string skin = this.SpawnArgs.GetString("spawn_skin", null);

				if(skin != null)
				{
					_skin = idR.DeclManager.FindSkin(skin);

					this.Skin = _skin;
					this.RenderEntity.MaterialParameters[6] = 0.0f;
				}
			}

			/* TODO: value = spawnArgs.GetString("bone_hips", "");
			hipJoint = animator.GetJointHandle(value);
			if(hipJoint == INVALID_JOINT)
			{
				gameLocal.Error("Joint '%s' not found for 'bone_hips' on '%s'", value, name.c_str());
			}

			value = spawnArgs.GetString("bone_chest", "");
			chestJoint = animator.GetJointHandle(value);
			if(chestJoint == INVALID_JOINT)
			{
				gameLocal.Error("Joint '%s' not found for 'bone_chest' on '%s'", value, name.c_str());
			}

			value = spawnArgs.GetString("bone_head", "");
			headJoint = animator.GetJointHandle(value);
			if(headJoint == INVALID_JOINT)
			{
				gameLocal.Error("Joint '%s' not found for 'bone_head' on '%s'", value, name.c_str());
			}

			// initialize the script variables
			AI_FORWARD = false;
			AI_BACKWARD = false;
			AI_STRAFE_LEFT = false;
			AI_STRAFE_RIGHT = false;
			AI_ATTACK_HELD = false;
			AI_WEAPON_FIRED = false;
			AI_JUMP = false;
			AI_DEAD = false;
			AI_CROUCH = false;
			AI_ONGROUND = true;
			AI_ONLADDER = false;
			AI_HARDLANDING = false;
			AI_SOFTLANDING = false;
			AI_RUN = false;
			AI_PAIN = false;
			AI_RELOAD = false;
			AI_TELEPORT = false;
			AI_TURN_LEFT = false;
			AI_TURN_RIGHT = false;

			// reset the script object*/
			ConstructScriptObject();

			// execute the script so the script object's constructor takes effect immediately
			/*scriptThread->Execute();*/

			// TODO: forceScoreBoard = false;
			this.ForceReady = false;


			/*privateCameraView = NULL;

			lastSpectateChange = 0;
			lastTeleFX = -9999;

			hiddenWeapon = false;
			tipUp = false;
			objectiveUp = false;
			teleportEntity = NULL;
			teleportKiller = -1;
			leader = false;

			SetPrivateCameraView(NULL);

			lastSnapshotSequence = 0;

			MPAim = -1;
			lastMPAim = -1;
			lastMPAimTime = 0;
			MPAimFadeTime = 0;
			MPAimHighlight = false;*/

			if(_hud != null)
			{
				_hud.HandleNamedEvent("aim_clear");
			}

			idR.CvarSystem.SetBool("ui_chat", false);
		}
Beispiel #2
0
		public override bool Parse(string text)
		{
			if(this.Disposed == true)
			{
				throw new ObjectDisposedException(this.GetType().Name);
			}

			idLexer lexer = new idLexer(idDeclFile.LexerOptions);
			lexer.LoadMemory(text, this.FileName, this.LineNumber);
			lexer.SkipUntilString("{");

			int defaultAnimationCount = 0;
			idToken token;
			idToken token2;
			string tokenValue;
			string fileName;
			string extension;
			int count;
			idMD5Joint[] md5Joints;

			while(true)
			{
				if((token = lexer.ReadToken()) == null)
				{
					break;
				}

				tokenValue = token.ToString();

				if(tokenValue == "}")
				{
					break;
				}

				if(tokenValue == "inherit")
				{
					idConsole.WriteLine("TODO: inherit");

					/*if( !src.ReadToken( &token2 ) ) {
						src.Warning( "Unexpected end of file" );
						MakeDefault();
						return false;
					}
			
					const idDeclModelDef *copy = static_cast<const idDeclModelDef *>( declManager->FindType( DECL_MODELDEF, token2, false ) );
					if ( !copy ) {
						common->Warning( "Unknown model definition '%s'", token2.c_str() );
					} else if ( copy->GetState() == DS_DEFAULTED ) {
						common->Warning( "inherited model definition '%s' defaulted", token2.c_str() );
						MakeDefault();
						return false;
					} else {
						CopyDecl( copy );
						numDefaultAnims = anims.Num();
					}*/
				} 
				else if(tokenValue == "skin") 
				{
					if((token2 = lexer.ReadToken()) == null)
					{
						lexer.Warning("Unexpected end of file");
						MakeDefault();

						return false;
					}

					_skin = idE.DeclManager.FindSkin(token2.ToString());

					if(_skin == null)
					{
						lexer.Warning("Skin '{0}' not found", token2.ToString());
						MakeDefault();

						return false;
					}
				} 
				else if(tokenValue == "mesh")
				{
					if((token2 = lexer.ReadToken()) == null)
					{
						lexer.Warning("Unexpected end of file");
						MakeDefault();

						return false;
					}

					fileName = token2.ToString();
					extension = Path.GetExtension(fileName);

					if(extension != idRenderModel_MD5.MeshExtension)
					{
						lexer.Warning("Invalid model for MD5 mesh");
						MakeDefault();

						return false;
					}

					_model = idE.RenderModelManager.FindModel(fileName);

					if(_model == null)
					{
						lexer.Warning("Model '{0}' not found", fileName);
						MakeDefault();

						return false;
					}
					else if(_model.IsDefault == true)
					{
						lexer.Warning("Model '{0}' defaulted", fileName);
						MakeDefault();

						return false;
					}

					// get the number of joints
					count = _model.JointCount;

					if(count == 0)
					{
						lexer.Warning("Model '{0}' has no joints", fileName);
					}

					// set up the joint hierarchy
					md5Joints = _model.Joints;

					_joints = new JointInfo[count];
					_jointParents = new int[count];
					_channelJoints = new int[(int) AnimationChannel.Count][];
					_channelJoints[0] = new int[count];

					for(int i = 0; i < count; i++)
					{
						_joints[i] = new JointInfo();
						_joints[i].Channel = AnimationChannel.All;
						_joints[i].Index = i;

						if(md5Joints[i].Parent != null)
						{
							_joints[i].ParentIndex = _model.GetJointIndex(md5Joints[i].Parent);
						}
						else
						{
							_joints[i].ParentIndex = -1;
						}

						_jointParents[i] = _joints[i].ParentIndex;
						_channelJoints[0][i] = i;
					}
				}
				else if(tokenValue == "remove")
				{
					idConsole.Warning("TODO: remove");

					// removes any anims whos name matches
					/*if( !src.ReadToken( &token2 ) ) {
						src.Warning( "Unexpected end of file" );
						MakeDefault();
						return false;
					}
					num = 0;
					for( i = 0; i < anims.Num(); i++ ) {
						if ( ( token2 == anims[ i ]->Name() ) || ( token2 == anims[ i ]->FullName() ) ) {
							delete anims[ i ];
							anims.RemoveIndex( i );
							if ( i >= numDefaultAnims ) {
								src.Warning( "Anim '%s' was not inherited.  Anim should be removed from the model def.", token2.c_str() );
								MakeDefault();
								return false;
							}
							i--;
							numDefaultAnims--;
							num++;
							continue;
						}
					}
					if ( !num ) {
						src.Warning( "Couldn't find anim '%s' to remove", token2.c_str() );
						MakeDefault();
						return false;
					}*/
				} 
				else if(tokenValue == "anim") 
				{
					if(_model == null)
					{
						lexer.Warning("Must specify mesh before defining anims");
						MakeDefault();

						return false;
					}
					else if(ParseAnimation(lexer, defaultAnimationCount) == false)
					{
						MakeDefault();

						return false;
					}
				} 
				else if(tokenValue == "offset") 
				{
					float[] tmp = lexer.Parse1DMatrix(3);

					if(tmp == null)
					{
						lexer.Warning("Expected vector following 'offset'");
						MakeDefault();
						return false;
					}

					_offset = new Vector3(tmp[0], tmp[1], tmp[2]);
				} 
				else if(tokenValue == "channel") 
				{
					if(_model == null)
					{
						lexer.Warning("Must specify mesh before defining channels");
						MakeDefault();

						return false;
					}

					// set the channel for a group of joints
					if((token2 = lexer.ReadToken()) == null)
					{
						lexer.Warning("Unexpected end of file");
						MakeDefault();

						return false;
					}

					if(lexer.CheckTokenString("(") == false)
					{
						lexer.Warning("Expected { after '{0}'", token2.ToString());
						MakeDefault();

						return false;
					}

					int i;
					int channelCount = (int) AnimationChannel.Count;

					for(i = (int) AnimationChannel.All + 1; i < channelCount; i++)
					{
						if(ChannelNames[i].Equals(token2.ToString(), StringComparison.OrdinalIgnoreCase) == true)
						{
							break;
						}
					}

					if(i >= channelCount)
					{
						lexer.Warning("Unknown channel '{0}'", token2.ToString());
						MakeDefault();

						return false;
					}

					int channel = i;
					StringBuilder jointNames = new StringBuilder();
					string token2Value;

					while(lexer.CheckTokenString(")") == false)
					{
						if((token2 = lexer.ReadToken()) == null)
						{
							lexer.Warning("Unexpected end of file");
							MakeDefault();

							return false;
						}

						token2Value = token2.ToString();
						jointNames.Append(token2Value);

						if((token2Value != "*") && (token2Value != "-"))
						{
							jointNames.Append(" ");
						}
					}

					int[] jointList = GetJointList(jointNames.ToString());
					int jointLength = jointList.Length;

					List<int> channelJoints = new List<int>();
					
					for(count = i = 0; i < jointLength; i++)
					{
						int jointIndex = jointList[i];

						if(_joints[jointIndex].Channel != AnimationChannel.All)
						{
							lexer.Warning("Join '{0}' assigned to multiple channels", _model.GetJointName(jointIndex));
							continue;
						}

						_joints[jointIndex].Channel = (AnimationChannel) channel;
						channelJoints.Add(jointIndex);
					}

					_channelJoints[channel] = channelJoints.ToArray();
				}
				else
				{
					lexer.Warning("unknown token '{0}'", token.ToString());
					MakeDefault();

					return false;
				}
			}
		
			return true;
		}
Beispiel #3
0
		public override void Spawn()
		{
			base.Spawn();

			if(this.Index >= idR.MaxClients)
			{
				idConsole.Error("entityIndex > MAX_CLIENTS for player.  Player may only be spawned with a client.");
			}

			// allow thinking during cinematics
			this.Cinematic = true;

			if(idR.Game.IsMultiplayer == true)
			{
				// always start in spectating state waiting to be spawned in
				// do this before SetClipModel to get the right bounding box
				this.IsSpectating = true;
			}

			// set our collision model
			_physicsObject.Self = this;

			SetClipModel();

			_physicsObject.SetMass(this.SpawnArgs.GetFloat("mass", 100));
			_physicsObject.SetContents(ContentFlags.Body);
			_physicsObject.SetClipMask(ContentFlags.MaskPlayerSolid);

			SetPhysics(_physicsObject);

			idConsole.Warning("TODO: InitAASLocation();");

			_skin = this.RenderEntity.CustomSkin;

			// only the local player needs guis
			if((idR.Game.IsMultiplayer == false) || (this.Index == idR.Game.LocalClientIndex))
			{
				// load HUD
				if(idR.Game.IsMultiplayer == true)
				{
					_hud = idR.UIManager.FindInterface("guis/mphud.gui", true, false, true);
				}
				else
				{
					string temp = this.SpawnArgs.GetString("hud", "");

					if(temp != string.Empty)
					{
						_hud = idR.UIManager.FindInterface(temp, true, false, true);
					}
				}

				if(_hud != null)
				{
					_hud.Activate(true, idR.Game.Time);
				}

				// load cursor
				string cursor = this.SpawnArgs.GetString("cursor", "");

				if(cursor != string.Empty)
				{
					_cursor = idR.UIManager.FindInterface(cursor, true, idR.Game.IsMultiplayer, idR.Game.IsMultiplayer);
				}

				if(_cursor != null)
				{
					_cursor.Activate(true, idR.Game.Time);
				}

				// TODO
				// objectiveSystem = uiManager->FindGui( "guis/pda.gui", true, false, true );
				// objectiveSystemOpen = false;
			}

			/*SetLastHitTime( 0 );

			// load the armor sound feedback
			declManager->FindSound( "player_sounds_hitArmor" );

			// set up conditions for animation
			LinkScriptVariables();

			animator.RemoveOriginOffset( true );*/

			// initialize user info related settings
			// on server, we wait for the userinfo broadcast, as this controls when the player is initially spawned in game
			if((idR.Game.IsClient == true) || (this.Index == idR.Game.LocalClientIndex))
			{
				UserInfoChanged(false);
			}

			// create combat collision hull for exact collision detection
			/*SetCombatModel();*/

			// supress model in non-player views, but allow it in mirrors and remote views
			this.RenderEntity.SuppressSurfaceInViewID = this.Index + 1;

			// don't project shadow on self or weapon
			this.RenderEntity.NoSelfShadow = true;

			/*idAFAttachment *headEnt = head.GetEntity();
			if ( headEnt ) {
				headEnt->GetRenderEntity()->suppressSurfaceInViewID = entityNumber+1;
				headEnt->GetRenderEntity()->noSelfShadow = true;
			}*/

			if(idR.Game.IsMultiplayer == true)
			{
				Init();
				Hide();	// properly hidden if starting as a spectator

				if(idR.Game.IsClient == false)
				{
					// set yourself ready to spawn. idMultiplayerGame will decide when/if appropriate and call SpawnFromSpawnSpot
					// TODO
					/*SetupWeaponEntity();*/
					SpawnFromSpawnSpot();

					_forceRespawn = true;
				}
			}
			else
			{
				idConsole.Warning("TODO: SetupWeaponEntity();");
				SpawnFromSpawnSpot();
			}
			
			// trigger playtesting item gives, if we didn't get here from a previous level
			// the devmap key will be set on the first devmap, but cleared on any level
			// transitions
			if((idR.Game.IsMultiplayer == false) && (idR.Game.ServerInfo.ContainsKey("devmap") == true))
			{
				idConsole.Warning("TODO: devmap");

				// fire a trigger with the name "devmap"
				/*idEntity *ent = gameLocal.FindEntity( "devmap" );
				if ( ent ) {
					ent->ActivateTargets( this );
				}*/
			}

			if(_hud != null)
			{
				idConsole.Warning("TODO: soul cube");

				// we can spawn with a full soul cube, so we need to make sure the hud knows this
				/*if ( weapon_soulcube > 0 && ( inventory.weapons & ( 1 << weapon_soulcube ) ) ) {
					int max_souls = inventory.MaxAmmoForAmmoClass( this, "ammo_souls" );
					if ( inventory.ammo[ idWeapon::GetAmmoNumForName( "ammo_souls" ) ] >= max_souls ) {
						hud->HandleNamedEvent( "soulCubeReady" );
					}
				}*/

				_hud.HandleNamedEvent("itemPickup");
			}

			idConsole.Warning("TODO: GetPDA");
			/*if ( GetPDA() ) {
				// Add any emails from the inventory
				for ( int i = 0; i < inventory.emails.Num(); i++ ) {
					GetPDA()->AddEmail( inventory.emails[i] );
				}
				GetPDA()->SetSecurity( common->GetLanguageDict()->GetString( "#str_00066" ) );
			}*/

			if(idR.Game.World.SpawnArgs.GetBool("no_Weapons") == true)
			{
				idConsole.Warning("TODO: no_Weapons");
			
				/*hiddenWeapon = true;
				if ( weapon.GetEntity() ) {
					weapon.GetEntity()->LowerWeapon();
				}
				idealWeapon = 0;*/
			} 
			else 
			{
				idConsole.Warning("TODO: hiddenWeapon = false;");
			}

			if(_hud != null)
			{
				idConsole.Warning("TODO: UpdateHudWeapon();");
				_hud.StateChanged(idR.Game.Time);
			}
			
			idConsole.Warning("TODO: inventory");

			/*tipUp = false;
			objectiveUp = false;

			if ( inventory.levelTriggers.Num() ) {
				PostEventMS( &EV_Player_LevelTrigger, 0 );
			}

			inventory.pdaOpened = false;
			inventory.selPDA = 0;*/

			if(idR.Game.IsMultiplayer == false)
			{
				int skill = idR.CvarSystem.GetInteger("g_skill");

				if(skill < 2)
				{
					if(this.Health < 25)
					{
						this.Health = 25;
					}

					if(idR.CvarSystem.GetBool("g_useDynamicProtection") == true)
					{
						idR.CvarSystem.SetFloat("g_damageScale", 1.0f);
					}
				} 
				else 
				{
					idR.CvarSystem.SetFloat("g_damageScale", 1.0f);
					idR.CvarSystem.SetFloat("g_armorProtection", (skill < 2) ? 0.4f : 0.2f);

					if(skill == 3)
					{
						idConsole.Warning("TODO: this.HealthTake = true");
						idConsole.Warning("TODO: nextHealthTake = gameLocal.time + g_healthTakeTime.GetInteger() * 1000;");
					}
				}
			}
		}
		public idMaterial RemapMaterialBySkin(idMaterial material, idDeclSkin skin, idMaterial customMaterial)
		{
			if(material == null)
			{
				return null;
			}

			// never remap surfaces that were originally nodraw, like collision hulls
			if(material.IsDrawn == false)
			{
				return material;
			}

			if(customMaterial != null)
			{
				// this is sort of a hack, but cause deformed surfaces to map to empty surfaces,
				// so the item highlight overlay doesn't highlight the autosprite surface
				if(material.Deform != DeformType.None)
				{
					return null;
				}

				return customMaterial;
			}

			if((skin == null) || (material == null))
			{
				return material;
			}

			return skin.RemapShaderBySkin(material);
		}