public static void SP_trigger_key(Entity self) {
    if (GameBase.st.item == null) {
      ServerGame.PF_dprintf("no key item for trigger_key at " + Lib.vtos(self.s.origin) + "\n");
      return;
    }
    self.item = GameItems.FindItemByClassname(GameBase.st.item);

    if (null == self.item) {
      ServerGame.PF_dprintf(
          "item "
              + GameBase.st.item
              + " not found for trigger_key at "
              + Lib.vtos(self.s.origin)
              + "\n");
      return;
    }

    if (self.target == null) {
      ServerGame.PF_dprintf(self.classname + " at " + Lib.vtos(self.s.origin) + " has no target\n");
      return;
    }

    ServerInit.SV_SoundIndex("misc/keytry.wav");
    ServerInit.SV_SoundIndex("misc/keyuse.wav");

    self.use = trigger_key_use;
  }
  public static void SP_trigger_gravity(Entity self) {
    if (GameBase.st.gravity == null) {
      ServerGame.PF_dprintf(
          "trigger_gravity without gravity set at " + Lib.vtos(self.s.origin) + "\n");
      GameUtil.G_FreeEdict(self);
      return;
    }

    InitTrigger(self);
    self.gravity = Lib.atoi(GameBase.st.gravity);
    self.touch = trigger_gravity_touch;
  }
  /**
   * QUAKED trigger_once (.5 .5 .5) ? x x TRIGGERED Triggers once, then removes itself. You must set
   * the key "target" to the name of another object in the level that has a matching "targetname".
   *
   * <p>If TRIGGERED, this trigger must be triggered before it is live.
   *
   * <p>sounds 1) secret 2) beep beep 3) large switch 4)
   *
   * <p>"message" string to be displayed when triggered
   */
  public static void SP_trigger_once(Entity ent) {
    // make old maps work because I messed up on flag assignments here
    // triggered was on bit 1 when it should have been on bit 4
    if ((ent.spawnflags & 1) != 0) {
      float[] v = {0, 0, 0};

      Math3D.VectorMA(ent.mins, 0.5f, ent.size, v);
      ent.spawnflags &= ~1;
      ent.spawnflags |= 4;
      ServerGame.PF_dprintf(
          "fixed TRIGGERED flag on " + ent.classname + " at " + Lib.vtos(v) + "\n");
    }

    ent.wait = -1;
    SP_trigger_multiple(ent);
  }
        public void touch(Entity self, Entity other, Plane plane, Surface surf) {
          if (Lib.strcmp(other.classname, "grenade") == 0) {
            Math3D.VectorScale(self.movedir, self.speed * 10, other.velocity);
          } else if (other.health > 0) {
            Math3D.VectorScale(self.movedir, self.speed * 10, other.velocity);

            if (other.client != null) {
              // don't take falling damage immediately from this
              Math3D.VectorCopy(other.velocity, other.client.oldvelocity);
              if (other.fly_sound_debounce_time < GameBase.level.time) {
                other.fly_sound_debounce_time = GameBase.level.time + 1.5f;
                ServerGame.PF_StartSound(
                    other,
                    Constants.CHAN_AUTO,
                    windsound,
                    (float) 1,
                    (float) Constants.ATTN_NORM,
                    (float) 0);
              }
            }
          }
          if ((self.spawnflags & PUSH_ONCE) != 0) GameUtil.G_FreeEdict(self);
        }
 protected void init() {
   GlState.r_world_matrix = Lib.newFloatBuffer(16);
   Images.init();
   Mesh.init();
   Models.init();
 }
        public void use(Entity self, Entity other, Entity activator) {
          int index;

          if (self.item == null) return;
          if (activator.client == null) return;

          index = GameItems.ITEM_INDEX(self.item);
          if (activator.client.pers.inventory[index] == 0) {
            if (GameBase.level.time < self.touch_debounce_time) return;
            self.touch_debounce_time = GameBase.level.time + 5.0f;
            ServerGame.PF_centerprintf(activator, "You need the " + self.item.pickup_name);
            ServerGame.PF_StartSound(
                activator,
                Constants.CHAN_AUTO,
                ServerInit.SV_SoundIndex("misc/keytry.wav"),
                (float) 1,
                (float) Constants.ATTN_NORM,
                (float) 0);
            return;
          }

          ServerGame.PF_StartSound(
              activator,
              Constants.CHAN_AUTO,
              ServerInit.SV_SoundIndex("misc/keyuse.wav"),
              (float) 1,
              (float) Constants.ATTN_NORM,
              (float) 0);
          if (GameBase.coop.value != 0) {
            int player;
            Entity ent;

            if (Lib.strcmp(self.item.classname, "key_power_cube") == 0) {
              int cube;

              for (cube = 0; cube < 8; cube++)
                if ((activator.client.pers.power_cubes & (1 << cube)) != 0) break;
              for (player = 1; player <= GameBase.game.maxclients; player++) {
                ent = GameBase.g_edicts[player];
                if (!ent.inuse) continue;
                if (null == ent.client) continue;
                if ((ent.client.pers.power_cubes & (1 << cube)) != 0) {
                  ent.client.pers.inventory[index]--;
                  ent.client.pers.power_cubes &= ~(1 << cube);
                }
              }
            } else {
              for (player = 1; player <= GameBase.game.maxclients; player++) {
                ent = GameBase.g_edicts[player];
                if (!ent.inuse) continue;
                if (ent.client == null) continue;
                ent.client.pers.inventory[index] = 0;
              }
            }
          } else {
            activator.client.pers.inventory[index]--;
          }

          GameUtil.G_UseTargets(self, activator);

          self.use = null;
        }
