Exemple #1
0
/* returns index of an item to steal, ABORT if player carrying none */
int stolen_item(void)
{
    int idx;
    int nextitem;

    int cards[MAXITEMS];

    nextitem = 0;

    /* look for bank cards */
    for (idx = 0; idx < MAXITEMS; ++idx)
    {
        if (0 == Player.possessions[idx]) continue;
        if (Player.possessions[idx]->id < OB_DEBIT_CARD) continue;
        if (Player.possessions[idx]->id > OB_SMART_CARD) continue;

        cards[nextitem++] = idx;
    }

    if (0 == nextitem) return random_item();

    if (nextitem > 1)
        shuffle(cards, nextitem);

    if (random_range(100) < 75)
    {
        /* oh that sucks... */
        return cards[0];
    }

    return random_item();
}
Exemple #2
0
// determines the next hop in a decentralied search:
//   N    network (with dist + graph)
//   s    start node
//   t    goal node
int SoftmaxDecentralizedSearch::next_hop(HNetwork& N, int s, int t) {
  map<int,double> D;
  vector<int> nbrs = N.get_neighbors(s);
  vector<int>::iterator v;
  for (v = nbrs.begin(); v < nbrs.end(); v++) {
    D[*v] = -1 * beta * N.dist(*v, t);
  }

  softmax_dist(D);
  return random_item(D);
}
Exemple #3
0
//=================================================================================================
Class ClassInfo::GetRandomPlayer()
{
	static vector<Class> classes;
	if(classes.empty())
	{
		for(ClassInfo& ci : ClassInfo::classes)
		{
			if(ci.pickable)
				classes.push_back(ci.class_id);
		}
	}
	return random_item(classes);
}
Exemple #4
0
/* enchant */
void enchant(int delta)
{
    int i,used = false;
    long change_cash;

    if (delta < 0) {
        i = random_item();
        if (i == ABORT || Player.possessions[i]->usef == I_NOTHING ||
                Player.possessions[i]->usef == I_NO_OP ||
                Player.possessions[i]->usef == I_NORMAL_ARMOR ||
                Player.possessions[i]->usef == I_NORMAL_WEAPON ||
                Player.possessions[i]->usef == I_NORMAL_SHIELD ||
                Player.possessions[i]->objchar == FOOD ||
                Player.possessions[i]->objchar == MISSILEWEAPON) {
            print1("You feel fortunate.");
            morewait();
        }
        else if (Player.possessions[i]->blessing < 0 ||
                 (Player.possessions[i]->objchar == ARTIFACT && random_range(3))) {
            if (Player.possessions[i]->uniqueness == COMMON)
                print1("Your ");
            nprint1(itemid(Player.possessions[i]));
            nprint1(" glows, but the glow flickers out...");
            morewait();
        }
        else {
            used = (Player.possessions[i]->used);
            if (used) {
                Player.possessions[i]->used = false;
                item_use(Player.possessions[i]);
            }
            if (Player.possessions[i]->uniqueness == COMMON)
                print1("Your ");
            nprint1(itemid(Player.possessions[i]));
            nprint1(" radiates an aura of mundanity!");
            morewait();
            Player.possessions[i]->plus = 0;
            Player.possessions[i]->charge = -1;
            Player.possessions[i]->usef = I_NOTHING;
            if (used) {
                Player.possessions[i]->used = true;
                item_use(Player.possessions[i]);
            }
        }
    }
    else {
        i = getitem(CASH);
        if (i == ABORT) {
            print1("You feel unlucky.");
            morewait();
        }
        else if (i == CASHVALUE) {
            print1("You enchant your money.... What a concept!");
            change_cash = Player.cash*(random_range(7) - 3)/6;
            if (change_cash > 0) print2("Seems to have been a good idea!");
            else print2("Maybe it wasn't such a good idea....");
            Player.cash += change_cash;
            morewait();
        }
        else if (Player.possessions[i]->objchar == ARTIFACT) {
            if (Player.possessions[i]->usef !=
                    Objects[Player.possessions[i]->id].usef) {
                print1("It re-acquires its magical aura!");
                Player.possessions[i]->usef = Objects[Player.possessions[i]->id].usef;
            }
            else {
                print1("The enchantment spell enfolds the ");
                nprint1(itemid(Player.possessions[i]));
                print2("and the potent enchantment of the Artifact causes a backlash!");
                morewait();
                clearmsg();
                manastorm(Player.x,Player.y,Player.possessions[i]->level*5);
            }
        }
        else {
            if (Player.possessions[i]->plus > random_range(20)+1) {
                print1("Uh-oh, the force of the enchantment was too much!");
                print2("There is a loud explosion!");
                morewait();
                manastorm(Player.x,Player.y,Player.possessions[i]->plus*5);
                dispose_lost_objects(1,Player.possessions[i]);
            }
            else {
                used = (Player.possessions[i]->used);
                if (used) {
                    State.setSuppressPrinting( true );
                    Player.possessions[i]->used = false;
                    item_use(Player.possessions[i]);
                    State.setSuppressPrinting( false );
                }
                print1("The item shines!");
                morewait();
                Player.possessions[i]->plus += delta+1;
                if (Player.possessions[i]->charge > -1)
                    Player.possessions[i]->charge +=
                        ((delta+1) * (random_range(10) + 1));
                if (used) {
                    State.setSuppressPrinting( true );
                    Player.possessions[i]->used = true;
                    item_use(Player.possessions[i]);
                    State.setSuppressPrinting( false );
                }
            }
        }
        calc_melee();
    }
}
Exemple #5
0
/* bless */
void bless(int blessing)
{
    int index,used;

    if (blessing < 0) {
        index = random_item();
        if (index == ABORT) {
            print1("You feel fortunate.");
            morewait();
        }
        else {
            print1("A foul odor arises from ");
            if (Player.possessions[index]->uniqueness == COMMON)
                nprint1("your ");
            nprint1(itemid(Player.possessions[index]));
            morewait();
            used = (Player.possessions[index]->used);
            if (used) {
                State.setSuppressPrinting( true );
                Player.possessions[index]->used = false;
                item_use(Player.possessions[index]);
                State.setSuppressPrinting( false );
            }
            Player.possessions[index]->blessing -= 2;
            if (Player.possessions[index]->blessing < 0)
                Player.possessions[index]->plus =
                    abs(Player.possessions[index]->plus) - 1;
            if (used) {
                State.setSuppressPrinting( true );
                Player.possessions[index]->used = true;
                item_use(Player.possessions[index]);
                State.setSuppressPrinting( false );
            }
        }
    }
    else {
        index = getitem(NULL_ITEM);
        if (index == CASHVALUE) {
            print1("Blessing your money has no effect.");
            morewait();
        }
        else if (index != ABORT) {
            used = Player.possessions[index]->isUsed();
            if (used) {
                State.setSuppressPrinting( true );
                Player.possessions[index]->used = false;
                item_use(Player.possessions[index]);
                State.setSuppressPrinting( false );
            }
            print1("A pure white light surrounds the item... ");
            if (Player.possessions[index]->blessing < 0-(blessing+1)) {
                print2("which is evil enough to resist the effect of the blessing!");
                morewait();
            }
            else if (Player.possessions[index]->blessing < -1) {
                print2("which disintegrates under the influence of the holy aura!");
                morewait();
                Player.itemweight -=  Player.possessions[index]->weight;
                dispose_lost_objects(1,Player.possessions[index]);
            }
            else if (Player.possessions[index]->blessing < blessing+1) {
                print2("which now seems affected by afflatus!");
                morewait();
                Player.possessions[index]->blessing++;
                Player.possessions[index]->plus =
                    abs(Player.possessions[index]->plus)+1;
            }
            else {
                print2("The hierolux fades without any appreciable effect....");
                morewait();
            }
            if (used && (Player.possessions[index] != NULL)) {
                State.setSuppressPrinting( true );
                Player.possessions[index]->used = true;
                item_use(Player.possessions[index]);
                State.setSuppressPrinting( false );
            }
        }
    }
    calc_melee();
}
Exemple #6
0
/* gain for an item */
void acquire(int blessing)
{
    char otype;
    int index,id = ABORT;
    pob newthing;

    if (blessing < 0) {
        index = random_item();
        if (index == ABORT)
            mprint("You feel fortunate.");
        else {
            print1("Smoke drifts out of your pack.... ");
            print2("Destroyed: ");
            nprint2(itemid(Player.possessions[index]));
            morewait();
            dispose_lost_objects(1,Player.possessions[index]);
        }
    }
    else {
        newthing = ((pob) checkmalloc(sizeof(objtype)));
        /* DAG this assignment looks unneccessary */
        newthing->id = -1;
        if (gamestatusp(CHEATED))
            print1("Acquire which kind of item: !?][}{)/=%%\\& ");
        else
            print1("Acquire which kind of item: !?][}{)/=%%\\ ");
        otype = mgetc();
        switch (otype) {
        case (POTION&0xff):
            if (blessing > 0)
                id = itemlist(POTIONID,NUMPOTIONS);
            else
                id = random_range(NUMPOTIONS);
            if (id < 0) print2("You feel stupid.");
            else make_potion(newthing,id);
            break;
        case (SCROLL&0xff):
            if (blessing > 0)
                id = itemlist(SCROLLID,NUMSCROLLS);
            else
                id = random_range(NUMSCROLLS);
            if (id < 0) print2("You feel stupid.");
            else make_scroll(newthing,id);
            break;
        case (RING&0xff):
            if (blessing > 0)
                id = itemlist(RINGID,NUMRINGS);
            else
                id = random_range(NUMRINGS);
            if (id < 0) print2("You feel stupid.");
            else make_ring(newthing,id);
            break;
        case (STICK&0xff):
            if (blessing > 0)
                id = itemlist(STICKID,NUMSTICKS);
            else
                id = random_range(NUMSTICKS);
            if (id < 0) print2("You feel stupid.");
            else make_stick(newthing,id);
            break;
        case (ARMOR&0xff):
            if (blessing > 0)
                id = itemlist(ARMORID,NUMARMOR);
            else
                id = random_range(NUMARMOR);
            if (id < 0) print2("You feel stupid.");
            else make_armor(newthing,id);
            break;
        case (SHIELD&0xff):
            if (blessing > 0)
                id = itemlist(SHIELDID,NUMSHIELDS);
            else
                id = random_range(NUMSHIELDS);
            if (id < 0) print2("You feel stupid.");
            else make_shield(newthing,id);
            break;
        case (WEAPON&0xff):
            if (blessing > 0)
                id = itemlist(WEAPONID,NUMWEAPONS);
            else
                id = random_range(NUMWEAPONS);
            if (id < 0) print2("You feel stupid.");
            else make_weapon(newthing,id);
            break;
        case (BOOTS&0xff):
            if (blessing > 0)
                id = itemlist(BOOTID,NUMBOOTS);
            else
                id = random_range(NUMBOOTS);
            if (id < 0) print2("You feel stupid.");
            else make_boots(newthing,id);
            break;
        case (CLOAK&0xff):
            if (blessing > 0)
                id = itemlist(CLOAKID,NUMCLOAKS);
            else
                id = random_range(NUMCLOAKS);
            if (id < 0) print2("You feel stupid.");
            else make_cloak(newthing,id);
            break;
        case (FOOD&0xff):
            if (blessing > 0)
                id = itemlist(FOODID,NUMFOODS);
            else
                id = random_range(NUMFOODS);
            if (id < 0) print2("You feel stupid.");
            else make_food(newthing,id);
            break;
        case (THING&0xff):
            if (blessing > 0)
                id = itemlist(THINGID,NUMTHINGS);
            else
                id = random_range(NUMTHINGS);
            if (id < 0) print2("You feel stupid.");
            else make_thing(newthing,id);
            break;
        case (ARTIFACT&0xff):
            if (gamestatusp(CHEATED))
                id = itemlist(ARTIFACTID,NUMARTIFACTS);
            else
                id = -1;
            if (id < 0) print2("You feel stupid.");
            else make_artifact(newthing,id);
            break;
        default:
            print2("You feel stupid.");
        }
        xredraw();
        if (id != ABORT) {
            if (blessing > 0) {
                newthing->known = 2;
                Objects[id].known = 1;
            }
            newthing->used = FALSE;
            gain_item(newthing);
        }
        else
        {
            /* DAG newthing allocated but was not freed... was YA memory leak */
            /* use free() rather than free_obj() since newthing not initialized */
            free( (char *) newthing );
        }
    }
}