Beispiel #1
0
void
shMapLevel::buildTwistyRooms ()
{
    int i = 1000;
    int n = 0;
    int x, y;

    n = buildTwistyCorridor (RNG (mColumns / 3, 2 * mColumns / 3),
                             4, kSouth);
    while (--i and n < 4 * (mRows + mColumns)) {
        do {
            x = RNG (mColumns);
            y = RNG (mRows);
        } while (!TESTSQ (x, y, kFloor));
        n += buildTwistyCorridor (x, y, (shDirection) (2 * RNG (4)));
        if (n > 4 * (mRows + mColumns)) break;
    }


    buildSnuggledRooms ();
//    wallCorridors ();

    n = RNG (1, 6) + RNG (1, 6) + RNG (1, 6) + RNG (1, 6);
    for (i = 0; i < n; i++) {
        do {
            x = RNG (mColumns);
            y = RNG (mRows);
        } while (!TESTSQ (x, y, kFloor)  or
                 isObstacle (x, y));
        putObject (generateObject (), x, y);
    }

}
Beispiel #2
0
void CompilGenerator::generateObjects(const std::vector<ObjectSPtr>& objects)
{
    std::vector<ObjectSPtr>::const_iterator it;
    for (it = objects.begin(); it != objects.end(); ++it)
    {
        if ((*it)->sourceId() != mDocument->mainFile()->sourceId())
			continue;

        generateObject(*it);
    }
}
Beispiel #3
0
/* Returns 1 if succesful and 0 otherwise. */
static int
compileObject (const char *ilkstr, int score, int *weight)
{
    shMenu *pickone = I->newMenu ("select one", 0);
    shObjectVector v;
    char letter = 'a';
    int choices = (score - 5) / 5;
    if (choices <= 0) choices = 1;
    /* Prepare choices and one backup item. */
    for (int i = 0; i < choices + 1; ++i) {
        shObject *obj = NULL;
        if (!ilkstr) { /* Choose fully randomly. */
            do { /* Money is boring.  Floppies are unbalancing.  Do not want. */
                if (obj) delete obj;
                obj = generateObject (Hero.mCLevel);
            } while (obj->isA (kObjMoney) or obj->isA (kFloppyDisk));
        } else { /* Choose from selected category. */
            obj = createObject (ilkstr, 0);
        } /* Should not happen but if it does lets not ruin a good game. */
        if (!obj) {
            debug.log ("Failed to generate \"%s\".", ilkstr);
            I->p ("Suddenly something goes very wrong!");
            return 0;
        } /* Items may be described in varying degrees of accuracy. */
        if ((score >= 15 and RNG (3)) or !RNG (10))
            obj->setAppearanceKnown ();
        if ((score >= 20 and RNG (5)) or !RNG (10))
            obj->setBugginessKnown ();
        if ((score >= 20 and RNG (5)) or !RNG (10))
            obj->setInfectedKnown ();
        if ((score >= 20 and RNG (5)) or !RNG (10))
            obj->setEnhancementKnown ();
        v.add (obj);
        if (i != choices) { /* Hide backup item. */
            if (!RNG (15)) { /* Sometimes give no description at all. */
                pickone->addPtrItem (letter++, "something", obj);
            } else {
                pickone->addPtrItem (letter++, obj->inv (), obj);
            }
        }
    } /* Make your pick. */
    shObject *chosen = NULL;
    int manual_pick = 1;
    if (choices > 1) {
        pickone->getPtrResult ((const void **) &chosen, NULL);
        /* Hero is not satisfied with options? Give backup item. */
        if (!chosen) {
            chosen = v.get (choices);
            manual_pick = 0;
        }
    } else {
        chosen = v.get (0);
    } /* Discard rest. */
    delete pickone;
    for (int i = 0; i < choices + 1; ++i) {
        shObject *obj = v.get (i);
        if (obj != chosen) delete obj;
    } /* Check weight. */
    if (chosen->myIlk ()->mWeight > *weight) {
        if (choices > 1) {
            I->p ("There is not enough particles left to assemble %s.",
                manual_pick ? chosen->inv () : "last item");
        }
        delete chosen;
        return 0;
    } else {
        if (!Hero.isBlind ()) chosen->setAppearanceKnown ();
        Level->putObject (chosen, Hero.mX, Hero.mY);
        *weight -= chosen->myIlk ()->mWeight;
    }
    return 1;
}
Beispiel #4
0
bool CompilGenerator::generate()
{
    generateObject(mDocument->mainFile());
    generateObjects(mDocument->objects());
    return serializeStreams();
}
Beispiel #5
0
//constructor:
shMonster::shMonster (shMonId id, int extralevels /* = 0 */ )
    :shCreature ()
{
    int do_or = 0;
    int do_and = 0;
    int gotweapon = 0;
    shMonsterIlk *ilk = &MonIlks[id];
    mIlkId = id;

    mType = ilk->mType;
    strncpy (mName, ilk->mName, 30);
    mCLevel = ilk->mBaseLevel;
    mNaturalArmorBonus = ilk->mNaturalArmorBonus;
    mReflexSaveBonus = 0;

    mDir = kNoDirection;
    mTame = 0;
    mStrategy = ilk->mDefaultStrategy;
    mDisposition = ilk->mDefaultDisposition;
    mTactic = kReady;
    mDestX = -1;
    mEnemyX = -1;
    mPlannedMoveIndex = -1;
    mSpellTimer = 0;

    memcpy (mInnateResistances, ilk->mInnateResistances,
            sizeof (mInnateResistances));
    mInnateIntrinsics = ilk->mInnateIntrinsics;
    for (int i = 0; i < ilk->mNumPowers; ++i)
        if (ilk->mPowers[i] == kTelepathyPower)
            mInnateIntrinsics |= kTelepathy; /* Assume always on. */
    mFeats = ilk->mFeats;

#define IMMUNE 122

    switch (mType) {
    case kMutant:
        mInnateResistances[kRadiological] = IMMUNE;
        mInnateResistances[kMagnetic] = IMMUNE;
        break;
    case kHumanoid:
        mInnateResistances[kMagnetic] = IMMUNE;
        break;
    case kAnimal:
        mInnateResistances[kMagnetic] = IMMUNE;
        mInnateIntrinsics |= kScent;
        break;
    case kInsect:
        mInnateResistances[kMagnetic] = IMMUNE;
        mInnateResistances[kRadiological] = IMMUNE;
        mInnateIntrinsics |= kScent;
        break;
    case kOutsider:
        mInnateResistances[kMagnetic] = IMMUNE;
        break;
    case kBot:
        mInnateResistances[kToxic] = IMMUNE;
        mInnateResistances[kPsychic] = IMMUNE;
        mInnateResistances[kRadiological] = IMMUNE;
        mInnateResistances[kViolating] = IMMUNE;
        mInnateResistances[kMesmerizing] = IMMUNE;
        mInnateResistances[kBlinding] = IMMUNE;
        mInnateIntrinsics |= kBreathless;
        break;
    case kDroid:
        mInnateResistances[kToxic] = IMMUNE;
        mInnateResistances[kPsychic] = IMMUNE;
        mInnateResistances[kRadiological] = IMMUNE;
        mInnateResistances[kViolating] = IMMUNE;
        mInnateResistances[kMesmerizing] = IMMUNE;
        mInnateResistances[kBlinding] = IMMUNE;
        mInnateIntrinsics |= kBreathless;
        break;
    case kProgram:
        mInnateResistances[kToxic] = IMMUNE;
        mInnateResistances[kRadiological] = IMMUNE;
        mInnateResistances[kViolating] = IMMUNE;
        /* Processes can be put to sleep so no kMesmerizing immunity. */
        mInnateIntrinsics |= kBreathless;
        break;
    case kConstruct:
        mInnateResistances[kToxic] = IMMUNE;
        mInnateResistances[kPsychic] = IMMUNE;
        mInnateResistances[kRadiological] = IMMUNE;
        mInnateResistances[kStunning] = IMMUNE;
        mInnateResistances[kConfusing] = IMMUNE;
        mInnateResistances[kViolating] = IMMUNE;
        mInnateResistances[kParalyzing] = IMMUNE;
        mInnateResistances[kMesmerizing] = IMMUNE;
        mInnateResistances[kBlinding] = IMMUNE;
        mInnateIntrinsics |= kBreathless;
        break;
    case kOoze:
        mInnateResistances[kToxic] = 3;
        mInnateResistances[kMagnetic] = IMMUNE;
        mInnateResistances[kRadiological] = IMMUNE;
        mInnateResistances[kViolating] = IMMUNE;
        mInnateResistances[kWebbing] = IMMUNE;
        mInnateIntrinsics |= kBreathless;
        break;
    case kAberration:
        mInnateResistances[kMagnetic] = IMMUNE;
        mInnateResistances[kRadiological] = IMMUNE;
        mInnateResistances[kViolating] = IMMUNE;
        break;
    case kCyborg:
        mInnateResistances[kToxic] = 2;
        mInnateResistances[kRadiological] = 10;
        mInnateIntrinsics |= kBreathless;
        break;
    case kEgg:
        mInnateResistances[kViolating] = IMMUNE;
        mInnateIntrinsics |= kBreathless;
        /* fall through */
    case kBeast:
        mInnateResistances[kMagnetic] = IMMUNE;
        mInnateIntrinsics |= kScent;
        break;
    case kVermin:
        mInnateResistances[kMagnetic] = IMMUNE;
        mInnateIntrinsics |= kScent;
        mInnateIntrinsics |= kCanSwim;
        break;
    case kAlien:
        mAlienEgg.mHatchChance = 0;
        mInnateResistances[kMagnetic] = IMMUNE;
        mInnateResistances[kRadiological] = 10;
        mInnateResistances[kCorrosive] = IMMUNE;
        mInnateIntrinsics |= kScent;
        if (!isA (kMonAlienQueen)) /* Too heavy and bloated. */
            mInnateIntrinsics |= kJumpy;
        gainRank (kUnarmedCombat, mCLevel/2);
        break;
    default:
        debug.log ("Alert! Unknown monster type");
        mInnateResistances[kMagnetic] = IMMUNE;
    }

#undef IMMUNE

    if (3 == ilk->mGender) {
        mGender = RNG (1, 2);
    } else {
        mGender = ilk->mGender;
    }

    /* roll ability scores */
    rollAbilityScores (ilk->mStr, ilk->mCon, ilk->mAgi,
                       ilk->mDex, ilk->mInt, ilk->mPsi);

    /* roll hit points */
    rollHitPoints (ilk->mHitDice, 8);

    /* setup speed */
    mSpeed = ilk->mSpeed;
    computeAC ();

    mGlyph = ilk->mGlyph;
    if (isA (kMonMutantNinjaTurtle))
        mGlyph.mTileX += RNG (4); /* Got four of those. */
    mState = kActing;

    if (equipment[id].mPtr) /* Does monster get standard equipment? */
    for (int i = 0; i < equipment[id].mCnt; ++i) {
        const char *str = equipment[id].mPtr[i];

        if ('|' == str[0]) { /* the or symbol indicates don't try to create
                                the object unless the previous obj failed */
            if (0 == do_or) {
                do_or = 1;
                do_and = 0;
                continue;
            } else {
                ++str;
            }
        } else if (',' == str[0]) { /* the comma symbol indicates create the
                                       object only if the prev obj was made */
            if (1 == do_and) {
                ++str;
            } else {
                continue;
            }
        }

        shObject *obj = createObject (str, 0);

        if (NULL == obj) {
            do_or = 1;
            do_and = 0;
            debug.log ("unable to equip %s", str);
            continue;
        }
        do_or = 0;
        do_and = 1;
        addObjectToInventory (obj);
        if (!mWeapon and obj->isA (kWeapon)) {
            if (obj->myIlk ()->mMeleeSkill != kNoSkillCode) {
                gainRank (obj->myIlk ()->mMeleeSkill, 1 + mCLevel * 2/3);
            }
            if (obj->myIlk ()->mGunSkill != kNoSkillCode) {
                gainRank (obj->myIlk ()->mGunSkill, 1 + mCLevel * 2/3);
            }
            ++gotweapon;
            /* don't wield until hero is in sight so he can see message */
            //wield (obj, 1);
        } else if (obj->isA (kArmor) or obj->isA (kImplant)) {
            don (obj, 1);
        }
    }

    if (!gotweapon) {
        gainRank (kUnarmedCombat, 1 + mCLevel);
    }

    /* Maybe monster gets some more treasure. */
    if (noTreasure () or
        kAnimal == mType  or kBeast == mType    or kAberration == mType or
        kInsect == mType  or kVermin == mType   or kOutsider == mType or
        kEgg == mType     or kOoze == mType     or kAlien == mType or
        kBot == mType     or kConstruct == mType)
    { /* No treasure requested or a monster does not want treasure. */
    } else {
        if (RNG (50) <= 5 + mCLevel) {
            shObject *cash = new shObject (kObjMoney);
            cash->mCount = NDX (mCLevel + 1, 10);
            addObjectToInventory (cash);
        }
        if (RNG (80) <= 5 + mCLevel) {
            shObject *obj = generateObject (-1);

            while (obj->getMass () > 5000) {
                delete obj;
                obj = generateObject (-1);
            }

            addObjectToInventory (obj);
        }
    }

    computeIntrinsics ();

    if (RNG (100) < ilk->mPeacefulChance) {
        mDisposition = kIndifferent;
    }

    debug.log ("spawned %s with %d HP speed %d", mName, mHP, mSpeed);
}
int main()
{

    /* Quick hack for Dominic should be removed later, has nothing to do with 2dx_S
    int n = 20;
    int r_inner = 4;
    int r_outer = 9;

    SingleParticle2dx::real_array2d_type data2d = SingleParticle2dx::real_array2d_type(boost::extents[n][n]);

    for (int i=0; i<n; i++)
    {
    	for (int j=0; j<n; j++)
    	{
    		double r = sqrt( (i-n/2)*(i-n/2) + (j-n/2)*(j-n/2) );
    		//if ( (r>r_inner) && (r<r_outer) )
    		if ( (r<r_outer) )
    		{
    			data2d[i][j] = 1;
    		}
    		else
    		{
    			data2d[i][j] = 0;
    		}
    	}
    }

    SingleParticle2dx::Utilities::MRCFileIO::writeToMrc(&data2d, "scheibe.mrc");
    return 0;
    */


    boost::uniform_real<> uni_dist(-1,1);
    boost::variate_generator<boost::mt19937, boost::uniform_real<> > generator(boost::mt19937(time(0)), uni_dist );

    SingleParticle2dx::ConfigContainer* config = SingleParticle2dx::ConfigContainer::Instance();
    config->setParticleSize(n);

    SingleParticle2dx::DataStructures::Projection2d proj(n,n);

    std::vector<SingleParticle2dx::DataStructures::Orientation*> orient_vec;
    std::vector<std::string> name_vec;

    orient_vec.push_back(new SingleParticle2dx::DataStructures::Orientation(0,0,0));
    name_vec.push_back("test_0_0_0.mrc");
//	orient_vec.push_back(new SingleParticle2dx::DataStructures::Orientation(0,0,45));
//	name_vec.push_back("test_0_0_45.mrc");

//	orient_vec.push_back(new SingleParticle2dx::DataStructures::Orientation(0,30,0));
//	name_vec.push_back("test_0_30_0.mrc");
//	orient_vec.push_back(new SingleParticle2dx::DataStructures::Orientation(0,30,45));
//	name_vec.push_back("test_0_30_45.mrc");

//	orient_vec.push_back(new SingleParticle2dx::DataStructures::Orientation(30,45,0));
//	name_vec.push_back("test_30_45_0.mrc");
//	orient_vec.push_back(new SingleParticle2dx::DataStructures::Orientation(30,45,30));
//	name_vec.push_back("test_30_45_45.mrc");

    SingleParticle2dx::real_array3d_type protein = SingleParticle2dx::real_array3d_type(boost::extents[2*dh+2*offset+1][2*dh+2*offset+1][2*dh+2*offset+1]);
    SingleParticle2dx::real_array3d_type data3d = SingleParticle2dx::real_array3d_type(boost::extents[n][n][n]);

    generateObject(dh+offset, dh+offset, dh+offset, protein);
    SingleParticle2dx::Utilities::MRCFileIO::writeToMrc(&protein, "protein.mrc");

    SingleParticle2dx::DataStructures::Reconstruction3d rec(n,n,n);


    for (int k=0; k<static_cast<int>(orient_vec.size()); k++)
    {
        std::cout << "Generate model " << k+1 << "/" << orient_vec.size() << std::endl;

        SingleParticle2dx::Utilities::DataContainerFunctions::resetData(&data3d);

        for(int i=lat; i<(n-lat); i+=lat)
        {
            for(int j=lat; j<(n-lat); j+=lat)
            {
                insertObject(i, j, n/2, data3d, protein, generator);
            }
        }

        std::cout << "projecting down" << std::endl;


        for(int i=0; i<n; i++)
        {
            for(int j=0; j<n; j++)
            {
                for(int k=0; k<i; k++)
                {
                    float aux = data3d[i][j][k];
                    data3d[i][j][k] = data3d[k][j][i];
                    data3d[k][j][i] = aux;
                }
            }
        }

        rec.setFourierSpaceData(data3d);
        rec.setProjectionMethod(4);
        SingleParticle2dx::DataStructures::ParticleContainer dummy_container;
        rec.forceProjectionPreparation(dummy_container);
        rec.writeToFile("test3d.mrc");

        int tilt = 0;
        SingleParticle2dx::DataStructures::Orientation o(0, tilt, -90);
        rec.calculateProjection(o, proj);
        proj.writeToFile("proj_" + SingleParticle2dx::Utilities::StringFunctions::TtoString(tilt) + ".mrc" );


        SingleParticle2dx::DataStructures::Orientation o2(90, 30, -180);
        rec.calculateProjection(o2, proj);
        proj.writeToFile("proj_" + SingleParticle2dx::Utilities::StringFunctions::TtoString(30) + ".mrc" );

    }


    rec.writeToFile( "test_syn.mrc" );

    return 0;
}
Beispiel #7
0
int
shMapLevel::buildSewer ()
{
    int x, y, i, n;
    int lighting = RNG (2) ? -1 : 1;
    SewerRoom nodes[NODECOLS][NODEROWS];

    mMapType = kSewer;

    x = RNG (NODECOLS);
    y = RNG (NODEROWS);

    //first pass
    buildSewerHelper (nodes, x, y, 0);

    //second pass, make more tightly connected
    for (n = 10; n; n--) {
        if (RNG(3)) {
            x = RNG (NODECOLS-1);
            y = RNG (NODEROWS);
            nodes[x][y].mWalls[1] = 0;
            nodes[x+1][y].mWalls[2] = 0;
        } else {
            x = RNG (NODECOLS);
            y = RNG (NODEROWS-1);
            nodes[x][y].mWalls[3] = 0;
            nodes[x][y+1].mWalls[0] = 0;
        }
    }

    for (x = 0; x < NODECOLS; x++) {
        for (y = 0; y < NODEROWS; y++) {
            if (nodes[x][y].mDeadEnd or !RNG(7)) {
                nodes[x][y].mBulbous = 1;
            }
        }
    }

    // force 2 bulbous rooms
    x = RNG (NODECOLS/3); y = RNG (NODEROWS);
    nodes[x][y].mBulbous = 1;
    x = NODECOLS - 1 - RNG (NODECOLS/3); y = RNG (NODEROWS);
    nodes[x][y].mBulbous = 1;

    // don't have adjacent bulbous rooms (looks bad)
    for (x = 0; x < NODECOLS-1; x++) {
        for (y = 0; y < NODEROWS; y++) {
            if (nodes[x][y].mBulbous and nodes[x+1][y].mBulbous and
                nodes[x][y].mWalls[1])
            {
                if (RNG(2))
                    nodes[x][y].mBulbous = 0;
                else
                    nodes[x+1][y].mBulbous = 0;
            }
        }
    }

    for (x = 0; x < NODECOLS; x++) {
        for (y = 0; y < NODEROWS-1; y++) {
            if (nodes[x][y].mBulbous and nodes[x][y+1].mBulbous and
                nodes[x][y].mWalls[3])
            {
                if (RNG(2))
                    nodes[x][y].mBulbous = 0;
                else
                    nodes[x][y+1].mBulbous = 0;
            }
        }
    }

    for (x = 0; x < NODECOLS; x++) {
        for (y = 0; y < NODEROWS; y++) {
            buildSewerRoom (nodes, x, y);
        }
    }

    for (n = NDX(2,4); n; n--) {
        floodMuck (RNG(NODECOLS)*6+5, RNG(NODEROWS)*4+2, kSewage, NDX(8,20));
    }

    for (i = NDX (2, 3); i; --i) {
        findUnoccupiedSquare (&x, &y);
        switch (RNG (4)) {
        case 0:
            addTrap (x, y, shFeature::kPit); break;
        case 1:
            addTrap (x, y, shFeature::kHole); break;
        case 2:
            addTrap (x, y, shFeature::kTrapDoor); break;
        case 3:
            addTrap (x, y, shFeature::kRadTrap); break;
        }
    }

    for (i = 0; i < 8; i++) {
        findUnoccupiedSquare (&x, &y);
        putObject (generateObject (mDLevel), x, y);
    }

    for (x = 0; x < mColumns; x++)
        for (y = 0; y < mRows; y++)
            setLit (x, y, lighting, lighting, lighting, lighting);



    return 1;
}
Beispiel #8
0
/* returns 1 if shop successfully created, 0 o/w */
int
shMapLevel::makeShop (int sx, int sy, int ex, int ey, int kind)
{
    int x, y;
    int dx = -1, gx = -1;
    int dy = -1, gy = -1;
    shFeature *f;
    shFeature *door = NULL;
    shMonster *clerk;
    int roomid = mSquares[sx][sy].mRoomId;

    /* Find the door (we only make shops in rooms with exactly one door). */
    for (x = sx + 1; x < ex; x++) {
        f = getFeature (x, sy);
        if (f and f->isDoor ()) {
            if (door) return 0;
            door = f;
            dx = x;
            dy = sy;
        }
        f = getFeature (x, ey);
        if (f and f->isDoor ()) {
            if (door) return 0;
            door = f;
            dx = x;
            dy = ey;
        }
    }
    for (y = sy + 1; y < ey; y++) {
        f = getFeature (sx, y);
        if (f and f->isDoor ()) {
            if (door) return 0;
            door = f;
            dx = sx;
            dy = y;
        }
        f = getFeature (ex, y);
        if (f and f->isDoor ()) {
            if (door) return 0;
            door = f;
            dx = ex;
            dy = y;
        }
    }

    if (!door)  return 0;  /* What?! There are no doors to this room? */

    /* Make sure door is a normal automatic door. */
    door->mType = shFeature::kDoorClosed;
    door->mDoor.mFlags = shFeature::kAutomatic;

    /* First row or column from the door shall be empty. */
    if (dx == sx) {
        sx++; dx++; gx = sx;
    } else if (dx == ex) {
        ex--; dx--; gx = ex;
    }
    if (dy == sy) {
        sy++; dy++; gy = sy;
    } else if (dy == ey) {
        ey--; dy--; gy = ey;
    }

    if (-1 == kind) { /* Randomly determine kind of shop. */
        switch (RNG (20)) {
        case 0: case 1: case 2: case 3: case 4:
        case 5: case 6: case 7:
            kind = shRoom::kGeneralStore; break;
        case 8: case 9: case 10:
            kind = shRoom::kHardwareStore; break;
        case 11: case 12: case 13:
            kind = shRoom::kSoftwareStore; break;
        case 14: case 15:
            kind = shRoom::kArmorStore; break;
        case 16: case 17:
            kind = shRoom::kWeaponStore; break;
        case 18:
            kind = shRoom::kImplantStore; break;
        case 19:
            kind = shRoom::kCanisterStore; break;
        }
    }

    bool infested = !RNG (25); /* Full of cockroaches. */

    for (x = sx + 1; x < ex; x++) { /* Get us some stuff to sell. */
        for (y = sy + 1; y < ey; y++) {
            shObject *obj = NULL;

            switch (kind) {
            case shRoom::kGeneralStore:
                obj = generateObject (-1); break;
            case shRoom::kHardwareStore:
                obj = createTool (); break;
            case shRoom::kSoftwareStore:
                if (RNG (8)) {
                    obj = createFloppyDisk ();
                } else {
                    obj = pickFromCategory (kObjGenericComputer);
                } break;
            case shRoom::kArmorStore:
                obj = createArmor (); break;
            case shRoom::kWeaponStore:
                if (RNG (20)) {
                    obj = createWeapon ();
                } else {
                    obj = createRayGun ();
                } break;
            case shRoom::kImplantStore:
                obj = createImplant (); break;
            case shRoom::kCanisterStore:
                obj = createCanister (); break;
            }
            obj->setUnpaid ();
            putObject (obj, x, y);

            if (infested and /* Put one under every big enough item. */
                obj->myIlk ()->mSize > MonIlks[kMonGiantCockroach].mSize)
            {
                shCreature *cockroach = new shMonster (kMonGiantCockroach);
                putCreature (cockroach, x, y);
            }
        }
    }

    /* The shopkeeper droid. */
    clerk = new shMonster (kMonClerkbot);
    putCreature (clerk, dx, dy);
    clerk->mShopKeeper.mHomeX = dx;
    clerk->mShopKeeper.mHomeY = dy;
    clerk->mShopKeeper.mShopId = roomid;
    clerk->mShopKeeper.mBill = 0;

    /* Shops may have a guard. */
    bool guarded = false;
    if (mDLevel > 4 and (!RNG (3) or mDLevel > TOWNLEVEL) and !isTownLevel ()) {
        shMonster *guard = NULL;
        shMonId guardtype[3] = {kMonSecuritron, kMonWarbot, kMonGuardbot};
        guard = new shMonster (guardtype [RNG (3)]);
        if (guard) { /* Pick a nice warm spot in a corner. */
            if (gx == -1) {
                gx = (sx+1 == dx) ? ex-1 :
                     (ex-1 == dx) ? sx+1 :
                          RNG (2) ? sx+1 : ex-1;
            } else {
                gy = (sy+1 == dy) ? ey-1 :
                     (ey-1 == dy) ? sy+1 :
                          RNG (2) ? sy+1 : ey-1;
            }
            if (!putCreature (guard, gx, gy)) {
                guard->mStrategy = shMonster::kGuard;
                guard->mDisposition = shMonster::kIndifferent;
                guard->mGuard.mToll = -1;
                guarded = true;
            }
        }
    }

    mRooms[roomid].mType = (shRoom::Type) kind;
    mFlags |= kHasShop;
    debug.log ("made %s%sshop on level %d.",
        guarded ? "guarded " : "", infested ? "infested " : "", mDLevel);
    return 1;
}
Beispiel #9
0
void
shMapLevel::decorateRoom (int sx, int sy, int ex, int ey)
{
    if ((ex-sx) * (ey-sy) <= 20 + RNG (1, 20) and
        mDLevel > 1 and
        !RNG (1 + mDLevel) and
        !(kHasShop & mFlags) and
        makeShop (sx, sy, ex, ey))
    {
        return;
    }

    while (!RNG (8)) {  /* secret treasure niche */
        int x, y, dx, dy, horiz;
    failedniche:
        if (!RNG (222)) break;
        if (RNG (2)) {
            x = RNG (sx + 1, ex - 1);
            dx = x;
            horiz = 1;
            if (RNG (2)) {
                if (!testSquares (x - 1, sy - 2, x + 1, sy - 1, kStone))
                    goto failedniche;
                y = sy - 1;
                dy = sy;
            } else {
                if (!testSquares (x - 1, ey + 1, x + 1, ey + 2, kStone))
                    goto failedniche;
                y = ey + 1;
                dy = ey;
            }
        } else {
            y = RNG (sy + 1, ey - 1);
            dy = y;
            horiz = 0;
            if (RNG (2)) {
                if (!testSquares (sx - 2, y - 1, sx - 1, y + 1, kStone))
                    goto failedniche;
                x = sx - 1;
                dx = sx;
            } else {
                if (!testSquares (ex + 1, y - 1, ex + 2, y + 1, kStone))
                    goto failedniche;
                x = ex + 1;
                dx = ex;
            }
        }
        SETSQ (x-1, y-1, kHWall);
        SETSQ (x,   y-1, kHWall);
        SETSQ (x+1, y-1, kHWall);
        SETSQ (x-1, y,   kVWall);
        SETSQ (x,   y,   kFloor);
        SETSQ (x+1, y,   kVWall);
        SETSQ (x-1, y+1, kHWall);
        SETSQ (x,   y+1, kHWall);
        SETSQ (x+1, y+1, kHWall);

        SETSQ (dx, dy, kFloor);
        addDoor (dx, dy, horiz, 0, RNG (6), 1, !RNG(3), !RNG(10));
        SETSQFLAG (x, y, kHallway);
        if (RNG (6)) putObject (generateObject (mDLevel), x, y);
        if (RNG (2)) putObject (generateObject (mDLevel), x, y);

    }

    if (mDLevel > 7 and !RNG (15)) {
        /* monolith room */
        shMonster *m = new shMonster (kMonMonolith);
        putCreature (m, (sx + ex) / 2, (sy + ey) / 2);
        return;
    }

    if ((mDLevel > 6) and !RNG (22) and
        makeNest (sx, sy, ex, ey))
    {
        return;
    }

    if (mDLevel > 1 and mDLevel < 10 and
        !(kHasMelnorme & mFlags) and
        !RNG (30))
    {   /* Melnorme room. */
        makeTradePost (sx, sy, ex, ey);
    }   /* No return statement.  Trade post is a mundane room. */

    mundaneRoom (sx, sy, ex, ey);
}
Beispiel #10
0
void
shMapLevel::mundaneRoom (int sx, int sy, int ex, int ey)
{
    int i, npiles, n;
    int x, y;

    if (mDLevel != TOWNLEVEL) {
        if (RNG (mDLevel + 6) > 9) {
            darkRoom (sx, sy, ex, ey);
        }

        if (!RNG (30)) {
            /* Radioactive room. */
            for (x = sx + 1; x < ex; x++) {
                for (y = sy + 1; y < ey; y++) {
                    mSquares[x][y].mFlags |= shSquare::kRadioactive;
                }
            }
        }
    }

    /* treasure expectation per room:
       version 0.3:
         0.375 piles x 1.1875 obj per pile +
         (~) 0.125 niches x 0.8 obj per niche
         ~ .5453125 objs per room

       version 0.2.9:
         0.375 piles x 1.375 obj per pile
         = .515625 obj per room
   */

    npiles = RNG (4) ? 0 : RNG (2) + RNG (2) + RNG (2);

    while (npiles--) {
        x = RNG (sx + 1, ex - 1);
        y = RNG (sy + 1, ey - 1);
        if (TESTSQ (x, y, kFloor)  and !isObstacle (x, y)) {
            n = RNG (10) ? 1 : RNG (2, 3);
            for (i = 0; i < n; i++) {
                putObject (generateObject (mDLevel), x, y);
            }
        }
    }

    if (0 == RNG (9)) {
        x = RNG (sx + 1, ex - 1);
        y = RNG (sy + 1, ey - 1);
        if (TESTSQ (x, y, kFloor) and !isObstacle (x, y) and
            0 == countObjects (x, y))
        {
            addVat (x, y);
        }
    }

    /* Reticulans of PRIME are weak enough to get instakilled in a pit.
       Do not place traps at all on first level. */
    while (!RNG (12) and mDLevel > 1) {
        x = RNG (sx + 1, ex - 1);
        y = RNG (sy + 1, ey - 1);
        if (TESTSQ (x, y, kFloor) and !isObstacle (x, y) and
            !getFeature (x, y))
        {
            shFeature::Type ttype;
        retrap:
            /* I'm using this retrap label because putting a for or while
               loop here uncovers a bug in g++! */
            /* FIXME: Probably the bug is long gone.  Get rid of goto. */
                ttype = (shFeature::Type) RNG (shFeature::kPit,
                                              shFeature::kPortal);
                switch (ttype) {
                case shFeature::kPit:
                case shFeature::kTrapDoor:
                    break;
                case shFeature::kAcidPit:
                    if (mDLevel < 7) goto retrap;
                    break;
                case shFeature::kHole:
                    if (RNG (5)) goto retrap;
                    break;
                case shFeature::kWeb:
                    goto retrap;
                case shFeature::kRadTrap:
                    if (mDLevel < 5) goto retrap;
                    break;
                case shFeature::kPortal:
                default: /* these traps are unimplemented */
                    goto retrap;
                }

            addTrap (x, y, ttype);
        }
    }
}