Exemple #7
0
  /*
   * ================ SCR_ExecuteLayoutString
   *
   * ================
   */
  static void ExecuteLayoutString(String s) {
    int x, y;
    int value;
    String token;
    int width;
    int index;
    ClientInfo ci;

    if (cls.state != ca_active || !cl.refresh_prepped) return;

    //		if (!s[0])
    if (s == null || s.length() == 0) return;

    x = 0;
    y = 0;
    width = 3;

    Com.ParseHelp ph = new Com.ParseHelp(s);

    while (!ph.isEof()) {
      token = Com.Parse(ph);
      if (token.equals("xl")) {
        token = Com.Parse(ph);
        x = Lib.atoi(token);
        continue;
      }
      if (token.equals("xr")) {
        token = Com.Parse(ph);
        x = viddef.width + Lib.atoi(token);
        continue;
      }
      if (token.equals("xv")) {
        token = Com.Parse(ph);
        x = viddef.width / 2 - 160 + Lib.atoi(token);
        continue;
      }

      if (token.equals("yt")) {
        token = Com.Parse(ph);
        y = Lib.atoi(token);
        continue;
      }
      if (token.equals("yb")) {
        token = Com.Parse(ph);
        y = viddef.height + Lib.atoi(token);
        continue;
      }
      if (token.equals("yv")) {
        token = Com.Parse(ph);
        y = viddef.height / 2 - 120 + Lib.atoi(token);
        continue;
      }

      if (token.equals("pic")) { // draw a pic from a stat number
        token = Com.Parse(ph);
        value = cl.frame.playerstate.stats[Lib.atoi(token)];
        if (value >= MAX_IMAGES) Com.Error(ERR_DROP, "Pic >= MAX_IMAGES");
        if (cl.configstrings[CS_IMAGES + value] != null) {
          AddDirtyPoint(x, y);
          AddDirtyPoint(x + 23, y + 23);
          re.DrawPic(x, y, cl.configstrings[CS_IMAGES + value]);
        }
        continue;
      }

      if (token.equals("client")) { // draw a deathmatch client block
        int score, ping, time;

        token = Com.Parse(ph);
        x = viddef.width / 2 - 160 + Lib.atoi(token);
        token = Com.Parse(ph);
        y = viddef.height / 2 - 120 + Lib.atoi(token);
        AddDirtyPoint(x, y);
        AddDirtyPoint(x + 159, y + 31);

        token = Com.Parse(ph);
        value = Lib.atoi(token);
        if (value >= MAX_CLIENTS || value < 0) Com.Error(ERR_DROP, "client >= MAX_CLIENTS");
        ci = cl.clientinfo[value];

        token = Com.Parse(ph);
        score = Lib.atoi(token);

        token = Com.Parse(ph);
        ping = Lib.atoi(token);

        token = Com.Parse(ph);
        time = Lib.atoi(token);

        Globals.re.DrawString(x + 32, y, ci.name, true);
        Globals.re.DrawString(x + 32, y + 8, "Score: ");
        Globals.re.DrawString(x + 32 + 7 * 8, y + 8, "" + score, true);
        Globals.re.DrawString(x + 32, y + 16, "Ping:  " + ping);
        Globals.re.DrawString(x + 32, y + 24, "Time:  " + time);

        if (ci.icon == null) ci = cl.baseclientinfo;
        re.DrawPic(x, y, ci.iconname);
        continue;
      }

      if (token.equals("ctf")) { // draw a ctf client block
        int score, ping;

        token = Com.Parse(ph);
        x = viddef.width / 2 - 160 + Lib.atoi(token);
        token = Com.Parse(ph);
        y = viddef.height / 2 - 120 + Lib.atoi(token);
        AddDirtyPoint(x, y);
        AddDirtyPoint(x + 159, y + 31);

        token = Com.Parse(ph);
        value = Lib.atoi(token);
        if (value >= MAX_CLIENTS || value < 0) Com.Error(ERR_DROP, "client >= MAX_CLIENTS");
        ci = cl.clientinfo[value];

        token = Com.Parse(ph);
        score = Lib.atoi(token);

        token = Com.Parse(ph);
        ping = Lib.atoi(token);
        if (ping > 999) ping = 999;

        // sprintf(block, "%3d %3d %-12.12s", score, ping, ci->name);
        String block =
            Com.sprintf("%3d %3d %-12.12s", new Vargs(3).add(score).add(ping).add(ci.name));

        if (value == cl.playernum) Globals.re.DrawString(x, y, block, true);
        else Globals.re.DrawString(x, y, block);
        continue;
      }

      if (token.equals("picn")) { // draw a pic from a name
        token = Com.Parse(ph);
        AddDirtyPoint(x, y);
        AddDirtyPoint(x + 23, y + 23);
        re.DrawPic(x, y, token);
        continue;
      }

      if (token.equals("num")) { // draw a number
        token = Com.Parse(ph);
        width = Lib.atoi(token);
        token = Com.Parse(ph);
        value = cl.frame.playerstate.stats[Lib.atoi(token)];
        DrawField(x, y, 0, width, value);
        continue;
      }

      if (token.equals("hnum")) { // health number
        int color;

        width = 3;
        value = cl.frame.playerstate.stats[STAT_HEALTH];
        if (value > 25) color = 0; // green
        else if (value > 0) color = (cl.frame.serverframe >> 2) & 1; // flash
        else color = 1;

        if ((cl.frame.playerstate.stats[STAT_FLASHES] & 1) != 0) re.DrawPic(x, y, "field_3");

        DrawField(x, y, color, width, value);
        continue;
      }

      if (token.equals("anum")) { // ammo number
        int color;

        width = 3;
        value = cl.frame.playerstate.stats[STAT_AMMO];
        if (value > 5) color = 0; // green
        else if (value >= 0) color = (cl.frame.serverframe >> 2) & 1; // flash
        else continue; // negative number = don't show

        if ((cl.frame.playerstate.stats[STAT_FLASHES] & 4) != 0) re.DrawPic(x, y, "field_3");

        DrawField(x, y, color, width, value);
        continue;
      }

      if (token.equals("rnum")) { // armor number
        int color;

        width = 3;
        value = cl.frame.playerstate.stats[STAT_ARMOR];
        if (value < 1) continue;

        color = 0; // green

        if ((cl.frame.playerstate.stats[STAT_FLASHES] & 2) != 0) re.DrawPic(x, y, "field_3");

        DrawField(x, y, color, width, value);
        continue;
      }

      if (token.equals("stat_string")) {
        token = Com.Parse(ph);
        index = Lib.atoi(token);
        if (index < 0 || index >= MAX_CONFIGSTRINGS) Com.Error(ERR_DROP, "Bad stat_string index");
        index = cl.frame.playerstate.stats[index];
        if (index < 0 || index >= MAX_CONFIGSTRINGS) Com.Error(ERR_DROP, "Bad stat_string index");
        Globals.re.DrawString(x, y, cl.configstrings[index]);
        continue;
      }

      if (token.equals("cstring")) {
        token = Com.Parse(ph);
        DrawHUDString(token, x, y, 320, false);
        continue;
      }

      if (token.equals("string")) {
        token = Com.Parse(ph);
        Globals.re.DrawString(x, y, token);
        continue;
      }

      if (token.equals("cstring2")) {
        token = Com.Parse(ph);
        DrawHUDString(token, x, y, 320, true);
        continue;
      }

      if (token.equals("string2")) {
        token = Com.Parse(ph);
        Globals.re.DrawString(x, y, token, true);
        continue;
      }

      if (token.equals("if")) { // draw a number
        token = Com.Parse(ph);
        value = cl.frame.playerstate.stats[Lib.atoi(token)];
        if (value == 0) {
          // skip to endif
          while (!ph.isEof() && !(token = Com.Parse(ph)).equals("endif")) ;
        }
        continue;
      }
    }
  }
 public static void OutOfBandPrint(int net_socket, NetworkAddress adr, String s) {
   Netchan_OutOfBand(net_socket, adr, s.length(), Lib.stringToBytes(s));
 }