Example #1
0
 public void insertOrderDeathInOrder(DVector DV, long lastStart, String msg, Tick tock) {
   if (DV.size() > 0)
     for (int i = 0; i < DV.size(); i++) {
       if (((Long) DV.elementAt(i, 1)).longValue() > lastStart) {
         DV.insertElementAt(i, Long.valueOf(lastStart), msg, tock);
         return;
       }
     }
   DV.addElement(Long.valueOf(lastStart), msg, tock);
 }
Example #2
0
 private Room getSortedRoom(int x, int y) {
   if (rooms.size() == 0) return null;
   synchronized (rooms) {
     int pos = properRoomIndex(x, y);
     if ((((Integer) rooms.elementAt(pos, 2)).intValue() == x)
         && (((Integer) rooms.elementAt(pos, 3)).intValue() == y))
       return (Room) rooms.elementAt(pos, 1);
   }
   return null;
 }
Example #3
0
 public int getGridChildY(Room loc) {
   try {
     return ((Integer) rooms.elementAt(rooms.indexOf(loc), 3)).intValue();
   } catch (Exception x) {
   }
   DVector rs = rooms.copyOf();
   for (int i = 0; i < rs.size(); i++)
     if (rs.elementAt(i, 1) == loc) return ((Integer) rs.elementAt(i, 3)).intValue();
   return -1;
 }
Example #4
0
 private void addSortedRoom(Room R, int x, int y) {
   if ((x < 0) || (y < 0) || (y >= yGridSize()) || (x >= xGridSize()) || (R == null)) return;
   synchronized (rooms) {
     long total = ((long) x << 31) + y;
     int pos = properRoomIndex(x, y);
     if (pos >= rooms.size()) {
       rooms.addElement(R, Integer.valueOf(x), Integer.valueOf(y));
       return;
     }
     long comptotal =
         (((Integer) rooms.elementAt(pos, 2)).longValue() << 31)
             + ((Integer) rooms.elementAt(pos, 3)).longValue();
     int comp = comptotal > total ? 1 : (comptotal == total) ? 0 : -1;
     if (comp == 0) return;
     if (comp > 0) rooms.insertElementAt(pos, R, Integer.valueOf(x), Integer.valueOf(y));
     else if (pos == rooms.size() - 1) rooms.addElement(R, Integer.valueOf(x), Integer.valueOf(y));
     else rooms.insertElementAt(pos + 1, R, Integer.valueOf(x), Integer.valueOf(y));
   }
 }
Example #5
0
 public void confirmWearability(MOB mob) {
   if (mob == null) return;
   Race R = mob.charStats().getMyRace();
   DVector reWearSet = new DVector(2);
   Item item = null;
   for (int i = 0; i < mob.inventorySize(); i++) {
     item = mob.fetchInventory(i);
     if ((item != null) && (!item.amWearingAt(Wearable.IN_INVENTORY))) {
       Long oldCode = Long.valueOf(item.rawWornCode());
       item.unWear();
       if (reWearSet.size() == 0) reWearSet.addElement(item, oldCode);
       else {
         short layer = (item instanceof Armor) ? ((Armor) item).getClothingLayer() : 0;
         int d = 0;
         for (; d < reWearSet.size(); d++)
           if (reWearSet.elementAt(d, 1) instanceof Armor) {
             if (((Armor) reWearSet.elementAt(d, 1)).getClothingLayer() > layer) break;
           } else if (0 > layer) break;
         if (d >= reWearSet.size()) reWearSet.addElement(item, oldCode);
         else reWearSet.insertElementAt(d, item, oldCode);
       }
     }
   }
   for (int r = 0; r < reWearSet.size(); r++) {
     item = (Item) reWearSet.elementAt(r, 1);
     long oldCode = ((Long) reWearSet.elementAt(r, 2)).longValue();
     int msgCode = CMMsg.MSG_WEAR;
     if ((oldCode & Wearable.WORN_WIELD) > 0) msgCode = CMMsg.MSG_WIELD;
     else if ((oldCode & Wearable.WORN_HELD) > 0) msgCode = CMMsg.MSG_HOLD;
     CMMsg msg =
         CMClass.getMsg(
             mob, item, null, CMMsg.NO_EFFECT, null, msgCode, null, CMMsg.NO_EFFECT, null);
     if ((R.okMessage(mob, msg))
         && (item.okMessage(item, msg))
         && ((mob.charStats().getWearableRestrictionsBitmap() & oldCode) == 0)
         && (item.canWear(mob, oldCode))) item.wearAt(oldCode);
   }
   // why wasn't that here before?
   mob.recoverEnvStats();
   mob.recoverCharStats();
   mob.recoverMaxState();
 }
