Esempio n. 1
0
bool Hero::displayInventory(int type)
{
    int option;

    if (type == SHOW_ALL)
    {
        cout << "Gold: " << gold << "\r\n\n";

        for (int i = 0; i < inventory.size(); i++)
        {
            cout << "\r\n" << (i + 1) << ") ";
            if (weapon.getName().compare(inventory.at(i).getName()) == 0)
            {
                cout << "Currently Equipped";
            }
            inventory.at(i).printInfo();
        }

        cout << "\r\nTo equip/use an item, enter item number. If not, enter 0.\r\n>>";
        cin >> option;

        if (option > 0 && option <= inventory.size())
        {
            equip(option - 1);
        }
    }
Esempio n. 2
0
		void environment::spawn_player(point2 location)
		{
			// player props
			auto weapon = std::make_shared<body_component::item_type>();
			weapon->add({ rl::effect::weapon_damage, 0x00, 50 });
			weapon->add({ rl::effect::equipment, static_cast<unsigned int>(rl::equipment_slot::hand_main) });
			weapon->set_name("Copper Sword");
			weapon->set_tag("copper_sword");

			// make player
			auto task = m_factory->produce();
			auto img = task->add_appearance('@', { 1, 1, 1 });
			auto pawn = task->add_location(location);
			auto body = task->add_body(100, 100);
			auto character = task->add_character();

			// setup
			body->set_name("You");
			body->set_tag("player");
			body->join_faction(1);
			body->add(weapon);
			body->equip(weapon);

			character->add_skill("sk_bash");
			character->add_skill("sk_panacea");
			character->add_skill("sk_teleport");
			character->add_skill("sk_fireball");
			character->add_skill("sk_indigo");

			m_terrain.add(task->assemble(persistency::permanent));

			impersonate(pawn);
		}
Esempio n. 3
0
void BagManager::manage()
{
  if ( AMenuItemPtr mItem = _bagMenu->getSelectedItem() )
  {
    ActorPtr selectedItem( mItem->getObject<Actor>() );
    if ( selectedItem )
    {
      ItemOperation operation = chooseItemOperationFromMenu(selectedItem);

      switch(operation)
      {
        case EQUIP: equip( selectedItem ); break;
        case DROP: Actor::Player->performAction( std::make_shared<DropAction>(selectedItem, getAmountToDrop(selectedItem) ) ); break;
        //TODO display actor info text instead of test string
        case INSPECT:
          Engine::instance()
              .windowManager()
              .getWindow<FixedSizeTextWindow>()
              .setText( selectedItem->getDescription() )
              .show();
          break;
        default:;
      }

      fillBag();
    }
  }
}
Esempio n. 4
0
void BagManager::equip(ActorPtr item)
{
  EquipActionPtr equipAction = std::make_shared<EquipAction>(item);
  Actor::Player->performAction( equipAction );

  switch( equipAction->getResult() )
  {
    case EquipResult::AlreadyEquiped:
      { //try to unequip, and then equip again
        if ( Actor::Player->performAction( std::make_shared<UnEquipAction>( item->getFeature<Pickable>()->getItemSlot() )))
        {
          equip( item );
        }
        else
        {
          msgBox( "Cannot unequip currently equipped item!", gui::MsgType::Error );
        }
      }
      break;

    case EquipResult::NoProperSlot:
      msgBox( "You haven't got appropriate slot to equip this item.", gui::MsgType::Error);
      break;

    case EquipResult::Nok:
      msgBox( "Cannot equip item!", gui::MsgType::Error );
      break;

    default:;
  }
}
Esempio n. 5
0
void Entity::init(){
	color = 2;
	inventory = new Inventory();
	attributes = new vector<Attribute*>();
	effects = new vector<Effect*>();
	addAttribute(new Attribute("Health", 1000));
	equip(NULL);
}
Esempio n. 6
0
void Hero::handleStateEquip(bool pressed, int key)
{
    showInventory();

    if (pressed)
    {
        switch (key)
        {
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        {
            int i = m_inventoryPage * INVENTORY_PAGE_SIZE + key - '1';
            if (i < (int)m_items.size())
            {
                ItemSharedPtr item = m_items[i];
                if (isEquipped(item))
                {
                    unequip(item);
                }
                else
                {
                    equip(item);
                }
            }
        }
        break;

        case 'n':
        case 'N':
        {
            m_inventoryPage++;
            if (m_inventoryPage * INVENTORY_PAGE_SIZE > (int)m_items.size())
            {
                m_inventoryPage = 0;
            }
        }
        break;

        case ' ':
            m_state = State::InGame;
            break;

        case 's':
        case 'S':
            m_state = State::Status;
            break;

        case 'd':
        case 'D':
            m_state = State::Drop;
            break;
        }
    }
}
Esempio n. 7
0
    void ActionWeapon::prepare(const MWWorld::Ptr &actor)
    {
        if (actor.getClass().hasInventoryStore(actor))
        {
            if (mWeapon.isEmpty())
                actor.getClass().getInventoryStore(actor).unequipSlot(MWWorld::InventoryStore::Slot_CarriedRight, actor);
            else
            {
                MWWorld::ActionEquip equip(mWeapon);
                equip.execute(actor);
            }

            if (!mAmmunition.isEmpty())
            {
                MWWorld::ActionEquip equip(mAmmunition);
                equip.execute(actor);
            }
        }
        actor.getClass().getCreatureStats(actor).setDrawState(DrawState_Weapon);
    }
Esempio n. 8
0
void invMenu(personagem *per){
	char test,nome[25];
	item it;

	while(1){
		system("cls");
		printf("voce deseja:\n");
		printf("a - mostrar todas as armaduras;\n");
		printf("b - mostrar todas as botas;\n");
		printf("c - mostrar todos os capacetes;\n");
		printf("d - mostrar todas as armas a distancia;\n");
		printf("f - mostrar todas as armas fisicas;\n");
		printf("m - mostrar todas as armas magicas;\n");
		printf("0 - sair.\n");
		printf("Digite a sua escolha:");
		scanf("%c",&test);
		if(test=='0'){
			return;
		}
		if(test!='a' && test!='b' && test!='c' && test!='d' && test!='f' && test!='m'){
			continue;
		}

		invType(test);

		printf("voce deseja:");
		printf("e - equipar um item;\n");
		printf("d - descartar um item;\n");
		printf("0 - sair.\n");
		scanf("%c",&test);
		switch(test){
			case '0':
				return;
			case 'e':
				printf("digite o nome do item:");
				gets(nome);
				itemFind(nome,&it);
				equip(per,it);
				break;
			case 'd':
				printf("digite o nome do item:");
				gets(nome);
				invRemove(nome);
				break;
			default:
				continue;
		}
	}
}
Esempio n. 9
0
void MWWorld::InventoryStore::autoEquipShield(const MWWorld::Ptr& actor)
{
    bool updated = false;

    mUpdatesEnabled = false;
    for (ContainerStoreIterator iter(begin(ContainerStore::Type_Armor)); iter != end(); ++iter)
    {
        if (iter->get<ESM::Armor>()->mBase->mData.mType != ESM::Armor::Shield)
            continue;

        if (iter->getClass().canBeEquipped(*iter, actor).first != 1)
            continue;

        if (iter->getClass().getItemHealth(*iter) <= 0)
            continue;

        std::pair<std::vector<int>, bool> shieldSlots =
            iter->getClass().getEquipmentSlots(*iter);

        if (shieldSlots.first.empty())
            continue;

        int slot = shieldSlots.first[0];
        const ContainerStoreIterator& shield = mSlots[slot];

        if (shield != end()
                && shield.getType() == Type_Armor && shield->get<ESM::Armor>()->mBase->mData.mType == ESM::Armor::Shield)
        {
            if (shield->getClass().getItemHealth(*shield) >= iter->getClass().getItemHealth(*iter))
                continue;
        }

        equip(slot, iter, actor);
        updated = true;
    }
    mUpdatesEnabled = true;

    if (updated)
    {
        fireEquipmentChangedEvent(actor);
        updateMagicEffects(actor);
    }
}
Esempio n. 10
0
// === OPERATION CHOOSING === //
void BagManager::manage()
{
  if ( AMenuItemPtr mItem = _bagMenu->getSelectedItem() )
  {
    if ( Actor* selectedItem = mItem->getObject<Actor>() )
    {
      ItemOperation operation = chooseItemOperationFromMenu(selectedItem);

      switch(operation)
      {
        case EQUIP: equip( selectedItem ); break;
        case DROP: drop( selectedItem ); break;
        default:;
      }

      fillBag();
    }
  }
}
Esempio n. 11
0
	ActorInventory::ActorInventory(const XMLNode &node)
		:Inventory(node), m_weapon(Item::dummyWeapon()), m_dummy_weapon(Item::dummyWeapon()), m_armour(Item::dummyArmour()), m_ammo{Item::dummyAmmo(), 0} {
		if(!node)
			return;

		XMLNode weapon_node = node.child("weapon");
		XMLNode armour_node = node.child("armour");
		XMLNode ammo_node = node.child("ammo");

		if(weapon_node)
			m_weapon = Item(findProto(weapon_node.attrib("proto_id"), ProtoId::item_weapon));
		if(armour_node)
			m_armour = Item(findProto(armour_node.attrib("proto_id"), ProtoId::item_armour));
		if(ammo_node) {
			Item ammo(findProto(ammo_node.attrib("proto_id"), ProtoId::item_ammo));
			int count = ammo_node.attrib<int>("count");
			int id = add(ammo, count);
			equip(id, count);
		}
	}
Esempio n. 12
0
/*
 * Method: GetCommodityBasePriceAlterations
 *
 * Get the price alterations for cargo items bought and sold in this system
 *
 * > alteration = system:GetCommodityBasePriceAlterations(cargo_item)
 *
 * Parameters:
 *
 *   cargo_item - The cargo item for which one wants to know the alteration
 * Return:
 *
 *   percentage -  percentage change to the cargo base price. Loosely,
 *                 positive values make the commodity more expensive,
 *                 indicating it is in demand, while negative values make the
 *                 commodity cheaper, indicating a surplus.
 *
 * Availability:
 *
 *   June 2014
 *
 * Status:
 *
 *   experimental
 */
static int l_starsystem_get_commodity_base_price_alterations(lua_State *l)
{
	PROFILE_SCOPED()
	LUA_DEBUG_START(l);

	StarSystem *s = LuaObject<StarSystem>::CheckFromLua(1);
	LuaTable equip(l, 2);

	if (!equip.CallMethod<bool>("IsValidSlot", "cargo")) {
		luaL_error(l, "GetCommodityBasePriceAlterations takes a valid cargo item as argument.");
		return 0;
	}
	equip.PushValueToStack("l10n_key"); // For now let's just use this poor man's hack.
	GalacticEconomy::Commodity e = static_cast<GalacticEconomy::Commodity>(
			LuaConstants::GetConstantFromArg(l, "CommodityType", -1));
	lua_pop(l, 1);
	lua_pushnumber(l, s->GetCommodityBasePriceModPercent(e));

	LUA_DEBUG_END(l, 1);
	return 1;
}
Esempio n. 13
0
int Monster::mobWield() {
    Object  *returnObject=0;
    int     i=0, found=0;

    if(objects.empty())
        return(0);

    if(ready[WIELD - 1])
        return(0);

    for(Object* obj : objects) {
        for(i=0;i<10;i++) {
            if(carry[i].info == obj->info) {
                found=1;
                break;
            }
        }

        if(!found) {
            continue;
        }

        if(obj->getWearflag() == WIELD) {
            if( (obj->damage.getNumber() + obj->damage.getSides() + obj->damage.getPlus()) <
                    (damage.getNumber() + damage.getSides() + damage.getPlus())/2 ||
                (obj->getShotsCur() < 1) )
            {
                continue;
            }

            returnObject = obj;
            break;
        }
    }
    if(!returnObject)
        return(0);

    equip(returnObject, WIELD);
    return(1);
}
Esempio n. 14
0
void Obj_Data :: To( content_array* where )
{
  event_data* event;
  room_data*   room;
  char_data*     ch;
  obj_data*     obj;
  int             i;

  if( array != NULL ) {
    roach( "Adding object somewhere which isn't nowhere." );
    roach( "-- Obj = %s", this );
    From( number );
    }

  if( ( room = Room( where->where ) ) != NULL ) {
    if( pIndexData->item_type == ITEM_CORPSE
      && value[0] > 0 ) {
      event = new event_data( execute_decay, this );
      add_queue( event, value[0] ); 
      }
    }

  if( ( ch = character( where->where ) ) != NULL
    && where == &ch->wearing ) {
    equip( ch, this );
    for( i = 0; i < ch->wearing; i++ ) {
      obj = (obj_data*) ch->wearing[i];
      if( obj->position > position 
        || ( obj->position == position
        && obj->layer > layer ) ) 
        break;
      }
    insert( *where, this, i );
    array = where; 
    }  

  Thing_Data :: To( where );
}
Esempio n. 15
0
void Shop::sell_loot(squadst& customers) const
{
   int partysize=0;
   for(int p=0;p<6;p++)
   {
      if(customers.squad[p]!=NULL)
      {
         partysize++;
      }
   }

   do
   {
      erase();

      locheader();
      printparty();

      set_color(COLOR_WHITE,COLOR_BLACK,0);
      move(10,1);
      addstr("E - Look over Equipment");

      if (location[customers.squad[0]->base]->loot.size() > 0)
         set_color(COLOR_WHITE,COLOR_BLACK,0);
      else
         set_color(COLOR_BLACK,COLOR_BLACK,1);
      move(10,40);
      addstr("F - Pawn Selectively");

      if (location[customers.squad[0]->base]->loot.size() > 0)
         set_color(COLOR_WHITE,COLOR_BLACK,0);
      else
         set_color(COLOR_BLACK,COLOR_BLACK,1);
      move(11,1);
      addstr("W - Pawn all Weapons");

      if (location[customers.squad[0]->base]->loot.size() > 0)
         set_color(COLOR_WHITE,COLOR_BLACK,0);
      else
         set_color(COLOR_BLACK,COLOR_BLACK,1);
      move(11,40);
      addstr("A - Pawn all Ammunition");

      if (location[customers.squad[0]->base]->loot.size() > 0)
         set_color(COLOR_WHITE,COLOR_BLACK,0);
      else
         set_color(COLOR_BLACK,COLOR_BLACK,1);
      move(12,1);
      addstr("C - Pawn all Clothes");

      if (location[customers.squad[0]->base]->loot.size() > 0)
         set_color(COLOR_WHITE,COLOR_BLACK,0);
      else
         set_color(COLOR_BLACK,COLOR_BLACK,1);
      move(12,40);
      addstr("L - Pawn all Loot");

      if (party_status != -1)
         set_color(COLOR_WHITE,COLOR_BLACK,0);
      else
         set_color(COLOR_BLACK,COLOR_BLACK,1);
      move(15,1);
      addstr("0 - Show the squad's Liberal status");

      if (partysize > 0 && (party_status == -1 || partysize > 1))
         set_color(COLOR_WHITE,COLOR_BLACK,0);
      else
         set_color(COLOR_BLACK,COLOR_BLACK,1);
      move(15,40);
      addstr("# - Check the status of a squad Liberal");

      set_color(COLOR_WHITE,COLOR_BLACK,0);
      move(16,40);
      addstr("Enter - Done pawning");

      int c = getch();
      translategetch(c);

      if (c == 10)
         break;

      if (c == 'e' && customers.squad[0]->base != -1)
         equip(location[customers.squad[0]->base]->loot, -1);

      if (c == 'w' || c == 'a' || c == 'c')
      {
         move(18,1);
         set_color(COLOR_WHITE,COLOR_BLACK,1);
         switch (c)
         {
            case 'w':
               addstr("Really sell all weapons? (Y)es to confirm.           ");
               break;
            case 'a':
               addstr("Really sell all ammo? (Y)es to confirm.              ");
               break;
            case 'c':
               addstr("Really sell all clothes? (Y)es to confirm.           ");
               break;
         }
         int c2 = getch();
         translategetch(c2);
         if (c2 != 'y')
         {
            c = 0;//no sale
         }
      }

      if((c == 'w' || c == 'c' || c == 'l' || c == 'a' || c == 'f') &&
         location[customers.squad[0]->base]->loot.size() > 0)
      {
         int fenceamount=0;

         if (c == 'f')
            fenceamount = fenceselect(customers);
         else
         {
            for (int l = location[customers.squad[0]->base]->loot.size() - 1; l >= 0; l--)
            {
               if (c == 'w' && location[customers.squad[0]->base]->loot[l]->is_weapon()
                   && location[customers.squad[0]->base]->loot[l]->is_good_for_sale())
               {
                  fenceamount += location[customers.squad[0]->base]->loot[l]->get_fencevalue()
                                 * location[customers.squad[0]->base]->loot[l]->get_number();
                  delete_and_remove(location[customers.squad[0]->base]->loot,l);
               }
               else if (c == 'c' && location[customers.squad[0]->base]->loot[l]->is_armor()
                        && location[customers.squad[0]->base]->loot[l]->is_good_for_sale())
               {
                  fenceamount += location[customers.squad[0]->base]->loot[l]->get_fencevalue()
                                 * location[customers.squad[0]->base]->loot[l]->get_number();
                  delete_and_remove(location[customers.squad[0]->base]->loot,l);
               }
               else if (c == 'a' && location[customers.squad[0]->base]->loot[l]->is_clip()
                        && location[customers.squad[0]->base]->loot[l]->is_good_for_sale())
               {
                  fenceamount += location[customers.squad[0]->base]->loot[l]->get_fencevalue()
                                 * location[customers.squad[0]->base]->loot[l]->get_number();
                  delete_and_remove(location[customers.squad[0]->base]->loot,l);
               }
               else if (c == 'l' && location[customers.squad[0]->base]->loot[l]->is_loot()
                        && location[customers.squad[0]->base]->loot[l]->is_good_for_sale())
               {
                  Loot* a = static_cast<Loot*>(location[customers.squad[0]->base]->loot[l]); //cast -XML
                  if(!a->no_quick_fencing())
                  {
                     fenceamount += location[customers.squad[0]->base]->loot[l]->get_fencevalue()
                                    * location[customers.squad[0]->base]->loot[l]->get_number();
                     delete_and_remove(location[customers.squad[0]->base]->loot,l);
                  }
               }
            }
         }

         if(fenceamount > 0)
         {
            set_color(COLOR_WHITE,COLOR_BLACK,1);
            move(8,1);
            addstr("You add $");
            addstr(tostring(fenceamount).c_str());
            addstr(" to Liberal Funds.");

            refresh();
            getch();

            ledger.add_funds(fenceamount,INCOME_PAWN);
         }
      }
   } while (true);
}
MarketWindow::MarketWindow(Player *player, PlayerWindow *playerWindow, const QList <const Item *> &wares)
	: player_(player), playerWindow_(playerWindow), wares_(wares)
{
	QVBoxLayout *mainLayout = new QVBoxLayout(this);
	setWindowTitle("Bazar");

	QLabel *playerItemsLabel = new QLabel("Twoje przedmioty");
	playerItemList = new QListWidget();
	playerItemList->setToolTip(QString::fromUtf8("Lista posiadanych przedmiotów."));
	QLabel *availableWaresLabel = new QLabel(QString::fromUtf8("Przedmioty dostępne na bazarze"));
	wareList = new QListWidget();
	wareList->setToolTip(QString::fromUtf8("Lista towarów dostępnych do kupienia na bazarze."));
	populateListWidgets();

	QVBoxLayout *leftPartLayout = new QVBoxLayout();
	leftPartLayout->addWidget(playerItemsLabel);
	leftPartLayout->addWidget(playerItemList);
	leftPartLayout->addWidget(availableWaresLabel);
	leftPartLayout->addWidget(wareList);

	QHBoxLayout *upperPartLayout = new QHBoxLayout();
	upperPartLayout->addLayout(leftPartLayout);

	itemDescriptionWidget = new QTextBrowser();
	itemDescriptionWidget->setToolTip(QString::fromUtf8("opis aktualnie zaznaczonego przedmiotu."));
	upperPartLayout->addWidget(itemDescriptionWidget);
	mainLayout->addLayout(upperPartLayout);

	QLabel *smallPotionIcon = new QLabel();
	smallPotionIcon->setPixmap(DataManager::pixmap(TCOA::Paths::ICON_SMALL_HEALTH_MIXTURE));
	smallPotionCountLabel = new QLabel(QString::number(player->equipment()->smallPotions()));
	smallPotionButton = new QPushButton(QString("Kup(") +
	                                    QString::number(CENA_MALEJ_MIKSTURY) +
	                                    QString(")"));
	smallPotionButton->setEnabled(player->gold() >= CENA_MALEJ_MIKSTURY);

	QLabel *largePotionIcon = new QLabel();
	largePotionIcon->setPixmap(DataManager::pixmap(TCOA::Paths::ICON_BIG_HEALTH_MIXTURE));
	largePotionCountLabel = new QLabel(QString::number(player->equipment()->largePotions()));
	largePotionButton = new QPushButton(QString("Kup(") +
	                                    QString::number(CENA_DUZEJ_MIKSTURY) +
	                                    QString(")"));
	largePotionButton->setEnabled(player->gold() >= CENA_DUZEJ_MIKSTURY);

	buyButton = new QPushButton();
	buyButton->setToolTip(QString::fromUtf8("Zależnie od okoliczności, przycisk pozwala na kupno albo sprzedaż aktualnie zaznaczonego przedmiotu."));
	buyButton->setVisible(false);
	equipButton = new QPushButton();
	equipButton->setToolTip(QString::fromUtf8("Zależnie od okoliczności, przycisk pozwala na założenie albo zdjęcie aktualnie zaznaczonego przedmiotu z Twojej postaci."));
	equipButton->setVisible(false);
	confirmButton = new QPushButton("Ok");

	QHBoxLayout *bottomPartLayout = new QHBoxLayout();
	bottomPartLayout->addWidget(smallPotionIcon);
	bottomPartLayout->addWidget(smallPotionCountLabel);
	bottomPartLayout->addWidget(smallPotionButton);
	bottomPartLayout->addWidget(largePotionIcon);
	bottomPartLayout->addWidget(largePotionCountLabel);
	bottomPartLayout->addWidget(largePotionButton);
	bottomPartLayout->addStretch();
	bottomPartLayout->addWidget(buyButton);
	bottomPartLayout->addWidget(equipButton);
	bottomPartLayout->addWidget(confirmButton);
	mainLayout->addLayout(bottomPartLayout);

	connect(wareList, SIGNAL(clicked(const QModelIndex &)), this, SLOT(displayMarketItem(const QModelIndex &)));
	connect(playerItemList, SIGNAL(clicked(const QModelIndex &)), this, SLOT(displayPlayerItem(const QModelIndex &)));

	connect(smallPotionButton, SIGNAL(clicked()), this, SLOT(buySmallPotion()));
	connect(largePotionButton, SIGNAL(clicked()), this, SLOT(buyLargePotion()));
	connect(confirmButton, SIGNAL(clicked()), this, SLOT(close()));
	connect(equipButton, SIGNAL(clicked()), this, SLOT(equip()));
	connect(buyButton, SIGNAL(clicked()), this, SLOT(buy()));
}
Esempio n. 17
0
void psClientCharManager::HandleEquipment(MsgEntry* me)
{
    psEquipmentMessage equip(me);
    unsigned int playerID = equip.player;

    GEMClientActor* object = (GEMClientActor*)cel->FindObject(playerID);
    if (!object)
    {
        Error2("Got equipment for actor %d, but couldn't find it!", playerID);
        return;
    }

    Debug2(LOG_CELPERSIST,0,"Got equipment for actor %d", playerID);


    csString slotname(psengine->slotName.GetName(equip.slot));

    //If the mesh has a $ it means it's an helm ($H) / bracher ($B) / belt ($E) / cloak ($C) so search for replacement
    equip.mesh.ReplaceAll("$H",object->helmGroup);
    equip.mesh.ReplaceAll("$B",object->BracerGroup);
    equip.mesh.ReplaceAll("$E",object->BeltGroup);
    equip.mesh.ReplaceAll("$C",object->CloakGroup);

    // Update any doll views registered for changes
    csArray<iPAWSSubscriber*> dolls = PawsManager::GetSingleton().ListSubscribers("sigActorUpdate");
    for (size_t i=0; i<dolls.GetSize(); i++)
    {
        if (dolls[i] == NULL)
            continue;
        pawsObjectView* doll = dynamic_cast<pawsObjectView*>(dolls[i]);

        if (doll == NULL)
            continue;
        if (doll->GetID() == playerID) // This is a doll of the updated object
        {
            iMeshWrapper* dollObject = doll->GetObject();
            if (dollObject == NULL)
            {
                Error2("Cannot update registered doll view with ID %d because it has no object", doll->GetID());
                continue;
            }
            psCharAppearance* p = doll->GetCharApp();
            p->Clone(object->CharAppearance());
            p->SetMesh(dollObject);
            if (equip.type == psEquipmentMessage::EQUIP)
            {
                p->Equip(slotname,equip.mesh,equip.part,equip.partMesh,equip.texture,equip.removedMesh);
            }
            else
            {
                p->Dequip(slotname,equip.mesh,equip.part,equip.partMesh,equip.texture,equip.removedMesh);
            }
        }
    }

    // Update the actor
    if (equip.type == psEquipmentMessage::EQUIP)
    {
        object->CharAppearance()->Equip(slotname,equip.mesh,equip.part,equip.partMesh,equip.texture,equip.removedMesh);
    }
    else
    {
        object->CharAppearance()->Dequip(slotname,equip.mesh,equip.part,equip.partMesh,equip.texture,equip.removedMesh);
    }
}
Esempio n. 18
0
void activate(Creature *cr)
{
   int hostagecount=0;
   int state=0;
   int choice=0;
   char havedead=0;
   for(int p=0;p<pool.size();p++)
   {
      if(pool[p]->alive&&pool[p]->align!=1&&pool[p]->location==cr->location)hostagecount++;
      if(!pool[p]->alive)havedead=1;
   }

   do
   {
      erase();

      set_color(COLOR_WHITE,COLOR_BLACK,0);
      printfunds(0,1,"Money: ");

      move(0,0);
     if (cr->income)
     {
        addstr(cr->name);
        addstr(" made $");
        char num[20];
        itoa(cr->income,num,10);
        addstr(num);
        addstr(" yesterday. What now?");
     }
     else
     {
        addstr("Taking Action: What will ");
        addstr(cr->name);
        addstr(" be doing today?");
     }

      printcreatureinfo(cr);

      makedelimiter(8,0);

      set_color(COLOR_WHITE,COLOR_BLACK,state=='a');
      move(10,1);
      addstr("A - Engaging in Liberal Activism");

      set_color(COLOR_WHITE,COLOR_BLACK,state=='b');
      move(11,1);
      addstr("B - Legal Fundraising");

      set_color(COLOR_WHITE,COLOR_BLACK,state=='c');
      move(12,1);
      addstr("C - Illegal Fundraising");

      set_color(COLOR_WHITE,COLOR_BLACK,state=='d');
      move(13,1);
      addstr("D - Make/Repair Clothing");

      if(cr->get_skill(SKILL_FIRSTAID)!=0)
      {
         set_color(COLOR_WHITE,COLOR_BLACK,(cr->activity.type==ACTIVITY_HEAL||cr->activity.type==ACTIVITY_NONE)&&state==0);
      }
      else
      {
         set_color(COLOR_BLACK,COLOR_BLACK,1);
      }
      move(14,1);
      addstr("H - Heal Liberals");

      move(15,1);
      if(cr->canwalk())
      {
         set_color(COLOR_WHITE,COLOR_BLACK,cr->activity.type==ACTIVITY_STEALCARS&&state==0);
         addstr("S - Stealing a Car");
      }
      else
      {
         if(!(cr->flag & CREATUREFLAG_WHEELCHAIR))set_color(COLOR_WHITE,COLOR_BLACK,cr->activity.type==ACTIVITY_WHEELCHAIR&&state==0);
         else set_color(COLOR_BLACK,COLOR_BLACK,1);
         addstr("S - Procuring a Wheelchair");
      }

      set_color(COLOR_WHITE,COLOR_BLACK,state=='t');
      move(16,1);
      addstr("T - Teaching Other Liberals");

     if(hostagecount>0)set_color(COLOR_WHITE,COLOR_BLACK,cr->activity.type==ACTIVITY_HOSTAGETENDING&&state==0);
      else set_color(COLOR_BLACK,COLOR_BLACK,1);
      move(17,1);
      addstr("I - Tend to a Conservative hostage");

      if(clinictime(*cr))
     {
        set_color(COLOR_WHITE,COLOR_BLACK,cr->activity.type==ACTIVITY_CLINIC&&state==0);
        move(18,1);
        addstr("M - Move to the Free CLINIC");
     }
      else
     {
        set_color(COLOR_WHITE,COLOR_BLACK,state=='l');
        move(18,1);
        addstr("L - Learn in the University District");
     }
      

      if(havedead)set_color(COLOR_WHITE,COLOR_BLACK,cr->activity.type==ACTIVITY_BURY&&state==0);
      else set_color(COLOR_BLACK,COLOR_BLACK,1);
      move(19,1);
      addstr("Z - Dispose of bodies");

     siegest *siege=NULL;
      if(selectedsiege!=-1)siege=&location[selectedsiege]->siege;
      if(activesquad!=NULL && activesquad->squad[0]->location!=-1)siege=&location[activesquad->squad[0]->location]->siege;
      char sieged=0;
      if(siege!=NULL)sieged=siege->siege;
      char underattack=0;
      if(siege!=NULL)
      {
         if(sieged)underattack=siege->underattack;
      }

     if (!sieged)
     {
         set_color(COLOR_WHITE,COLOR_BLACK,0);
        move(20,1);
        addstr("E - Equip this Liberal");
     }

      if(state == 'a' || state == 'b' || state == 'c' ||state == 'd' )
      {
         set_color(COLOR_WHITE,COLOR_BLACK,0);
         move(19,40);
         addstr("? - Help");
      }

      set_color(COLOR_WHITE,COLOR_BLACK,0);
      move(20,40);
      addstr("Enter - Confirm Selection");

      set_color(COLOR_WHITE,COLOR_BLACK,0);
      move(21,1);
      addstr("X - Nothing for Now");

      switch(state)
      {
      case 'a':
         set_color(COLOR_WHITE,COLOR_BLACK,cr->activity.type==ACTIVITY_COMMUNITYSERVICE);
         move(10,40);
         addstr("1 - Community Service");

         set_color(COLOR_WHITE,COLOR_BLACK,cr->activity.type==ACTIVITY_TROUBLE);
         move(11,40);
         addstr("2 - Liberal Disobedience");

         set_color(COLOR_WHITE,COLOR_BLACK,cr->activity.type==ACTIVITY_GRAFFITI);
         move(12,40);
         addstr("3 - Graffiti");

         set_color(COLOR_WHITE,COLOR_BLACK,cr->activity.type==ACTIVITY_POLLS);
         move(13,40);
         addstr("4 - Search Opinion Polls");

         //set_color(COLOR_WHITE,COLOR_BLACK,cr->activity.type==ACTIVITY_DOS_ATTACKS);
         //move(14,40);
         //addstr("5 - Harass Websites");

         set_color(COLOR_WHITE,COLOR_BLACK,cr->activity.type==ACTIVITY_HACKING);
         move(14,40);
         addstr("5 - Hacking");

         set_color(COLOR_WHITE,COLOR_BLACK,cr->activity.type==ACTIVITY_WRITE_LETTERS);
         move(15,40);
         addstr("6 - Write to Newspapers");

         if(cr->location!=-1&&
            location[cr->location]->compound_walls & COMPOUND_PRINTINGPRESS)
         {
            set_color(COLOR_WHITE,COLOR_BLACK,cr->activity.type==ACTIVITY_WRITE_GUARDIAN);
            move(16,40);
            addstr("7 - Write for The Liberal Guardian");
         }
         break;
      case 'b':
         set_color(COLOR_WHITE,COLOR_BLACK,cr->activity.type==ACTIVITY_DONATIONS);
         move(10,40);
         addstr("1 - Solicit Donations");

         set_color(COLOR_WHITE,COLOR_BLACK,cr->activity.type==ACTIVITY_SELL_TSHIRTS);
         move(11,40);
         if(cr->get_skill(SKILL_TAILORING)>=8)
            addstr("2 - Sell Liberal T-Shirts");
         else if(cr->get_skill(SKILL_TAILORING)>=4)
            addstr("2 - Sell Embroidered Shirts");
         else
            addstr("2 - Sell Tie-Dyed T-Shirts");

         set_color(COLOR_WHITE,COLOR_BLACK,cr->activity.type==ACTIVITY_SELL_ART);
         move(12,40);
         if(cr->get_skill(SKILL_ART)>=8)
            addstr("3 - Sell Liberal Art");
         else if(cr->get_skill(SKILL_ART)>=4)
            addstr("3 - Sell Paintings");
         else
            addstr("3 - Sell Portrait Sketches");

         set_color(COLOR_WHITE,COLOR_BLACK,cr->activity.type==ACTIVITY_SELL_MUSIC);
         move(13,40);
         if(cr->get_skill(SKILL_MUSIC)>8)
            addstr("4 - Play Liberal Music");
         else
            addstr("4 - Play Street Music");
         break;
      case 'c':
         set_color(COLOR_WHITE,COLOR_BLACK,cr->activity.type==ACTIVITY_SELL_DRUGS);
         move(10,40);
         addstr("1 - Sell Brownies");

         set_color(COLOR_WHITE,COLOR_BLACK,cr->activity.type==ACTIVITY_PROSTITUTION);
         move(11,40);
         if(cr->age < 18)
            set_color(COLOR_BLACK, COLOR_BLACK, 1);    //Grayed out for minors
         addstr("2 - Prostitution");

         set_color(COLOR_WHITE,COLOR_BLACK,cr->activity.type==ACTIVITY_CCFRAUD);
         move(12,40);
         addstr("3 - Steal Credit Card Numbers");

         /*set_color(COLOR_WHITE,COLOR_BLACK,cr->activity.type==ACTIVITY_DOS_RACKET);
         move(13,40);
         addstr("4 - Electronic Protection Racket");*/
         break;
      case 'd':
         set_color(COLOR_WHITE,COLOR_BLACK,cr->activity.type==ACTIVITY_MAKE_ARMOR);
         move(10,40);
         addstr("1 - Make Clothing");

         set_color(COLOR_WHITE,COLOR_BLACK,cr->activity.type==ACTIVITY_REPAIR_ARMOR);
         move(11,40);
         addstr("2 - Repair Clothing");
         break;
      case 't':
         set_color(COLOR_WHITE,COLOR_BLACK,0);
         move(10,40);
         addstr("Teach Liberals About What?");

         set_color(COLOR_WHITE,COLOR_BLACK,cr->activity.type==ACTIVITY_TEACH_POLITICS);
         move(12,40);
         addstr("1 - Political Activism");

         set_color(COLOR_WHITE,COLOR_BLACK,cr->activity.type==ACTIVITY_TEACH_COVERT);
         move(13,40);
         addstr("2 - Infiltration");

         set_color(COLOR_WHITE,COLOR_BLACK,cr->activity.type==ACTIVITY_TEACH_FIGHTING);
         move(14,40);
         addstr("3 - Urban Warfare");
       break;
     case 'l':
       listclasses(cr);
       break;
      }

      set_color(COLOR_WHITE,COLOR_BLACK,0);
      switch(cr->activity.type)
      {
      case ACTIVITY_COMMUNITYSERVICE:
         move(22,3);
         addstr(cr->name);
         addstr(" will help the elderly, local library, anything");
         move(23,1);
         addstr("  that is liberal.");
         break;
      case ACTIVITY_TROUBLE:
         move(22,3);
         addstr(cr->name);
         addstr(" will create public disturbances. ");
         break;
      case ACTIVITY_GRAFFITI:
         move(22,3);
         addstr(cr->name);
         addstr(" will spray political graffiti. Art and Heart will");
         move(23,1);
         addstr("  enhance the liberal effect.");
         break;
      case ACTIVITY_POLLS:
         move(22,3);
         addstr(cr->name);
         addstr(" will search the internet for public opinion polls.");
         move(23,1);
         addstr("  Polls will give an idea on how the liberal agenda is going. Computers");
         move(24,1);
         addstr("  and intelligence will provide better results.");
         break;
      case ACTIVITY_DOS_ATTACKS:
         move(22,3);
         addstr(cr->name);
         addstr(" will harass Conservative websites. Computer skill");
         move(23,1);
         addstr("  will give greater effect.");
         break;
      case ACTIVITY_HACKING:
         move(22,3);
         addstr(cr->name);
         addstr(" will harass websites and hack private networks.");
         move(23,1);
         addstr("  Computer skill and intelligence will give more frequent results.");
         move(24,1);
         addstr("  Multiple hackers will increase chances of both success and detection.");
         break;
      case ACTIVITY_WRITE_LETTERS:
         move(22,3);
         addstr(cr->name);
         addstr(" will write letters to newspapers about current events.");
         break;
      case ACTIVITY_WRITE_GUARDIAN:
         move(22,3);
         addstr(cr->name);
         addstr(" will write articles for the LCS's newspaper.");
         break;
      case ACTIVITY_DONATIONS:
         move(22,3);
         addstr(cr->name);
         addstr(" will walk around and ask for donations to the LCS.");
         move(23,1);
         addstr("  Based on persuasion, public's view on the cause, and how well dressed the");
         move(24,1);
         addstr("  activist is.");
         break;
      case ACTIVITY_SELL_TSHIRTS:
         move(22,3);
         addstr(cr->name);
         if(cr->get_skill(SKILL_TAILORING)>=8)
            addstr(" will print and distribute shirts with Liberal slogans.");
         else if(cr->get_skill(SKILL_TAILORING)>=4)
            addstr(" will embroider shirts and sell them on the street.");
         else
            addstr(" will tie-dye T-shirts and sell them on the street.");
         break;
      case ACTIVITY_SELL_ART:
         move(22,3);
         addstr(cr->name);
         if(cr->get_skill(SKILL_ART)>=8)
            addstr(" will create and sell paintings embracing the Liberal agenda.");
         else if(cr->get_skill(SKILL_ART)>=4)
            addstr(" will make pretty paintings and sell them on the streets.");
         else
            addstr(" will sketch people and sell portraits back to them.");
         break;
      case ACTIVITY_SELL_MUSIC:
         move(22,3);
         addstr(cr->name);
         addstr(" will go out into the streets and drum on buckets,");
         move(23,1);
         addstr("  or play guitar if one is equipped.");
         break;
      case ACTIVITY_SELL_DRUGS:
         move(22,3);
         addstr(cr->name);
         addstr(" will bake and sell special adult brownies that open");
         move(23,1);
         addstr("  magical shimmering doorways to the adamantium pits.");
         break;
      case ACTIVITY_PROSTITUTION:
         move(22,3);
         addstr(cr->name);
         addstr(" will trade sex for money.");
         break;
      case ACTIVITY_CCFRAUD:
         move(22,3);
         addstr(cr->name);
         addstr(" will commit credit card fraud online.");
         break;
      case ACTIVITY_DOS_RACKET:
         move(22,3);
         addstr(cr->name);
         addstr(" will demand money in exchange for not bringing down");
         move(23,1);
         addstr("major websites.");
         break;
      case ACTIVITY_TEACH_POLITICS:
         move(22,1);
         addstr("  Skills Trained: Writing, Persuasion, Law, Street Sense, Science,");
         move(23,1);
         addstr("    Religion, Business, Music, Art");
         move(24,1);
         addstr("  Classes cost up to $20/day to conduct. All Liberals able will attend.");
         break;
      case ACTIVITY_TEACH_COVERT:
         move(22,1);
         addstr("  Skills Trained: Computers, Security, Stealth, Disguise, Tailoring,");
         move(23,1);
         addstr("    Seduction, Psychology, Driving");
         move(24,1);
         addstr("  Classes cost up to $60/day to conduct. All Liberals able will attend.");
         break;
      case ACTIVITY_TEACH_FIGHTING:
         move(22,1);
         addstr("  Skills Trained: All Weapon Skills, Martial Arts, Dodge, First Aid");
         move(24,1);
         addstr("  Classes cost up to $100/day to conduct. All Liberals able will attend.");
         break;
      case ACTIVITY_STUDY_DEBATING:
      case ACTIVITY_STUDY_MARTIAL_ARTS:
      case ACTIVITY_STUDY_DRIVING:
      case ACTIVITY_STUDY_PSYCHOLOGY:
      case ACTIVITY_STUDY_FIRST_AID:
      case ACTIVITY_STUDY_LAW:
      case ACTIVITY_STUDY_DISGUISE:
      case ACTIVITY_STUDY_SCIENCE:
      case ACTIVITY_STUDY_BUSINESS:
      //case ACTIVITY_STUDY_COOKING:
      case ACTIVITY_STUDY_GYMNASTICS:
      case ACTIVITY_STUDY_WRITING:
      case ACTIVITY_STUDY_ART:
      case ACTIVITY_STUDY_MUSIC:
      case ACTIVITY_STUDY_TEACHING:
      case ACTIVITY_STUDY_LOCKSMITHING:
         move(22,3);
         addstr(cr->name);
         addstr(" will attend classes in the University District");
         move(23,1);
         addstr("  at a cost of $60 a day.");
         break;
      }

      refresh();
      int c=getch();
      translategetch(c);



      if(c>='a'&&c<='z'){state=c;}
      if((c>='a'&&c<='z') || (c>='1'&&c<='9'))
      {
         choice=c;
         switch(state)
         {
         case 'a':
            switch(choice)
            {
            case '1':cr->activity.type=ACTIVITY_COMMUNITYSERVICE;break;
            case '2':cr->activity.type=ACTIVITY_TROUBLE;break;
            case '3':cr->activity.type=ACTIVITY_GRAFFITI;
               cr->activity.arg=-1;
               break;
            case '4':cr->activity.type=ACTIVITY_POLLS;break;
            //case '5':cr->activity.type=ACTIVITY_DOS_ATTACKS;break;
            case '5':cr->activity.type=ACTIVITY_HACKING;break;
            case '6':cr->activity.type=ACTIVITY_WRITE_LETTERS;break;
            case '7':
               if(cr->location!=-1&&
                  location[cr->location]->compound_walls & COMPOUND_PRINTINGPRESS)
               {
                  cr->activity.type=ACTIVITY_WRITE_GUARDIAN;break;
               }
            default:
               if(cr->get_attribute(ATTRIBUTE_WISDOM,true)>7)
               {
                  cr->activity.type=ACTIVITY_COMMUNITYSERVICE;
                  choice='1';
               }
               else if(cr->get_attribute(ATTRIBUTE_WISDOM,true)>4)
               {
                  cr->activity.type=ACTIVITY_TROUBLE;
                  choice='2';
               }
               else
               {
                  if(cr->get_skill(SKILL_COMPUTERS)>2)
                  {
                     cr->activity.type=ACTIVITY_HACKING;
                     choice='5';
                  }
                  else if(cr->get_skill(SKILL_ART)>1)
                  {
                     cr->activity.type=ACTIVITY_GRAFFITI;
                     cr->activity.arg=-1;
                     choice='3';
                  }
                  else
                  {
                     cr->activity.type=ACTIVITY_TROUBLE;
                     choice='2';
                  }
               }
            }
            break;
         case 'b':
            switch(choice)
            {
            case '1':cr->activity.type=ACTIVITY_DONATIONS;break;
            case '2':cr->activity.type=ACTIVITY_SELL_TSHIRTS;break;
            case '3':cr->activity.type=ACTIVITY_SELL_ART;break;
            case '4':cr->activity.type=ACTIVITY_SELL_MUSIC;break;
            default:
               if(cr->get_skill(SKILL_ART)>1)
               {
                  cr->activity.type=ACTIVITY_SELL_ART;
                  choice='3';
               }
               else if(cr->get_skill(SKILL_TAILORING)>1)
               {
                  cr->activity.type=ACTIVITY_SELL_TSHIRTS;
                  choice='2';
               }
               else if(cr->get_skill(SKILL_MUSIC)>1)
               {
                  cr->activity.type=ACTIVITY_SELL_MUSIC;
                  choice='4';
               }
               else
               {
                  cr->activity.type=ACTIVITY_DONATIONS;
                  choice='1';
               }
            }
            break;
         case 'c':
            switch(choice)
            {
            case '1':cr->activity.type=ACTIVITY_SELL_DRUGS;break;
            case '2':
               if(cr->age >= 18) cr->activity.type=ACTIVITY_PROSTITUTION;break;
            case '3':cr->activity.type=ACTIVITY_CCFRAUD;break;
               //case '4':cr->activity.type=ACTIVITY_DOS_RACKET;break;
            default:
               if(cr->get_skill(SKILL_COMPUTERS)>1)
               {
                  cr->activity.type=ACTIVITY_CCFRAUD;
                  choice='3';
               }
               else if(cr->get_skill(SKILL_SEDUCTION)>1 && cr->age >= 18)
               {
                  cr->activity.type=ACTIVITY_PROSTITUTION;
                  choice='2';
               }
               else
               {
                  cr->activity.type=ACTIVITY_SELL_DRUGS;
                  choice='1';
               }
            }
            break;
         case 'd':
            switch(choice)
            {
            case '1':break;
            case '2':cr->activity.type=ACTIVITY_REPAIR_ARMOR;choice='2';break;
            default:cr->activity.type=ACTIVITY_REPAIR_ARMOR;choice='2';break;
            }
            break;
       case 'l':
          updateclasschoice(cr, choice);
          break;
         case 't':
            switch(choice)
            {
            case '1':cr->activity.type=ACTIVITY_TEACH_POLITICS;break;
            case '2':cr->activity.type=ACTIVITY_TEACH_COVERT;break;
            case '3':cr->activity.type=ACTIVITY_TEACH_FIGHTING;break;
            default:
               switch(cr->type)
               {
               case CREATURE_MERC:
               case CREATURE_SWAT:
               case CREATURE_DEATHSQUAD:
               case CREATURE_GANGUNIT:
               case CREATURE_SOLDIER:
               case CREATURE_VETERAN:
               case CREATURE_HARDENED_VETERAN:
               case CREATURE_GANGMEMBER:
               case CREATURE_MUTANT:
               case CREATURE_CRACKHEAD:
                  cr->activity.type=ACTIVITY_TEACH_FIGHTING;
                  choice='2';
                  break;
               case CREATURE_AGENT:
               case CREATURE_AMATEURMAGICIAN:
               case CREATURE_THIEF:
               case CREATURE_PROSTITUTE:
               case CREATURE_PRISONER:
                  cr->activity.type=ACTIVITY_TEACH_COVERT;
                  choice='3';
                  break;
               default:
                  cr->activity.type=ACTIVITY_TEACH_POLITICS;
                  choice='1';
                  break;
               }
               break;
            }
            break;
         }
      }

      if(c=='h'&&cr->get_skill(SKILL_FIRSTAID)!=0)
      {
         cr->activity.type=ACTIVITY_HEAL;
         break;
      }
      if(state=='d'&&choice=='1')
      {
         activityst oact=cr->activity;
         cr->activity.type=ACTIVITY_NONE;
         select_makeclothing(cr);
         if(cr->activity.type==ACTIVITY_MAKE_ARMOR)break;
         else cr->activity=oact;
      }
      if(c=='i'&&hostagecount>0)
      {
         activityst oact=cr->activity;
         cr->activity.type=ACTIVITY_NONE;
         select_tendhostage(cr);
         if(cr->activity.type==ACTIVITY_HOSTAGETENDING)break;
         else cr->activity=oact;
      }
      if (!sieged && c == 'e')
      {
         //create a temp squad containing just this liberal
         int oldsquadid = cr->squadid;
         squadst *oldactivesquad = activesquad;
         activesquad=new squadst;
         strcpy(activesquad->name, "Temporary Squad");
         activesquad->id=cursquadid;
         activesquad->squad[0]=cr;
         cr->squadid = activesquad->id;
         //go to equipment screen
         equip(location[activesquad->squad[0]->location]->loot,-1);
         //once you're done, restore original squad status.
         delete activesquad;
         activesquad = oldactivesquad;
         cr->squadid = oldsquadid;
      }
      if(c=='s')
      {
         if(cr->canwalk())
         {
            cr->activity.type=ACTIVITY_STEALCARS;
            break;
         }
         else if(!(cr->flag & CREATUREFLAG_WHEELCHAIR))
         {
            cr->activity.type=ACTIVITY_WHEELCHAIR;
            break;
         }
      }
      /*if(c=='w'&&location[cr->location]->compound_walls==COMPOUND_PRINTINGPRESS)
      {
      activityst oact=cr->activity;
      cr->activity.type=ACTIVITY_NONE;
      if(select_view(cr,cr->activity.arg))
      cr->activity.type=ACTIVITY_WRITE_GUARDIAN;
      else cr->activity=oact;
      break;
      }*/
      if(c=='m'&&clinictime(*cr))
      {
         cr->activity.type=ACTIVITY_CLINIC;
         break;
      }
      if(c=='z'&&havedead)
      {
         cr->activity.type=ACTIVITY_BURY;
         break;
      }
      if(c=='x')
      {
         cr->activity.type=ACTIVITY_NONE;
         break;
      }
      // Enter pressed
      if(c==10||c==ESC)
      {
         break;
      }
      // ? Pressed
      if(c==63)
      {     
         if(state == 'a' || state == 'b' || state == 'c' ||state == 'd' )
         {
            // Call activity help pages
            HelpActivities(cr->activity.type);
         }
      }
   }while(1);
}
Esempio n. 19
0
void Shop::browse_halfscreen(squadst& customers, int& buyer) const
{
   unsigned page = 0;
   const unsigned max_entries_per_page = 20;

   std::vector<ShopOption*> available_options = options_;

   available_options.erase (remove_if (available_options.begin(),
				       available_options.end(),
				       not1 (mem_fun (&ShopOption::display))),
			    available_options.end());

   int partysize = 0;
   for (int p = 0; p < 6; ++p)
   {
      if(customers.squad[p] != NULL)
      {
         partysize++;
      }
   }

   do
   {
      erase();
      set_color(COLOR_WHITE,COLOR_BLACK,0);

      locheader();
      printparty();

      move(8,45);
      addstr("Buyer: ");
      addstr(customers.squad[buyer]->name);

      //Write wares and prices
      int yline = 10;
      int column = 1;
      int taken_letters = 0;
      for (unsigned p = page * (max_entries_per_page - 1);
           p < available_options.size() && p < page * (max_entries_per_page - 1) + max_entries_per_page;
           ++p)
      {
         if (available_options[p]->is_available())
            set_color(COLOR_WHITE,COLOR_BLACK,0);
         else
            set_color(COLOR_BLACK,COLOR_BLACK,1);
         if (column == 1)
            move(yline,1);
         else
            move(yline,40);

         if (available_options[p]->letter_defined_)
            addch(available_options[p]->showletter());
         else
         {
            // Find an available letter to use for this ware.
            bool done = false;
            while (taken_letters < 27 && !done)
            {
               done = true;
               if ('a' + taken_letters == 'b' || // Letters used by the shop UI are disallowed.
                   'a' + taken_letters == 'e' ||
                   ('a' + taken_letters == 's' && allow_selling_) ||
                   ('a' + taken_letters == 'm' && sell_masks_))
               {
                  ++taken_letters;
                  done = false;
                  continue;
               }
               for (unsigned i = 0; i < available_options.size(); ++i)
               {
                  if (available_options[i]->letter_defined_ &&
                      'a' + taken_letters == available_options[i]->letter_)
                  {
                     ++taken_letters;
                     done = false;
                     break;
                  }
               }
            }
            available_options[p]->letter_ = 'a' + taken_letters;
            addch('A' + taken_letters);
            ++taken_letters;
         }

         addstr(" - ");
         addstr(available_options[p]->get_description_halfscreen().c_str());
         if (column == 1)
            column = 2;
         else
         {
            ++yline;
            column = 1;
         }
      }
      if (sell_masks_)
      {
         move(yline,1+(column-1)*39);
         if (ledger.get_funds() >= 15)
            set_color(COLOR_WHITE,COLOR_BLACK,0);
         else
            set_color(COLOR_BLACK,COLOR_BLACK,1);
         addstr("M - Buy a Mask                ($15)");
      }
      if (column == 2)
         ++yline;

      set_color(COLOR_WHITE,COLOR_BLACK,0);
      move(yline,1);
      addstr("E - Look over Equipment");
      ++yline;

      if (allow_selling_)
      {
         move(yline,1);
         if (location[customers.squad[0]->base]->loot.size() > 0)
            set_color(COLOR_WHITE,COLOR_BLACK,0);
         else
            set_color(COLOR_BLACK,COLOR_BLACK,1);
         addstr("S - Sell something");
         ++yline;
      }

      ++yline;

      if (party_status != -1)
         set_color(COLOR_WHITE,COLOR_BLACK,0);
      else
         set_color(COLOR_BLACK,COLOR_BLACK,1);
      move(yline,1);
      addstr("0 - Show the squad's Liberal status");

      if (partysize > 0 && (party_status == -1 || partysize > 1))
         set_color(COLOR_WHITE,COLOR_BLACK,0);
      else
         set_color(COLOR_BLACK,COLOR_BLACK,1);
      move(yline++,40);
      addstr("# - Check the status of a squad Liberal");

      if (partysize >= 2)
         set_color(COLOR_WHITE,COLOR_BLACK,0);
      else
         set_color(COLOR_BLACK,COLOR_BLACK,1);
      move(yline,1);
      addstr("B - Choose a buyer");

      set_color(COLOR_WHITE,COLOR_BLACK,0);
      move(yline,40);
      addstr("Enter - ");
      addstr(exit_.c_str());



      int c = getch();
      translategetch(c);

      for (unsigned i = 0; i < available_options.size(); ++i)
      {
         if (c == available_options[i]->letter_)
         {
            available_options[i]->choose(customers, buyer);
            break;
         }
      }

      if(c == 'e' && customers.squad[0]->base != -1)
         equip(location[customers.squad[0]->base]->loot, -1);
      else if (c == 's' && allow_selling_
               && location[customers.squad[0]->base]->loot.size() > 0)
         sell_loot(customers);
      else if (c == 'm' && sell_masks_ && ledger.get_funds() >= 15)
      {
         maskselect(*customers.squad[buyer]);
      }
      else if (c == 'b')
         choose_buyer(customers, buyer);
      else if (c == '0')
         party_status=-1;
      else if ( c >= '1' && c <= '6')
      {
         if (customers.squad[c-'1'] != NULL)
         {
            if (party_status == c - '1')
               fullstatus(party_status);
            else
               party_status = c - '1';
         }
      }
      else if (c == 10)
         break;

   } while (true);
}
Esempio n. 20
0
void Pi::HandleKeyDown(SDL_Keysym *key)
{
	if (key->sym == SDLK_ESCAPE) {
		if (Pi::game) {
			// only accessible once game started
			HandleEscKey();
		}
		return;
	}
	const bool CTRL = input.KeyState(SDLK_LCTRL) || input.KeyState(SDLK_RCTRL);

	// special keys.
	if (CTRL) {
		switch (key->sym) {
		case SDLK_q: // Quit
			Pi::RequestQuit();
			break;
		case SDLK_PRINTSCREEN: // print
		case SDLK_KP_MULTIPLY: // screen
		{
			char buf[256];
			const time_t t = time(0);
			struct tm *_tm = localtime(&t);
			strftime(buf, sizeof(buf), "screenshot-%Y%m%d-%H%M%S.png", _tm);
			Graphics::ScreendumpState sd;
			Pi::renderer->Screendump(sd);
			write_screenshot(sd, buf);
			break;
		}

		case SDLK_SCROLLLOCK: // toggle video recording
			Pi::isRecordingVideo = !Pi::isRecordingVideo;
			if (Pi::isRecordingVideo) {
				char videoName[256];
				const time_t t = time(0);
				struct tm *_tm = localtime(&t);
				strftime(videoName, sizeof(videoName), "pioneer-%Y%m%d-%H%M%S", _tm);
				const std::string dir = "videos";
				FileSystem::userFiles.MakeDirectory(dir);
				const std::string fname = FileSystem::JoinPathBelow(FileSystem::userFiles.GetRoot() + "/" + dir, videoName);
				Output("Video Recording started to %s.\n", fname.c_str());
				// start ffmpeg telling it to expect raw rgba 720p-60hz frames
				// -i - tells it to read frames from stdin
				// if given no frame rate (-r 60), it will just use vfr
				char cmd[256] = { 0 };
				snprintf(cmd, sizeof(cmd), "ffmpeg -f rawvideo -pix_fmt rgba -s %dx%d -i - -threads 0 -preset fast -y -pix_fmt yuv420p -crf 21 -vf vflip %s.mp4", config->Int("ScrWidth"), config->Int("ScrHeight"), fname.c_str());

				// open pipe to ffmpeg's stdin in binary write mode
#if defined(_MSC_VER) || defined(__MINGW32__)
				Pi::ffmpegFile = _popen(cmd, "wb");
#else
				Pi::ffmpegFile = _popen(cmd, "w");
#endif
			} else {
				Output("Video Recording ended.\n");
				if (Pi::ffmpegFile != nullptr) {
					_pclose(Pi::ffmpegFile);
					Pi::ffmpegFile = nullptr;
				}
			}
			break;
#if WITH_DEVKEYS
		case SDLK_i: // Toggle Debug info
			Pi::showDebugInfo = !Pi::showDebugInfo;
			break;

#ifdef PIONEER_PROFILER
		case SDLK_p: // alert it that we want to profile
			if (input.KeyState(SDLK_LSHIFT) || input.KeyState(SDLK_RSHIFT))
				Pi::doProfileOne = true;
			else {
				Pi::doProfileSlow = !Pi::doProfileSlow;
				Output("slow frame profiling %s\n", Pi::doProfileSlow ? "enabled" : "disabled");
			}
			break;
#endif

		case SDLK_F12: {
			if (Pi::game) {
				vector3d dir = -Pi::player->GetOrient().VectorZ();
				/* add test object */
				if (input.KeyState(SDLK_RSHIFT)) {
					Missile *missile =
						new Missile(ShipType::MISSILE_GUIDED, Pi::player);
					missile->SetOrient(Pi::player->GetOrient());
					missile->SetFrame(Pi::player->GetFrame());
					missile->SetPosition(Pi::player->GetPosition() + 50.0 * dir);
					missile->SetVelocity(Pi::player->GetVelocity());
					game->GetSpace()->AddBody(missile);
					missile->AIKamikaze(Pi::player->GetCombatTarget());
				} else if (input.KeyState(SDLK_LSHIFT)) {
					SpaceStation *s = static_cast<SpaceStation *>(Pi::player->GetNavTarget());
					if (s) {
						Ship *ship = new Ship(ShipType::POLICE);
						int port = s->GetFreeDockingPort(ship);
						if (port != -1) {
							Output("Putting ship into station\n");
							// Make police ship intent on killing the player
							ship->AIKill(Pi::player);
							ship->SetFrame(Pi::player->GetFrame());
							ship->SetDockedWith(s, port);
							game->GetSpace()->AddBody(ship);
						} else {
							delete ship;
							Output("No docking ports free dude\n");
						}
					} else {
						Output("Select a space station...\n");
					}
				} else {
					Ship *ship = new Ship(ShipType::POLICE);
					if (!input.KeyState(SDLK_LALT)) { //Left ALT = no AI
						if (!input.KeyState(SDLK_LCTRL))
							ship->AIFlyTo(Pi::player); // a less lethal option
						else
							ship->AIKill(Pi::player); // a really lethal option!
					}
					lua_State *l = Lua::manager->GetLuaState();
					pi_lua_import(l, "Equipment");
					LuaTable equip(l, -1);
					LuaObject<Ship>::CallMethod<>(ship, "AddEquip", equip.Sub("laser").Sub("pulsecannon_dual_1mw"));
					LuaObject<Ship>::CallMethod<>(ship, "AddEquip", equip.Sub("misc").Sub("laser_cooling_booster"));
					LuaObject<Ship>::CallMethod<>(ship, "AddEquip", equip.Sub("misc").Sub("atmospheric_shielding"));
					lua_pop(l, 5);
					ship->SetFrame(Pi::player->GetFrame());
					ship->SetPosition(Pi::player->GetPosition() + 100.0 * dir);
					ship->SetVelocity(Pi::player->GetVelocity());
					ship->UpdateEquipStats();
					game->GetSpace()->AddBody(ship);
				}
			}
			break;
		}
#endif /* DEVKEYS */
#if WITH_OBJECTVIEWER
		case SDLK_F10:
			Pi::SetView(Pi::game->GetObjectViewerView());
			break;
#endif
		case SDLK_F11:
			// XXX only works on X11
			//SDL_WM_ToggleFullScreen(Pi::scrSurface);
#if WITH_DEVKEYS
			renderer->ReloadShaders();
#endif
			break;
		case SDLK_F9: // Quicksave
		{
			if (Pi::game) {
				if (Pi::game->IsHyperspace())
					Pi::game->log->Add(Lang::CANT_SAVE_IN_HYPERSPACE);

				else {
					const std::string name = "_quicksave";
					const std::string path = FileSystem::JoinPath(GetSaveDir(), name);
					try {
						Game::SaveGame(name, Pi::game);
						Pi::game->log->Add(Lang::GAME_SAVED_TO + path);
					} catch (CouldNotOpenFileException) {
						Pi::game->log->Add(stringf(Lang::COULD_NOT_OPEN_FILENAME, formatarg("path", path)));
					} catch (CouldNotWriteToFileException) {
						Pi::game->log->Add(Lang::GAME_SAVE_CANNOT_WRITE);
					}
				}
			}
			break;
		}
		default:
			break; // This does nothing but it stops the compiler warnings
		}
	}
}
Esempio n. 21
0
File: Pi.cpp Progetto: lwho/pioneer
void Pi::HandleEvents()
{
	PROFILE_SCOPED()
	SDL_Event event;

	// XXX for most keypresses SDL will generate KEYUP/KEYDOWN and TEXTINPUT
	// events. keybindings run off KEYUP/KEYDOWN. the console is opened/closed
	// via keybinding. the console TextInput widget uses TEXTINPUT events. thus
	// after switching the console, the stray TEXTINPUT event causes the
	// console key (backtick) to appear in the text entry field. we hack around
	// this by setting this flag if the console was switched. if its set, we
	// swallow the TEXTINPUT event this hack must remain until we have a
	// unified input system
	bool skipTextInput = false;

	Pi::mouseMotion[0] = Pi::mouseMotion[1] = 0;
	while (SDL_PollEvent(&event)) {
		if (event.type == SDL_QUIT) {
			if (Pi::game)
				Pi::EndGame();
			Pi::Quit();
		}

		if (skipTextInput && event.type == SDL_TEXTINPUT) {
			skipTextInput = false;
			continue;
		}
		if (ui->DispatchSDLEvent(event))
			continue;

		bool consoleActive = Pi::IsConsoleActive();
		if (!consoleActive)
			KeyBindings::DispatchSDLEvent(&event);
		else
			KeyBindings::toggleLuaConsole.CheckSDLEventAndDispatch(&event);
		if (consoleActive != Pi::IsConsoleActive()) {
			skipTextInput = true;
			continue;
		}

		if (Pi::IsConsoleActive())
			continue;

		Gui::HandleSDLEvent(&event);

		switch (event.type) {
			case SDL_KEYDOWN:
				if (event.key.keysym.sym == SDLK_ESCAPE) {
					if (Pi::game) {
						// only accessible once game started
						if (currentView != 0) {
							if (currentView != Pi::game->GetSettingsView()) {
								Pi::game->SetTimeAccel(Game::TIMEACCEL_PAUSED);
								SetView(Pi::game->GetSettingsView());
							}
							else {
								Pi::game->RequestTimeAccel(Game::TIMEACCEL_1X);
								SetView(Pi::player->IsDead()
										? static_cast<View*>(Pi::game->GetDeathView())
										: static_cast<View*>(Pi::game->GetWorldView()));
							}
						}
					}
					break;
				}
				// special keys. LCTRL+turd
				if ((KeyState(SDLK_LCTRL) || (KeyState(SDLK_RCTRL)))) {
					switch (event.key.keysym.sym) {
						case SDLK_q: // Quit
							if (Pi::game)
								Pi::EndGame();
							Pi::Quit();
							break;
						case SDLK_PRINTSCREEN: // print
						case SDLK_KP_MULTIPLY: // screen
						{
							char buf[256];
							const time_t t = time(0);
							struct tm *_tm = localtime(&t);
							strftime(buf, sizeof(buf), "screenshot-%Y%m%d-%H%M%S.png", _tm);
							Graphics::ScreendumpState sd;
							Pi::renderer->Screendump(sd);
							write_screenshot(sd, buf);
							break;
						}
#if WITH_DEVKEYS
						case SDLK_i: // Toggle Debug info
							Pi::showDebugInfo = !Pi::showDebugInfo;
							break;

#ifdef PIONEER_PROFILER
						case SDLK_p: // alert it that we want to profile
							if (KeyState(SDLK_LSHIFT) || KeyState(SDLK_RSHIFT))
								Pi::doProfileOne = true;
							else {
								Pi::doProfileSlow = !Pi::doProfileSlow;
								Output("slow frame profiling %s\n", Pi::doProfileSlow ? "enabled" : "disabled");
							}
							break;
#endif

						case SDLK_F12:
						{
							if(Pi::game) {
								vector3d dir = -Pi::player->GetOrient().VectorZ();
								/* add test object */
								if (KeyState(SDLK_RSHIFT)) {
									Missile *missile =
										new Missile(ShipType::MISSILE_GUIDED, Pi::player);
									missile->SetOrient(Pi::player->GetOrient());
									missile->SetFrame(Pi::player->GetFrame());
									missile->SetPosition(Pi::player->GetPosition()+50.0*dir);
									missile->SetVelocity(Pi::player->GetVelocity());
									game->GetSpace()->AddBody(missile);
									missile->AIKamikaze(Pi::player->GetCombatTarget());
								} else if (KeyState(SDLK_LSHIFT)) {
									SpaceStation *s = static_cast<SpaceStation*>(Pi::player->GetNavTarget());
									if (s) {
										Ship *ship = new Ship(ShipType::POLICE);
										int port = s->GetFreeDockingPort(ship);
										if (port != -1) {
											Output("Putting ship into station\n");
											// Make police ship intent on killing the player
											ship->AIKill(Pi::player);
											ship->SetFrame(Pi::player->GetFrame());
											ship->SetDockedWith(s, port);
											game->GetSpace()->AddBody(ship);
										} else {
											delete ship;
											Output("No docking ports free dude\n");
										}
									} else {
											Output("Select a space station...\n");
									}
								} else {
									Ship *ship = new Ship(ShipType::POLICE);
									if( KeyState(SDLK_LCTRL) )
										ship->AIFlyTo(Pi::player);	// a less lethal option
									else
										ship->AIKill(Pi::player);	// a really lethal option!
									lua_State *l = Lua::manager->GetLuaState();
									pi_lua_import(l, "Equipment");
									LuaTable equip(l, -1);
									LuaObject<Ship>::CallMethod<>(ship, "AddEquip", equip.Sub("laser").Sub("pulsecannon_dual_1mw"));
									LuaObject<Ship>::CallMethod<>(ship, "AddEquip", equip.Sub("misc").Sub("laser_cooling_booster"));
									LuaObject<Ship>::CallMethod<>(ship, "AddEquip", equip.Sub("misc").Sub("atmospheric_shielding"));
									lua_pop(l, 5);
									ship->SetFrame(Pi::player->GetFrame());
									ship->SetPosition(Pi::player->GetPosition()+100.0*dir);
									ship->SetVelocity(Pi::player->GetVelocity());
									ship->UpdateEquipStats();
									game->GetSpace()->AddBody(ship);
								}
							}
							break;
						}
#endif /* DEVKEYS */
#if WITH_OBJECTVIEWER
						case SDLK_F10:
							Pi::SetView(Pi::game->GetObjectViewerView());
							break;
#endif
						case SDLK_F11:
							// XXX only works on X11
							//SDL_WM_ToggleFullScreen(Pi::scrSurface);
#if WITH_DEVKEYS
							renderer->ReloadShaders();
#endif
							break;
						case SDLK_F9: // Quicksave
						{
							if(Pi::game) {
								if (Pi::game->IsHyperspace())
									Pi::game->log->Add(Lang::CANT_SAVE_IN_HYPERSPACE);

								else {
									const std::string name = "_quicksave";
									const std::string path = FileSystem::JoinPath(GetSaveDir(), name);
									try {
										Game::SaveGame(name, Pi::game);
										Pi::game->log->Add(Lang::GAME_SAVED_TO + path);
									} catch (CouldNotOpenFileException) {
										Pi::game->log->Add(stringf(Lang::COULD_NOT_OPEN_FILENAME, formatarg("path", path)));
									}
									catch (CouldNotWriteToFileException) {
										Pi::game->log->Add(Lang::GAME_SAVE_CANNOT_WRITE);
									}
								}
							}
							break;
						}
						default:
							break; // This does nothing but it stops the compiler warnings
					}
				}
				Pi::keyState[event.key.keysym.sym] = true;
				Pi::keyModState = event.key.keysym.mod;
				Pi::onKeyPress.emit(&event.key.keysym);
				break;
			case SDL_KEYUP:
				Pi::keyState[event.key.keysym.sym] = false;
				Pi::keyModState = event.key.keysym.mod;
				Pi::onKeyRelease.emit(&event.key.keysym);
				break;
			case SDL_MOUSEBUTTONDOWN:
				if (event.button.button < COUNTOF(Pi::mouseButton)) {
					Pi::mouseButton[event.button.button] = 1;
					Pi::onMouseButtonDown.emit(event.button.button,
							event.button.x, event.button.y);
				}
				break;
			case SDL_MOUSEBUTTONUP:
				if (event.button.button < COUNTOF(Pi::mouseButton)) {
					Pi::mouseButton[event.button.button] = 0;
					Pi::onMouseButtonUp.emit(event.button.button,
							event.button.x, event.button.y);
				}
				break;
			case SDL_MOUSEWHEEL:
				Pi::onMouseWheel.emit(event.wheel.y > 0); // true = up
				break;
			case SDL_MOUSEMOTION:
				Pi::mouseMotion[0] += event.motion.xrel;
				Pi::mouseMotion[1] += event.motion.yrel;
		//		SDL_GetRelativeMouseState(&Pi::mouseMotion[0], &Pi::mouseMotion[1]);
				break;
			case SDL_JOYAXISMOTION:
				if (!joysticks[event.jaxis.which].joystick)
					break;
				if (event.jaxis.value == -32768)
					joysticks[event.jaxis.which].axes[event.jaxis.axis] = 1.f;
				else
					joysticks[event.jaxis.which].axes[event.jaxis.axis] = -event.jaxis.value / 32767.f;
				break;
			case SDL_JOYBUTTONUP:
			case SDL_JOYBUTTONDOWN:
				if (!joysticks[event.jaxis.which].joystick)
					break;
				joysticks[event.jbutton.which].buttons[event.jbutton.button] = event.jbutton.state != 0;
				break;
			case SDL_JOYHATMOTION:
				if (!joysticks[event.jaxis.which].joystick)
					break;
				joysticks[event.jhat.which].hats[event.jhat.hat] = event.jhat.value;
				break;
		}
	}
}
Esempio n. 22
0
int main(){
	personagem per;
	char test;
	item it;

	printf("\ndigite o level:");
	scanf("%i",&per.lvl);
	printf("%i\ndigite o valor de wis:",per.lvl);
	scanf("%i",&per.wis);
	printf("%i\ndigite o valor de str:",per.wis);
	scanf("%i",&per.str);
	printf("%i\ndigite o valor de dex:",per.str);
	scanf("%hhu",&per.dex);
	printf("%i\ndigite o valor de pos:",per.dex);
	scanf("%hhu",&per.pos);
	printf("%i\ndigite o valor de hp:",per.pos);
	scanf("%i",&per.hp);
	printf("%i\ndigite o valor de xp:",per.hp);
	scanf("%i",&per.xp);
	printf("%i\ndigite o slot(de 0 a 3):",per.xp);
	scanf("%i",&per.slot);
	printf("%i\n",per.slot);
	scanf("%*c");
	printf("digite o nome do personagem:");
	gets(per.nome);

	printf("yo:%s\n",per.nome);

	for(test=0;test<6;test++){
		(per.equip[test]).nome[0]='\0';
	}

	printf("deseja equipar um item(s/n):");
	scanf("%c",&test);

	while(test=='s'){
		scanf("%*c");
		printf("voce deseja encontrar um item pelo nome(c) ou pelo numero(n):");
		scanf("%c",&test);

		if(test=='c'){
			char nome[25];
			scanf("%*c");
			printf("digite o nome do item:");
			gets(nome);
			if(itemFind(nome,&it)) printf("item não encontrado\n");
			else equip(&per,it);
		}
		else{
			if(test=='n'){
				printf("digite o numero do item:");
				scanf("%i",&test);
				scanf("%*c");
				if(itemGet(test,&it))printf("item não encontrado\n");
				else equip(&per,it);
			}
			else printf("comando invalido\n");
		}

		printf("deseja equipar outro item(s/n):");
		scanf("%c",&test);
	}

	system("pause");
	save(per);

	return 0;
}