示例#1
0
void Square::putCreature(Creature* c) {
  CHECK(canEnter(c));
  creature = c;
  onEnter(c);
}
示例#2
0
bool Creature::canFleeToExit(const Exit *exit, bool skipScary, bool blinking) {
    Player  *pThis = getAsPlayer();

    // flags both players and mobs have to obey
    if(!canEnter(exit, false, blinking) ||

        exit->flagIsSet(X_SECRET) ||
        exit->isConcealed(this) ||
        exit->flagIsSet(X_DESCRIPTION_ONLY) ||

        exit->flagIsSet(X_NO_FLEE) ||

        exit->flagIsSet(X_TO_STORAGE_ROOM) ||
        exit->flagIsSet(X_TO_BOUND_ROOM) ||
        exit->flagIsSet(X_TOLL_TO_PASS) ||
        exit->flagIsSet(X_WATCHER_UNLOCK)
    )
        return(false);


    if(pThis) {

        if(
            ((  getRoomParent()->flagIsSet(R_NO_FLEE) ||
                getRoomParent()->flagIsSet(R_LIMBO)
            ) && inCombat()) ||
            (exit->flagIsSet(X_DIFFICULT_CLIMB) && !isEffected("levitate")) ||
            (
                (
                    exit->flagIsSet(X_NEEDS_CLIMBING_GEAR) ||
                    exit->flagIsSet(X_CLIMBING_GEAR_TO_REPEL) ||
                    exit->flagIsSet(X_DIFFICULT_CLIMB)
                ) &&
                !isEffected("levitate")
            )
        ) return(false);

        int chance=0, *scary;

        // should we skip checking for scary exits?
        skipScary = skipScary || fd == -1 || exit->target.mapmarker.getArea() || isEffected("fear");

        // are they scared of going in that direction
        if(!skipScary && pThis->scared_of) {
            scary = pThis->scared_of;
            while(*scary) {
                if(exit->target.room.id && *scary == exit->target.room.id) {
                    // oldPrint(fd, "Scared of going %s^x!\n", exit->getCName());

                    // there is a chance we will flee to this exit anyway
                    chance = 65 + bonus((int) dexterity.getCur()) * 5;

                    if(getRoomParent()->flagIsSet(R_DIFFICULT_TO_MOVE) || getRoomParent()->flagIsSet(R_DIFFICULT_FLEE))
                        chance /=2;

                    if(mrand(1,100) < chance)
                        return(false);

                    // success; means that the player is now scared of this room
                    if(inUniqueRoom() && fd > -1) {
                        scary = pThis->scared_of;
                        {
                            int roomNum = getUniqueRoomParent()->info.id;
                            if(scary) {
                                int size = 0;
                                while(*scary) {
                                    size++;
                                    if(*scary == roomNum)
                                        break;
                                    scary++;
                                }
                                if(!*scary) {
                                    // LEAK: Next line reported to be leaky: 10 count
                                    pThis->scared_of = (int *) realloc(pThis->scared_of, (size + 2) * sizeof(int));
                                    (pThis->scared_of)[size] = roomNum;
                                    (pThis->scared_of)[size + 1] = 0;
                                }
                            } else {
                                // LEAK: Next line reported to be leaky: 10 count
                                pThis->scared_of = (int *) malloc(sizeof(int) * 2);
                                (pThis->scared_of)[0] = roomNum;
                                (pThis->scared_of)[1] = 0;
                            }
                        }
                    }
                    return(true);
                }
                scary++;
            }
        }

    }

    return(true);
}