Example #6
0
 public void clearGrid(Room bringBackHere) {
   try {
     DVector myRooms = rooms.copyOf();
     for (int r = 0; r < myRooms.size(); r++) {
       Room room = (Room) myRooms.elementAt(r, 1);
       CMLib.map().emptyRoom(room, bringBackHere);
     }
     while (myRooms.size() > 0) {
       Room room = (Room) myRooms.elementAt(0, 1);
       room.destroy();
       myRooms.removeElementAt(0);
     }
     try {
       rooms.clear();
     } catch (Exception e) {
     }
   } catch (Exception e) {
     Log.debugOut("StdThinGrid", e);
   }
 }
Example #7
0
 public void destroy() {
   super.destroy();
   Room R = null;
   for (int i = rooms.size() - 1; i >= 0; i--) {
     R = (Room) rooms.elementAt(i, 1);
     if (R != null) R.destroy();
   }
   rooms.clear();
   descriptions = new Vector(1);
   displayTexts = new Vector(1);
   gridexits = new Vector(1);
 }
Example #8
0
 public boolean isMyGridChild(Room loc) {
   if (loc == null) return false;
   if (loc.getGridParent() == this) return true;
   if (loc.getGridParent() != null) return false;
   try {
     return rooms.contains(loc);
   } catch (Exception e) {
   } // optimization
   DVector myRooms = rooms.copyOf();
   for (int i = 0; i < myRooms.size(); i++) if (loc == myRooms.elementAt(i, 1)) return true;
   return false;
 }
Example #9
0
 private int properRoomIndex(int x, int y) {
   if (rooms.size() == 0) return 0;
   synchronized (rooms) {
     int start = 0;
     int end = rooms.size() - 1;
     int comp = 0;
     long total = ((long) x << 31) + y;
     long comptotal = 0;
     int mid = 0;
     while (start <= end) {
       mid = (end + start) / 2;
       comptotal =
           (((Integer) rooms.elementAt(mid, 2)).longValue() << 31)
               + ((Integer) rooms.elementAt(mid, 3)).longValue();
       comp = comptotal > total ? 1 : (comptotal == total) ? 0 : -1;
       if (comp == 0) return mid;
       else if (comp > 0) end = mid - 1;
       else start = mid + 1;
     }
     if (end < 0) return 0;
     if (start >= rooms.size()) return rooms.size() - 1;
     return mid;
   }
 }
Example #10
0
 public void executeMsg(Environmental myHost, CMMsg msg) {
   if ((msg.targetMinor() == CMMsg.TYP_EXPIRE) && (msg.target() instanceof Room)) {
     Room R = (Room) msg.target();
     if (R.getGridParent() == this) {
       if ((roomID().length() > 0) && (getArea() != null))
         getArea().delProperRoomnumber(getGridChildCode(R));
       DVector thisGridRooms = rooms;
       thisGridRooms.removeElement(R);
       Room R2 = null;
       for (int r = thisGridRooms.size() - 1; r >= 0; r--) {
         R2 = (Room) thisGridRooms.elementAt(r, 1);
         for (int d = Directions.NUM_DIRECTIONS() - 1; d >= 0; d--)
           if (R2.rawDoors()[d] == R) {
             R2.rawDoors()[d] = null;
             R2.setRawExit(d, null);
           }
       }
     }
   }
   super.executeMsg(myHost, msg);
 }
Example #11
0
 public boolean tick(Tickable ticking, int tickID) {
   if (!super.tick(ticking, tickID)) return false;
   if (CMath.bset(flags(), Area.FLAG_INSTANCE_CHILD)) return true;
   if ((--childCheckDown) <= 0) {
     childCheckDown = CHILD_CHECK_INTERVAL;
     synchronized (children) {
       for (int i = children.size() - 1; i >= 0; i--) {
         StdThinInstance childA = (StdThinInstance) children.elementAt(i, 2);
         if (childA.getAreaState() > Area.STATE_ACTIVE) {
           Vector V = (Vector) children.elementAt(i, 3);
           boolean anyInside = false;
           for (int v = 0; v < V.size(); v++) {
             MOB M = (MOB) V.elementAt(v);
             if (CMLib.flags().isInTheGame(M, true)
                 && (M.location() != null)
                 && (M.location().getArea() == childA)) anyInside = true;
           }
           if (!anyInside) {
             children.removeElementsAt(i);
             for (int v = 0; v < V.size(); v++) {
               MOB M = (MOB) V.elementAt(v);
               if ((M.location() != null) && (M.location().getArea() == this))
                 M.setLocation(M.getStartRoom());
             }
             MOB mob = CMClass.sampleMOB();
             for (Enumeration e = childA.getProperMap(); e.hasMoreElements(); ) {
               Room R = (Room) e.nextElement();
               R.executeMsg(mob, CMClass.getMsg(mob, R, null, CMMsg.MSG_EXPIRE, null));
             }
             CMLib.map().delArea(childA);
             childA.destroy();
           }
         }
       }
     }
   }
   return true;
 }
