/// <summary> /// SV_AddGravity /// </summary> static void AddGravity(edict_t ent) { float val = Progs.GetEdictFieldFloat(ent, "gravity"); if (val == 0) { val = 1; } ent.v.velocity.z -= (float)(val * _Gravity.Value * Host.FrameTime); }
/// <summary> /// SV_WriteClientdataToMessage /// </summary> public static void WriteClientDataToMessage(edict_t ent, MsgWriter msg) { // // send a damage message // if (ent.v.dmg_take != 0 || ent.v.dmg_save != 0) { edict_t other = ProgToEdict(ent.v.dmg_inflictor); msg.WriteByte(Protocol.svc_damage); msg.WriteByte((int)ent.v.dmg_save); msg.WriteByte((int)ent.v.dmg_take); msg.WriteCoord(other.v.origin.x + 0.5f * (other.v.mins.x + other.v.maxs.x)); msg.WriteCoord(other.v.origin.y + 0.5f * (other.v.mins.y + other.v.maxs.y)); msg.WriteCoord(other.v.origin.z + 0.5f * (other.v.mins.z + other.v.maxs.z)); ent.v.dmg_take = 0; ent.v.dmg_save = 0; } // // send the current viewpos offset from the view entity // SetIdealPitch(); // how much to look up / down ideally // a fixangle might get lost in a dropped packet. Oh well. if (ent.v.fixangle != 0) { msg.WriteByte(Protocol.svc_setangle); msg.WriteAngle(ent.v.angles.x); msg.WriteAngle(ent.v.angles.y); msg.WriteAngle(ent.v.angles.z); ent.v.fixangle = 0; } int bits = 0; if (ent.v.view_ofs.z != Protocol.DEFAULT_VIEWHEIGHT) { bits |= Protocol.SU_VIEWHEIGHT; } if (ent.v.idealpitch != 0) { bits |= Protocol.SU_IDEALPITCH; } // stuff the sigil bits into the high bits of items for sbar, or else // mix in items2 float val = Progs.GetEdictFieldFloat(ent, "items2", 0); int items; if (val != 0) { items = (int)ent.v.items | ((int)val << 23); } else { items = (int)ent.v.items | ((int)Progs.GlobalStruct.serverflags << 28); } bits |= Protocol.SU_ITEMS; if (((int)ent.v.flags & EdictFlags.FL_ONGROUND) != 0) { bits |= Protocol.SU_ONGROUND; } if (ent.v.waterlevel >= 2) { bits |= Protocol.SU_INWATER; } if (ent.v.punchangle.x != 0) { bits |= Protocol.SU_PUNCH1; } if (ent.v.punchangle.y != 0) { bits |= Protocol.SU_PUNCH2; } if (ent.v.punchangle.z != 0) { bits |= Protocol.SU_PUNCH3; } if (ent.v.velocity.x != 0) { bits |= Protocol.SU_VELOCITY1; } if (ent.v.velocity.y != 0) { bits |= Protocol.SU_VELOCITY2; } if (ent.v.velocity.z != 0) { bits |= Protocol.SU_VELOCITY3; } if (ent.v.weaponframe != 0) { bits |= Protocol.SU_WEAPONFRAME; } if (ent.v.armorvalue != 0) { bits |= Protocol.SU_ARMOR; } // if (ent.v.weapon) bits |= Protocol.SU_WEAPON; // send the data msg.WriteByte(Protocol.svc_clientdata); msg.WriteShort(bits); if ((bits & Protocol.SU_VIEWHEIGHT) != 0) { msg.WriteChar((int)ent.v.view_ofs.z); } if ((bits & Protocol.SU_IDEALPITCH) != 0) { msg.WriteChar((int)ent.v.idealpitch); } if ((bits & Protocol.SU_PUNCH1) != 0) { msg.WriteChar((int)ent.v.punchangle.x); } if ((bits & Protocol.SU_VELOCITY1) != 0) { msg.WriteChar((int)(ent.v.velocity.x / 16)); } if ((bits & Protocol.SU_PUNCH2) != 0) { msg.WriteChar((int)ent.v.punchangle.y); } if ((bits & Protocol.SU_VELOCITY2) != 0) { msg.WriteChar((int)(ent.v.velocity.y / 16)); } if ((bits & Protocol.SU_PUNCH3) != 0) { msg.WriteChar((int)ent.v.punchangle.z); } if ((bits & Protocol.SU_VELOCITY3) != 0) { msg.WriteChar((int)(ent.v.velocity.z / 16)); } // always sent msg.WriteLong(items); if ((bits & Protocol.SU_WEAPONFRAME) != 0) { msg.WriteByte((int)ent.v.weaponframe); } if ((bits & Protocol.SU_ARMOR) != 0) { msg.WriteByte((int)ent.v.armorvalue); } if ((bits & Protocol.SU_WEAPON) != 0) { msg.WriteByte(ModelIndex(Progs.GetString(ent.v.weaponmodel))); } msg.WriteShort((int)ent.v.health); msg.WriteByte((int)ent.v.currentammo); msg.WriteByte((int)ent.v.ammo_shells); msg.WriteByte((int)ent.v.ammo_nails); msg.WriteByte((int)ent.v.ammo_rockets); msg.WriteByte((int)ent.v.ammo_cells); if (Common.GameKind == GameKind.StandardQuake) { msg.WriteByte((int)ent.v.weapon); } else { for (int i = 0; i < 32; i++) { if ((((int)ent.v.weapon) & (1 << i)) != 0) { msg.WriteByte(i); break; } } } }