Example #12
0
 public String getGridChildCode(Room loc) {
   if (roomID().length() == 0) return "";
   try {
     int x = rooms.indexOf(loc);
     return roomID()
         + "#("
         + ((Integer) rooms.elementAt(x, 2)).intValue()
         + ","
         + ((Integer) rooms.elementAt(x, 3)).intValue()
         + ")";
   } catch (Exception x) {
   }
   DVector rs = rooms.copyOf();
   for (int i = 0; i < rs.size(); i++)
     if (rs.elementAt(i, 1) == loc)
       return roomID()
           + "#("
           + ((Integer) rs.elementAt(i, 2)).intValue()
           + ","
           + ((Integer) rs.elementAt(i, 3)).intValue()
           + ")";
   return "";
 }
Example #13
0
 public Item isRuinedLoot(DVector policies, Item I) {
   if (I == null) return null;
   if ((CMath.bset(I.envStats().disposition(), EnvStats.IS_UNSAVABLE))
       || (CMath.bset(I.envStats().sensesMask(), EnvStats.SENSE_ITEMNORUIN))
       || (I instanceof Coins)) return I;
   if (I.name().toLowerCase().indexOf("ruined ") >= 0) return I;
   for (int d = 0; d < policies.size(); d++) {
     if ((((Vector) policies.elementAt(d, 3)).size() > 0)
         && (!CMLib.masking().maskCheck((Vector) policies.elementAt(d, 3), I, true))) continue;
     if (CMLib.dice().rollPercentage() > ((Integer) policies.elementAt(d, 1)).intValue()) continue;
     int flags = ((Integer) policies.elementAt(d, 2)).intValue();
     if (CMath.bset(flags, CMMiscUtils.LOOTFLAG_WORN) && I.amWearingAt(Wearable.IN_INVENTORY))
       continue;
     else if (CMath.bset(flags, CMMiscUtils.LOOTFLAG_UNWORN)
         && (!I.amWearingAt(Wearable.IN_INVENTORY))) continue;
     if (CMath.bset(flags, CMMiscUtils.LOOTFLAG_LOSS)) return null;
     Item I2 = CMClass.getItem("GenItem");
     I2.baseEnvStats().setWeight(I.baseEnvStats().weight());
     I2.setName(I.Name());
     I2.setDisplayText(I.displayText());
     I2.setDescription(I2.description());
     I2.recoverEnvStats();
     I2.setMaterial(I.material());
     String ruinDescAdder = null;
     switch (I2.material() & RawMaterial.MATERIAL_MASK) {
       case RawMaterial.MATERIAL_LEATHER:
       case RawMaterial.MATERIAL_CLOTH:
       case RawMaterial.MATERIAL_VEGETATION:
       case RawMaterial.MATERIAL_FLESH:
       case RawMaterial.MATERIAL_PAPER:
         ruinDescAdder =
             CMStrings.capitalizeFirstLetter(I2.name()) + " is torn and ruined beyond repair.";
         break;
       case RawMaterial.MATERIAL_METAL:
       case RawMaterial.MATERIAL_MITHRIL:
       case RawMaterial.MATERIAL_WOODEN:
         ruinDescAdder =
             CMStrings.capitalizeFirstLetter(I2.name()) + " is battered and ruined beyond repair.";
         break;
       case RawMaterial.MATERIAL_GLASS:
         ruinDescAdder =
             CMStrings.capitalizeFirstLetter(I2.name())
                 + " is shattered and ruined beyond repair.";
         break;
       case RawMaterial.MATERIAL_ROCK:
       case RawMaterial.MATERIAL_PRECIOUS:
       case RawMaterial.MATERIAL_PLASTIC:
         ruinDescAdder =
             CMStrings.capitalizeFirstLetter(I2.name()) + " is cracked and ruined beyond repair.";
         break;
       case RawMaterial.MATERIAL_UNKNOWN:
       case RawMaterial.MATERIAL_ENERGY:
       case RawMaterial.MATERIAL_LIQUID:
       default:
         ruinDescAdder = CMStrings.capitalizeFirstLetter(I2.name()) + " is ruined beyond repair.";
         break;
     }
     I2.setDescription(CMStrings.endWithAPeriod(I2.description()) + " " + ruinDescAdder);
     String oldName = I2.Name();
     I2.setName(CMLib.english().insertUnColoredAdjective(I2.Name(), "ruined"));
     int x = I2.displayText().toUpperCase().indexOf(oldName.toUpperCase());
     I2.setBaseValue(0);
     if (x >= 0)
       I2.setDisplayText(
           I2.displayText().substring(0, x)
               + I2.Name()
               + I2.displayText().substring(x + oldName.length()));
     return I2;
   }
   return I;
 }
Example #14
0
  public void checkHealth() {
    long lastDateTime = System.currentTimeMillis() - (5 * TimeManager.MILI_MINUTE);
    long longerDateTime = System.currentTimeMillis() - (120 * TimeManager.MILI_MINUTE);
    thread.status("checking");

    thread.status("checking tick groups.");
    DVector orderedDeaths = new DVector(3);
    try {
      Tick almostTock = null;
      for (Iterator<Tick> e = tickGroups(); e.hasNext(); ) {
        almostTock = e.next();
        if ((almostTock.awake) && (almostTock.lastStop < lastDateTime)) {
          TockClient client = almostTock.lastClient;
          if (client == null)
            insertOrderDeathInOrder(
                orderedDeaths,
                0,
                "LOCKED GROUP " + almostTock.getCounter() + "! No further information.",
                almostTock);
          else if ((!CMath.bset(client.tickID, Tickable.TICKID_LONGERMASK))
              || (almostTock.lastStop < longerDateTime)) {
            if (client.clientObject == null)
              insertOrderDeathInOrder(
                  orderedDeaths,
                  0,
                  "LOCKED GROUP "
                      + almostTock.getCounter()
                      + ": NULL @"
                      + CMLib.time().date2String(client.lastStart)
                      + ", tickID "
                      + client.tickID,
                  almostTock);
            else {
              StringBuffer str = null;
              Tickable obj = client.clientObject;
              long code = client.clientObject.getTickStatus();
              String codeWord = CMLib.threads().getTickStatusSummary(client.clientObject);
              String msg = null;
              if (obj instanceof Environmental)
                str =
                    new StringBuffer(
                        "LOCKED GROUP "
                            + almostTock.getCounter()
                            + " : "
                            + obj.name()
                            + " ("
                            + ((Environmental) obj).ID()
                            + ") @"
                            + CMLib.time().date2String(client.lastStart)
                            + ", status("
                            + code
                            + " ("
                            + codeWord
                            + "), tickID "
                            + client.tickID);
              else
                str =
                    new StringBuffer(
                        "LOCKED GROUP "
                            + almostTock.getCounter()
                            + ": "
                            + obj.name()
                            + ", status("
                            + code
                            + " ("
                            + codeWord
                            + ") @"
                            + CMLib.time().date2String(client.lastStart)
                            + ", tickID "
                            + client.tickID);

              if ((obj instanceof MOB) && (((MOB) obj).location() != null))
                msg = str.toString() + " in " + ((MOB) obj).location().roomID();
              else if ((obj instanceof Item)
                  && (((Item) obj).owner() != null)
                  && (((Item) obj).owner() instanceof Room))
                msg = str.toString() + " in " + ((Room) ((Item) obj).owner()).roomID();
              else if ((obj instanceof Item)
                  && (((Item) obj).owner() != null)
                  && (((Item) obj).owner() instanceof MOB))
                msg = str.toString() + " owned by " + ((MOB) ((Item) obj).owner()).name();
              else if (obj instanceof Room) msg = str.toString() + " is " + ((Room) obj).roomID();
              else msg = str.toString();
              insertOrderDeathInOrder(orderedDeaths, client.lastStart, msg, almostTock);
            }
          }
          // no isDEBUGGING check -- just always let her rip.
          thread.debugDumpStack(almostTock);
        }
      }
    } catch (java.util.NoSuchElementException e) {
    }
    for (int i = 0; i < orderedDeaths.size(); i++)
      Log.errOut(thread.getName(), (String) orderedDeaths.elementAt(i, 2));

    thread.status("killing tick groups.");
    for (int x = 0; x < orderedDeaths.size(); x++) {
      Tick almostTock = (Tick) orderedDeaths.elementAt(x, 3);
      Vector objs = new Vector();
      try {
        for (Iterator e = almostTock.tickers(); e.hasNext(); ) objs.addElement(e.next());
      } catch (NoSuchElementException e) {
      }
      almostTock.shutdown();
      if (CMLib.threads() instanceof ServiceEngine)
        ((ServiceEngine) CMLib.threads()).delTickGroup(almostTock);
      for (int i = 0; i < objs.size(); i++) {
        TockClient c = (TockClient) objs.elementAt(i);
        CMLib.threads().startTickDown(c.clientObject, c.tickID, c.reTickDown);
      }
    }

    thread.status("Checking mud threads");
    for (int m = 0; m < CMLib.hosts().size(); m++) {
      Vector badThreads = ((MudHost) CMLib.hosts().elementAt(m)).getOverdueThreads();
      if (badThreads.size() > 0) {
        for (int b = 0; b < badThreads.size(); b++) {
          Thread T = (Thread) badThreads.elementAt(b);
          String threadName = T.getName();
          if (T instanceof Tickable)
            threadName =
                ((Tickable) T).name()
                    + " ("
                    + ((Tickable) T).ID()
                    + "): "
                    + ((Tickable) T).getTickStatus();
          thread.status("Killing " + threadName);
          Log.errOut("Killing stray thread: " + threadName);
          CMLib.killThread(T, 100, 1);
        }
      }
    }

    thread.status("Done checking threads");
  }
Example #15
0
 public boolean okMessage(Environmental myHost, CMMsg msg) {
   if (!super.okMessage(myHost, msg)) return false;
   if (CMath.bset(flags(), Area.FLAG_INSTANCE_CHILD)) return true;
   setAreaState(Area.STATE_PASSIVE);
   if ((msg.sourceMinor() == CMMsg.TYP_ENTER)
       && (msg.target() instanceof Room)
       && (CMath.bset(flags(), Area.FLAG_INSTANCE_PARENT))
       && (isRoom((Room) msg.target()))
       && (!CMSecurity.isAllowed(msg.source(), (Room) msg.target(), "CMDAREAS"))
       && (((msg.source().getStartRoom() == null)
           || (msg.source().getStartRoom().getArea() != this)))) {
     synchronized (children) {
       int myDex = -1;
       for (int i = 0; i < children.size(); i++) {
         Vector V = (Vector) children.elementAt(i, 1);
         if (V.contains(msg.source())) {
           myDex = i;
           break;
         }
       }
       HashSet grp = msg.source().getGroupMembers(new HashSet());
       for (int i = 0; i < children.size(); i++) {
         if (i != myDex) {
           Vector V = (Vector) children.elementAt(i, 1);
           for (int v = V.size() - 1; v >= 0; v--) {
             MOB M = (MOB) V.elementAt(v);
             if (grp.contains(M)) {
               if (myDex < 0) {
                 myDex = i;
                 break;
               } else if ((CMLib.flags().isInTheGame(M, true))
                   && (M.location().getArea() != (Area) children.elementAt(i, 2))) {
                 V.remove(M);
                 ((Vector) children.elementAt(myDex, 1)).addElement(M);
               }
             }
           }
         }
       }
       StdThinInstance redirectA = null;
       if (myDex < 0) {
         StdThinInstance newA = (StdThinInstance) this.copyOf();
         newA.properRooms = new Vector(1);
         newA.properRoomIDSet = null;
         newA.metroRoomIDSet = null;
         newA.blurbFlags = new Vector(1);
         newA.setName((++instanceCounter) + "_" + Name());
         newA.flags |= Area.FLAG_INSTANCE_CHILD;
         for (Enumeration e = getProperRoomnumbers().getRoomIDs(); e.hasMoreElements(); )
           newA.addProperRoomnumber(newA.convertToMyArea((String) e.nextElement()));
         redirectA = newA;
         CMLib.map().addArea(newA);
         newA.setAreaState(Area.STATE_ACTIVE); // starts ticking
         children.addElement(CMParms.makeVector(msg.source()), redirectA);
       } else redirectA = (StdThinInstance) children.elementAt(myDex, 2);
       Room R =
           redirectA.getRoom(
               redirectA.convertToMyArea(CMLib.map().getExtendedRoomID((Room) msg.target())));
       if (R != null) msg.setTarget(R);
     }
   }
   return true;
 }