Esempio n. 1
0
void invlet_test( player &dummy, inventory_location from, inventory_location to )
{
    // invlet to assign
    constexpr char invlet = '|';

    // iterate through all permutations of test actions
    for( int id = 0; id < INVLET_STATE_NUM * INVLET_STATE_NUM * TEST_ACTION_NUM; ++id ) {
        // how to assign invlet to the first item
        invlet_state first_invlet_state = invlet_state( id % INVLET_STATE_NUM );
        // how to assign invlet to the second item
        invlet_state second_invlet_state = invlet_state( id / INVLET_STATE_NUM % INVLET_STATE_NUM );
        // the test steps
        test_action action = test_action( id / INVLET_STATE_NUM / INVLET_STATE_NUM % TEST_ACTION_NUM );

        // the final expected invlet state of the two items
        invlet_state expected_first_invlet_state = second_invlet_state == NONE ? first_invlet_state : NONE;
        invlet_state expected_second_invlet_state = second_invlet_state;

        // remove all items
        dummy.inv.clear();
        dummy.worn.clear();
        dummy.remove_weapon();
        g->m.i_clear( dummy.pos() );

        // some two items that can be wielded, worn, and picked up
        item tshirt( "tshirt" );
        item jeans( "jeans" );

        // add the items to the starting position
        add_item( dummy, tshirt, to );
        add_item( dummy, jeans, to );

        // assign invlet to the first item
        assign_invlet( dummy, item_at( dummy, 0, to ), invlet, first_invlet_state );

        // remove the first item
        move_item( dummy, 0, to, from );

        // assign invlet to the second item
        assign_invlet( dummy, item_at( dummy, 0, to ), invlet, second_invlet_state );

        item *final_first = nullptr, *final_second = nullptr;
        switch( action ) {
            case REMOVE_1ST_REMOVE_2ND_ADD_1ST_ADD_2ND:
                move_item( dummy, 0, to, from );
                move_item( dummy, 0, from, to );
                move_item( dummy, 0, from, to );
                final_first = &item_at( dummy, 0, to );
                final_second = &item_at( dummy, 1, to );
                break;
            case REMOVE_1ST_REMOVE_2ND_ADD_2ND_ADD_1ST:
                move_item( dummy, 0, to, from );
                move_item( dummy, 1, from, to );
                move_item( dummy, 0, from, to );
                final_first = &item_at( dummy, 1, to );
                final_second = &item_at( dummy, 0, to );
                break;
            case REMOVE_1ST_ADD_1ST:
                move_item( dummy, 0, from, to );
                final_first = &item_at( dummy, 1, to );
                final_second = &item_at( dummy, 0, to );
                break;
            default:
                FAIL( "unimplemented" );
                break;
        }

        invlet_state final_first_invlet_state = check_invlet( dummy, *final_first, invlet ),
                     final_second_invlet_state = check_invlet( dummy, *final_second, invlet );

        INFO( test_action_desc( action, from, to, first_invlet_state, second_invlet_state,
                                expected_first_invlet_state, expected_second_invlet_state, final_first_invlet_state,
                                final_second_invlet_state ) );
        REQUIRE( final_first->typeId() == tshirt.typeId() );
        REQUIRE( final_second->typeId() == jeans.typeId() );
        CHECK( final_first_invlet_state == expected_first_invlet_state );
        CHECK( final_second_invlet_state == expected_second_invlet_state );

        // clear invlets
        assign_invlet( dummy, *final_first, invlet, NONE );
        assign_invlet( dummy, *final_second, invlet, NONE );
    }
}
Esempio n. 2
0
void inventory::push_back(item newit)
{
 add_item(newit);
}
Esempio n. 3
0
size_t RamShield::proc(const request* r, bool warmup) {
	if (!warmup) {stat.accesses++;}
	counter++;

	double currTime = r->time;

	assert(dramSize + flashSize <= DRAM_SIZE + FLASH_SIZE*stat.threshold);
	auto searchRKId = allObjects.find(r->kid);
	if (searchRKId != allObjects.end()) {
		/*
		* The object exists in system. If the sizes of the 
		* current request and previous request differ then the previous
		* request is removed. Otherwise, one 
		* needs to update the hitrate and its place in the globalLru.
		* If it is in the cache, one needs also to update the 
		* 'flashiness' value and its place in the dram MFU and dram LRU 
		*/
		RamShield::RItem& item = searchRKId->second;
		if (r->size() == item.size) {
	                //HIT
			if (!warmup) {stat.hits++;}
			if (!item.isGhost) {
				assert(item.globalLruIt != globalLru.end());
				globalLru.erase(item.globalLruIt);
			}
			globalLru.emplace_front(item.kId);
			item.globalLruIt = globalLru.begin();

			if (item.isInDram) {
				if (!warmup) {stat.hits_dram++;}

				//Update Flashiness
				std::pair<uint32_t, double> p = *(item.dramLocation);
				p.second += 1;
				dramIt tmp = item.dramLocation;
				dramAdd(p, tmp, item);
				dram.erase(tmp);
			} else {
				if (!warmup) {stat.hits_flash++;}
				if (item.isGhost) {
					item.isGhost = false;
					item.flashIt->size += item.size;
					flashSize += item.size;
					while (dramSize + flashSize > DRAM_SIZE + FLASH_SIZE*stat.threshold) {
			                        uint32_t globalLruKid = globalLru.back();
			                        RamShield::RItem& victimItem = allObjects[globalLruKid];
			                        assert(victimItem.size > 0);
			                        evict_item(victimItem, warmup);
					}
					assert(dramSize + flashSize <= DRAM_SIZE + FLASH_SIZE*stat.threshold);
				}
			}
			item.lastAccessInTrace = counter;
			item.last_accessed = currTime;

			return 1;
		} else {
			//UPDATE
			if (!item.isInDram)
				item.flashIt->items.remove(item.kId);
		
			if (!item.isGhost)
				evict_item(item, warmup);

 			if (!item.isInDram) {
				 assert(allObjects.find(item.kId) != allObjects.end());
				 allObjects.erase(item.kId);
			}
		}
	}
	//MISS

	/*
	* The request doesn't exist in the system. We always insert new requests
	* to the DRAM. 
	*/
	RamShield::RItem newItem(r, counter);
	assert(((unsigned int) newItem.size) <= DRAM_SIZE);
	assert(dramSize + flashSize <= DRAM_SIZE + FLASH_SIZE*stat.threshold);
	while (true) {
		if ((newItem.size + dramSize <= DRAM_SIZE) && (dramSize + flashSize + newItem.size <= DRAM_SIZE + FLASH_SIZE*stat.threshold)) {
			add_item(newItem);
			return PROC_MISS;
		}

		//Not enough space in DRAM, check flash
		assert(numBlocks <= maxBlocks);
		if ((dramSize + flashSize + newItem.size) > DRAM_SIZE + FLASH_SIZE*stat.threshold) {
			uint32_t globalLruKid = globalLru.back();
			RamShield::RItem& victimItem = allObjects[globalLruKid];
			assert(victimItem.size > 0);
			evict_item(victimItem, warmup);
			assert(dramSize + flashSize <= DRAM_SIZE + FLASH_SIZE*stat.threshold);
		} else if (numBlocks < maxBlocks) {
			allocate_flash_block(warmup);
		assert(dramSize + flashSize <= DRAM_SIZE + FLASH_SIZE*stat.threshold);
		} else {
			assert(0);
		}
		assert(numBlocks <= maxBlocks);
	}
	assert(0);
	return PROC_MISS;
}
Esempio n. 4
0
void inventory::add_stack(const std::vector<item> newits)
{
 for (int i = 0; i < newits.size(); i++)
  add_item(newits[i], true);
}
Esempio n. 5
0
inventory& inventory::operator+= (const item &rhs)
{
 add_item(rhs);
 return *this;
}
Esempio n. 6
0
void profession::add_items_from_jsonarray(JsonArray jsarr, std::string gender)
{
    while (jsarr.has_more()) {
        add_item(jsarr.next_string(), gender);
    }
}
Esempio n. 7
0
static void 
add_bool(void *opaque, void *parent, const char *name, int v)
{
  add_item(opaque, parent, name, BOOLEAN_TO_JSVAL(!!v));
}
Esempio n. 8
0
void AC3ConfigAudioBitrate::create_objects()
{
	add_item(new BC_MenuItem("32"));
	add_item(new BC_MenuItem("40"));
	add_item(new BC_MenuItem("48"));
	add_item(new BC_MenuItem("56"));
	add_item(new BC_MenuItem("64"));
	add_item(new BC_MenuItem("80"));
	add_item(new BC_MenuItem("96"));
	add_item(new BC_MenuItem("112"));
	add_item(new BC_MenuItem("128"));
	add_item(new BC_MenuItem("160"));
	add_item(new BC_MenuItem("192"));
	add_item(new BC_MenuItem("224"));
	add_item(new BC_MenuItem("256"));
	add_item(new BC_MenuItem("320"));
	add_item(new BC_MenuItem("384"));
	add_item(new BC_MenuItem("448"));
	add_item(new BC_MenuItem("512"));
	add_item(new BC_MenuItem("576"));
	add_item(new BC_MenuItem("640"));
}
Esempio n. 9
0
void inventory::add_stack(const std::list<item> newits)
{
    for( const auto &newit : newits ) {
        add_item( newit, true );
    }
}
Esempio n. 10
0
/*
//item
*/
xui_method_explain(xui_toolbar, add_separate,	void		)( void )
{
	add_item(new xui_separate(xui_vector<s32>(8), m_flow));
}
Esempio n. 11
0
void create_object(void)
{
    set_short("The second floor of the third gate tower");
    set_long("The second floor of the third gate tower. There are several " +
             "holes and wooden hatches on the floor, and large iron " +
             "cauldrons hang over the hatches in chains from the ceiling. " +
             "There are thin arrowslits in the west and south walls, and " +
             "archways to the east and the northwest.\n");
    set_new_light(5);
    add_property("indoors");

    add_item("room","A room on the second floor of the tower");
    add_item("floor","A smooth, black stone floor with holes and wooden " +
             "hatches on it");
    add_item("hatch|hatches","The hatches cover shafts going down to the " +
             "tunnel below");
    add_item("hole|holes","Probably for firing arrows through, if an " +
             "attacking force would manage to come all the way down there");
    add_item("shafts|shaft","Probably used for pouring molten lead and " +
             "other nasty things down upon attackers in the tunnel below " +
             "through");
    add_item("cauldron|cauldrons","The big iron cauldrons are probably " +
             "being used for melting and keeping lead, that would be " +
             "poured down upon an attacking force in the tunnel below in");
    add_item("chain|chains","Strong iron chains holding up the cauldrons");
    add_item("ceilong|wall|walls","Smooth, black stone");
    add_item("arrowslits|arrowslit","Through the arrowslits in the west " +
             "wall you see the inner courtayard, and through those in the " +
             "south wall you see the outer courtyard");
    add_item("courtyard","You would have to go down there to get a good look");
    add_item("archway|archways","Two of them. One going east, the other " +
             "going northwest");

    add_exit(ROOM + "lev2_wall2","east");
    add_exit(ROOM + "lev2_guardroom2","northwest");

    reset(0);
}
Esempio n. 12
0
bool map::process_fields_in_submap(game *g, int gridn)
{
 bool found_field = false;
 field *cur;
 field_id curtype;
 for (int locx = 0; locx < SEEX; locx++) {
  for (int locy = 0; locy < SEEY; locy++) {
   cur = &(grid[gridn]->fld[locx][locy]);
   int x = locx + SEEX * (gridn % my_MAPSIZE),
       y = locy + SEEY * int(gridn / my_MAPSIZE);

   curtype = cur->type;
   if (!found_field && curtype != fd_null)
    found_field = true;
   if (cur->density > 3 || cur->density < 1)
    debugmsg("Whoooooa density of %d", cur->density);

  if (cur->age == 0)	// Don't process "newborn" fields
   curtype = fd_null;

  int part;
  vehicle *veh;
  switch (curtype) {

   case fd_null:
    break;	// Do nothing, obviously.  OBVIOUSLY.

   case fd_blood:
   case fd_bile:
    if (has_flag(swimmable, x, y))	// Dissipate faster in water
     cur->age += 250;
    break;

   case fd_acid:
    if (has_flag(swimmable, x, y))	// Dissipate faster in water
     cur->age += 20;
    for (int i = 0; i < i_at(x, y).size(); i++) {
     item *melting = &(i_at(x, y)[i]);
     if (melting->made_of(LIQUID) || melting->made_of(VEGGY)   ||
         melting->made_of(FLESH)  || melting->made_of(POWDER)  ||
         melting->made_of(COTTON) || melting->made_of(WOOL)    ||
         melting->made_of(PAPER)  || melting->made_of(PLASTIC) ||
         (melting->made_of(GLASS) && !one_in(3)) || one_in(4)) {
// Acid destructable objects here
      melting->damage++;
      if (melting->damage >= 5 ||
          (melting->made_of(PAPER) && melting->damage >= 3)) {
       cur->age += melting->volume();
       for (int m = 0; m < i_at(x, y)[i].contents.size(); m++)
        i_at(x, y).push_back( i_at(x, y)[i].contents[m] );
       i_at(x, y).erase(i_at(x, y).begin() + i);
       i--;
      }
     }
    }
    break;

   case fd_sap:
    break; // It doesn't do anything.

   case fd_fire: {
// Consume items as fuel to help us grow/last longer.
    bool destroyed = false;
    int vol = 0, smoke = 0, consumed = 0;
    for (int i = 0; i < i_at(x, y).size() && consumed < cur->density * 2; i++) {
     destroyed = false;
     vol = i_at(x, y)[i].volume();
     item *it = &(i_at(x, y)[i]);

     if (it->is_ammo() && it->ammo_type() != AT_BATT &&
         it->ammo_type() != AT_NAIL && it->ammo_type() != AT_BB &&
         it->ammo_type() != AT_BOLT && it->ammo_type() != AT_ARROW && it->ammo_type() != AT_NULL) {
      cur->age /= 2;
      cur->age -= 600;
      destroyed = true;
      smoke += 6;
      consumed++;

     } else if (it->made_of(PAPER)) {
      destroyed = it->burn(cur->density * 3);
      consumed++;
      if (cur->density == 1)
       cur->age -= vol * 10;
      if (vol >= 4)
       smoke++;

     } else if ((it->made_of(WOOD) || it->made_of(VEGGY))) {
      if (vol <= cur->density * 10 || cur->density == 3) {
       cur->age -= 4;
       destroyed = it->burn(cur->density);
       smoke++;
       consumed++;
      } else if (it->burnt < cur->density) {
       destroyed = it->burn(1);
       smoke++;
      }

     } else if ((it->made_of(COTTON) || it->made_of(WOOL))) {
      if (vol <= cur->density * 5 || cur->density == 3) {
       cur->age--;
       destroyed = it->burn(cur->density);
       smoke++;
       consumed++;
      } else if (it->burnt < cur->density) {
       destroyed = it->burn(1);
       smoke++;
      }

     } else if (it->made_of(FLESH)) {
      if (vol <= cur->density * 5 || (cur->density == 3 && one_in(vol / 20))) {
       cur->age--;
       destroyed = it->burn(cur->density);
       smoke += 3;
       consumed++;
      } else if (it->burnt < cur->density * 5 || cur->density >= 2) {
       destroyed = it->burn(1);
       smoke++;
      }

     } else if (it->made_of(LIQUID)) {
      switch (it->type->id) { // TODO: Make this be not a hack.
       case itm_whiskey:
       case itm_vodka:
       case itm_rum:
       case itm_tequila:
        cur->age -= 300;
        smoke += 6;
        break;
       default:
        cur->age += rng(80 * vol, 300 * vol);
        smoke++;
      }
      destroyed = true;
      consumed++;

     } else if (it->made_of(POWDER)) {
      cur->age -= vol;
      destroyed = true;
      smoke += 2;

     } else if (it->made_of(PLASTIC)) {
      smoke += 3;
      if (it->burnt <= cur->density * 2 || (cur->density == 3 && one_in(vol))) {
       destroyed = it->burn(cur->density);
       if (one_in(vol + it->burnt))
        cur->age--;
      }
     }

     if (destroyed) {
      for (int m = 0; m < i_at(x, y)[i].contents.size(); m++)
       i_at(x, y).push_back( i_at(x, y)[i].contents[m] );
      i_at(x, y).erase(i_at(x, y).begin() + i);
      i--;
     }
    }

    veh = veh_at(x, y, part);
    if (veh)
     veh->damage (part, cur->density * 10, false);
    // If the flames are in a brazier, they're fully contained, so skip consuming terrain
    if(tr_brazier != tr_at(x, y)) {
     // Consume the terrain we're on
     if (has_flag(explodes, x, y)) {
      ter(x, y) = ter_id(int(ter(x, y)) + 1);
      cur->age = 0;
      cur->density = 3;
      g->explosion(x, y, 40, 0, true);

     } else if (has_flag(flammable, x, y) && one_in(32 - cur->density * 10)) {
      cur->age -= cur->density * cur->density * 40;
      smoke += 15;
      if (cur->density == 3)
       g->m.destroy(g, x, y, false);

     } else if (has_flag(flammable2, x, y) && one_in(32 - cur->density * 10)) {
      cur->age -= cur->density * cur->density * 40;
      smoke += 15;
      if (cur->density == 3)
       ter(x, y) = t_ash;

     } else if (has_flag(l_flammable, x, y) && one_in(62 - cur->density * 10)) {
      cur->age -= cur->density * cur->density * 30;
      smoke += 10;
      if (cur->density == 3)
       g->m.destroy(g, x, y, false);

     } else if (terlist[ter(x, y)].flags & mfb(swimmable))
      cur->age += 800;	// Flames die quickly on water
    }

// If we consumed a lot, the flames grow higher
    while (cur->density < 3 && cur->age < 0) {
     cur->age += 300;
     cur->density++;
    }

// If the flames are in a pit, it can't spread to non-pit
    bool in_pit = (ter(x, y) == t_pit);
// If the flames are REALLY big, they contribute to adjacent flames
    if (cur->density == 3 && cur->age < 0 && tr_brazier != tr_at(x, y)) {
// Randomly offset our x/y shifts by 0-2, to randomly pick a square to spread to
     int starti = rng(0, 2);
     int startj = rng(0, 2);
     for (int i = 0; i < 3 && cur->age < 0; i++) {
      for (int j = 0; j < 3 && cur->age < 0; j++) {
       int fx = x + ((i + starti) % 3) - 1, fy = y + ((j + startj) % 3) - 1;
       if (field_at(fx, fy).type == fd_fire && field_at(fx, fy).density < 3 &&
           (in_pit == (ter(fx, fy) == t_pit))) {
        field_at(fx, fy).density++;
        field_at(fx, fy).age = 0;
        cur->age = 0;
       }
      }
     }
    }
// Consume adjacent fuel / terrain / webs to spread.
// Randomly offset our x/y shifts by 0-2, to randomly pick a square to spread to
    int starti = rng(0, 2);
    int startj = rng(0, 2);
    for (int i = 0; i < 3; i++) {
     for (int j = 0; j < 3; j++) {
      int fx = x + ((i + starti) % 3) - 1, fy = y + ((j + startj) % 3) - 1;
      if (INBOUNDS(fx, fy)) {
       int spread_chance = 20 * (cur->density - 1) + 10 * smoke;
       if (field_at(fx, fy).type == fd_web)
        spread_chance = 50 + spread_chance / 2;
       if (has_flag(explodes, fx, fy) && one_in(8 - cur->density) &&
	   tr_brazier != tr_at(x, y)) {
        ter(fx, fy) = ter_id(int(ter(fx, fy)) + 1);
        g->explosion(fx, fy, 40, 0, true);
       } else if ((i != 0 || j != 0) && rng(1, 100) < spread_chance &&
                  tr_brazier != tr_at(x, y) &&
                  (in_pit == (ter(fx, fy) == t_pit)) &&
                  ((cur->density == 3 &&
                    (has_flag(flammable, fx, fy) || one_in(20))) ||
                   (cur->density == 3 &&
                    (has_flag(l_flammable, fx, fy) && one_in(10))) ||
                   flammable_items_at(fx, fy) ||
                   field_at(fx, fy).type == fd_web)) {
        if (field_at(fx, fy).type == fd_smoke ||
            field_at(fx, fy).type == fd_web)
         field_at(fx, fy) = field(fd_fire, 1, 0);
        else
         add_field(g, fx, fy, fd_fire, 1);
       } else {
        bool nosmoke = true;
        for (int ii = -1; ii <= 1; ii++) {
         for (int jj = -1; jj <= 1; jj++) {
          if (field_at(x+ii, y+jj).type == fd_fire &&
              field_at(x+ii, y+jj).density == 3)
           smoke++;
          else if (field_at(x+ii, y+jj).type == fd_smoke)
           nosmoke = false;
         }
        }
// If we're not spreading, maybe we'll stick out some smoke, huh?
        if (move_cost(fx, fy) > 0 &&
            (!one_in(smoke) || (nosmoke && one_in(40))) &&
            rng(3, 35) < cur->density * 10 && cur->age < 1000) {
         smoke--;
         add_field(g, fx, fy, fd_smoke, rng(1, cur->density));
        }
       }
      }
     }
    }
   } break;

   case fd_smoke:
    for (int i = -1; i <= 1; i++) {
     for (int j = -1; j <= 1; j++)
      g->scent(x+i, y+j) = 0;
    }
    if (is_outside(x, y))
     cur->age += 50;
    if (one_in(2)) {
     std::vector <point> spread;
     for (int a = -1; a <= 1; a++) {
      for (int b = -1; b <= 1; b++) {
       if ((field_at(x+a, y+b).type == fd_smoke &&
             field_at(x+a, y+b).density < 3       ) ||
           (field_at(x+a, y+b).is_null() && move_cost(x+a, y+b) > 0))
        spread.push_back(point(x+a, y+b));
      }
     }
     if (cur->density > 0 && cur->age > 0 && spread.size() > 0) {
      point p = spread[rng(0, spread.size() - 1)];
      if (field_at(p.x, p.y).type == fd_smoke &&
          field_at(p.x, p.y).density < 3) {
        field_at(p.x, p.y).density++;
        cur->density--;
      } else if (cur->density > 0 && move_cost(p.x, p.y) > 0 &&
                 add_field(g, p.x, p.y, fd_smoke, 1)){
       cur->density--;
       field_at(p.x, p.y).age = cur->age;
      }
     }
    }
   break;

   case fd_tear_gas:
// Reset nearby scents to zero
    for (int i = -1; i <= 1; i++) {
     for (int j = -1; j <= 1; j++)
      g->scent(x+i, y+j) = 0;
    }
    if (is_outside(x, y))
     cur->age += 30;
// One in three chance that it spreads (less than smoke!)
    if (one_in(3)) {
     std::vector <point> spread;
// Pick all eligible points to spread to
     for (int a = -1; a <= 1; a++) {
      for (int b = -1; b <= 1; b++) {
       if (((field_at(x+a, y+b).type == fd_smoke ||
             field_at(x+a, y+b).type == fd_tear_gas) &&
             field_at(x+a, y+b).density < 3            )      ||
           (field_at(x+a, y+b).is_null() && move_cost(x+a, y+b) > 0))
        spread.push_back(point(x+a, y+b));
      }
     }
// Then, spread to a nearby point
     if (cur->density > 0 && cur->age > 0 && spread.size() > 0) {
      point p = spread[rng(0, spread.size() - 1)];
// Nearby teargas grows thicker
      if (field_at(p.x, p.y).type == fd_tear_gas &&
          field_at(p.x, p.y).density < 3) {
        field_at(p.x, p.y).density++;
        cur->density--;
// Nearby smoke is converted into teargas
      } else if (field_at(p.x, p.y).type == fd_smoke) {
       field_at(p.x, p.y).type = fd_tear_gas;
// Or, just create a new field.
      } else if (cur->density > 0 && move_cost(p.x, p.y) > 0 &&
                 add_field(g, p.x, p.y, fd_tear_gas, 1)) {
       cur->density--;
       field_at(p.x, p.y).age = cur->age;
      }
     }
    }
    break;

   case fd_toxic_gas:
// Reset nearby scents to zero
    for (int i = -1; i <= 1; i++) {
     for (int j = -1; j <= 1; j++)
      g->scent(x+i, y+j) = 0;
    }
    if (is_outside(x, y))
     cur->age += 40;
    if (one_in(2)) {
     std::vector <point> spread;
// Pick all eligible points to spread to
     for (int a = -1; a <= 1; a++) {
      for (int b = -1; b <= 1; b++) {
       if (((field_at(x+a, y+b).type == fd_smoke ||
             field_at(x+a, y+b).type == fd_tear_gas ||
             field_at(x+a, y+b).type == fd_toxic_gas ||
             field_at(x+a, y+b).type == fd_nuke_gas   ) &&
             field_at(x+a, y+b).density < 3            )      ||
           (field_at(x+a, y+b).is_null() && move_cost(x+a, y+b) > 0))
        spread.push_back(point(x+a, y+b));
      }
     }
// Then, spread to a nearby point
     if (cur->density > 0 && cur->age > 0 && spread.size() > 0) {
      point p = spread[rng(0, spread.size() - 1)];
// Nearby toxic gas grows thicker
      if (field_at(p.x, p.y).type == fd_toxic_gas &&
          field_at(p.x, p.y).density < 3) {
        field_at(p.x, p.y).density++;
        cur->density--;
// Nearby smoke & teargas is converted into toxic gas
      } else if (field_at(p.x, p.y).type == fd_smoke ||
                 field_at(p.x, p.y).type == fd_tear_gas) {
       field_at(p.x, p.y).type = fd_toxic_gas;
// Or, just create a new field.
      } else if (cur->density > 0 && move_cost(p.x, p.y) > 0 &&
                 add_field(g, p.x, p.y, fd_toxic_gas, 1)) {
       cur->density--;
       field_at(p.x, p.y).age = cur->age;
      }
     }
    }
    break;


   case fd_nuke_gas:
// Reset nearby scents to zero
    for (int i = -1; i <= 1; i++) {
     for (int j = -1; j <= 1; j++)
      g->scent(x+i, y+j) = 0;
    }
    if (is_outside(x, y))
     cur->age += 40;
// Increase long-term radiation in the land underneath
    radiation(x, y) += rng(0, cur->density);
    if (one_in(2)) {
     std::vector <point> spread;
// Pick all eligible points to spread to
     for (int a = -1; a <= 1; a++) {
      for (int b = -1; b <= 1; b++) {
       if (((field_at(x+a, y+b).type == fd_smoke ||
             field_at(x+a, y+b).type == fd_tear_gas ||
             field_at(x+a, y+b).type == fd_toxic_gas ||
             field_at(x+a, y+b).type == fd_nuke_gas   ) &&
             field_at(x+a, y+b).density < 3            )      ||
           (field_at(x+a, y+b).is_null() && move_cost(x+a, y+b) > 0))
        spread.push_back(point(x+a, y+b));
      }
     }
// Then, spread to a nearby point
     if (cur->density > 0 && cur->age > 0 && spread.size() > 0) {
      point p = spread[rng(0, spread.size() - 1)];
// Nearby nukegas grows thicker
      if (field_at(p.x, p.y).type == fd_nuke_gas &&
          field_at(p.x, p.y).density < 3) {
        field_at(p.x, p.y).density++;
        cur->density--;
// Nearby smoke, tear, and toxic gas is converted into nukegas
      } else if (field_at(p.x, p.y).type == fd_smoke ||
                 field_at(p.x, p.y).type == fd_toxic_gas ||
                 field_at(p.x, p.y).type == fd_tear_gas) {
       field_at(p.x, p.y).type = fd_nuke_gas;
// Or, just create a new field.
      } else if (cur->density > 0 && move_cost(p.x, p.y) > 0 &&
                 add_field(g, p.x, p.y, fd_nuke_gas, 1)) {
       cur->density--;
       field_at(p.x, p.y).age = cur->age;
      }
     }
    }
    break;

   case fd_gas_vent:
    for (int i = x - 1; i <= x + 1; i++) {
     for (int j = y - 1; j <= y + 1; j++) {
      if (field_at(i, j).type == fd_toxic_gas && field_at(i, j).density < 3)
       field_at(i, j).density++;
      else
       add_field(g, i, j, fd_toxic_gas, 3);
     }
    }
    break;

   case fd_fire_vent:
    if (cur->density > 1) {
     if (one_in(3))
      cur->density--;
    } else {
     cur->type = fd_flame_burst;
     cur->density = 3;
    }
    break;

   case fd_flame_burst:
    if (cur->density > 1)
     cur->density--;
    else {
     cur->type = fd_fire_vent;
     cur->density = 3;
    }
    break;

   case fd_electricity:
    if (!one_in(5)) {	// 4 in 5 chance to spread
     std::vector<point> valid;
     if (move_cost(x, y) == 0 && cur->density > 1) { // We're grounded
      int tries = 0;
      while (tries < 10 && cur->age < 50) {
       int cx = x + rng(-1, 1), cy = y + rng(-1, 1);
       if (move_cost(cx, cy) != 0 && field_at(cx, cy).is_null()) {
        add_field(g, cx, cy, fd_electricity, 1);
        cur->density--;
        tries = 0;
       } else
        tries++;
      }
     } else {	// We're not grounded; attempt to ground
      for (int a = -1; a <= 1; a++) {
       for (int b = -1; b <= 1; b++) {
        if (move_cost(x + a, y + b) == 0 && // Grounded tiles first
            field_at(x + a, y + b).is_null())
         valid.push_back(point(x + a, y + b));
       }
      }
      if (valid.size() == 0) {	// Spread to adjacent space, then
       int px = x + rng(-1, 1), py = y + rng(-1, 1);
       if (move_cost(px, py) > 0 && field_at(px, py).type == fd_electricity &&
           field_at(px, py).density < 3)
        field_at(px, py).density++;
       else if (move_cost(px, py) > 0)
        add_field(g, px, py, fd_electricity, 1);
       cur->density--;
      }
      while (valid.size() > 0 && cur->density > 0) {
       int index = rng(0, valid.size() - 1);
       add_field(g, valid[index].x, valid[index].y, fd_electricity, 1);
       cur->density--;
       valid.erase(valid.begin() + index);
      }
     }
    }
    break;

   case fd_fatigue:
    if (cur->density < 3 && int(g->turn) % 3600 == 0 && one_in(10))
     cur->density++;
    else if (cur->density == 3 && one_in(600)) { // Spawn nether creature!
     mon_id type = mon_id(rng(mon_flying_polyp, mon_blank));
     monster creature(g->mtypes[type]);
     creature.spawn(x + rng(-3, 3), y + rng(-3, 3));
     g->z.push_back(creature);
    }
    break;

   case fd_push_items: {
    std::vector<item> *it = &(i_at(x, y));
    for (int i = 0; i < it->size(); i++) {
     if ((*it)[i].type->id != itm_rock || (*it)[i].bday >= int(g->turn) - 1)
      i++;
     else {
      item tmp = (*it)[i];
      tmp.bday = int(g->turn);
      it->erase(it->begin() + i);
      i--;
      std::vector<point> valid;
      for (int xx = x - 1; xx <= x + 1; xx++) {
       for (int yy = y - 1; yy <= y + 1; yy++) {
        if (field_at(xx, yy).type == fd_push_items)
         valid.push_back( point(xx, yy) );
       }
      }
      if (!valid.empty()) {
       point newp = valid[rng(0, valid.size() - 1)];
       add_item(newp.x, newp.y, tmp);
       if (g->u.posx == newp.x && g->u.posy == newp.y) {
        g->add_msg("A %s hits you!", tmp.tname().c_str());
        g->u.hit(g, random_body_part(), rng(0, 1), 6, 0);
       }
       int npcdex = g->npc_at(newp.x, newp.y),
           mondex = g->mon_at(newp.x, newp.y);

       if (npcdex != -1) {
        int junk;
        npc *p = &(g->active_npc[npcdex]);
        p->hit(g, random_body_part(), rng(0, 1), 6, 0);
        if (g->u_see(newp.x, newp.y, junk))
         g->add_msg("A %s hits %s!", tmp.tname().c_str(), p->name.c_str());
       }

       if (mondex != -1) {
        int junk;
        monster *mon = &(g->z[mondex]);
        mon->hurt(6 - mon->armor_bash());
        if (g->u_see(newp.x, newp.y, junk))
         g->add_msg("A %s hits the %s!", tmp.tname().c_str(),
                                         mon->name().c_str());
       }
      }
     }
    }
   } break;

   case fd_shock_vent:
    if (cur->density > 1) {
     if (one_in(5))
      cur->density--;
    } else {
     cur->density = 3;
     int num_bolts = rng(3, 6);
     for (int i = 0; i < num_bolts; i++) {
      int xdir = 0, ydir = 0;
      while (xdir == 0 && ydir == 0) {
       xdir = rng(-1, 1);
       ydir = rng(-1, 1);
      }
      int dist = rng(4, 12);
      int boltx = x, bolty = y;
      for (int n = 0; n < dist; n++) {
       boltx += xdir;
       bolty += ydir;
       add_field(g, boltx, bolty, fd_electricity, rng(2, 3));
       if (one_in(4)) {
        if (xdir == 0)
         xdir = rng(0, 1) * 2 - 1;
        else
         xdir = 0;
       }
       if (one_in(4)) {
        if (ydir == 0)
         ydir = rng(0, 1) * 2 - 1;
        else
         ydir = 0;
       }
      }
     }
    }
    break;

   case fd_acid_vent:
    if (cur->density > 1) {
     if (cur->age >= 10) {
      cur->density--;
      cur->age = 0;
     }
    } else {
     cur->density = 3;
     for (int i = x - 5; i <= x + 5; i++) {
      for (int j = y - 5; j <= y + 5; j++) {
       if (field_at(i, j).type == fd_null || field_at(i, j).density == 0) {
        int newdens = 3 - (rl_dist(x, y, i, j) / 2) + (one_in(3) ? 1 : 0);
        if (newdens > 3)
         newdens = 3;
        if (newdens > 0)
         add_field(g, i, j, fd_acid, newdens);
       }
      }
     }
    }
    break;

   } // switch (curtype)

   cur->age++;
   if (fieldlist[cur->type].halflife > 0) {
    if (cur->age > 0 &&
        dice(3, cur->age) > dice(3, fieldlist[cur->type].halflife)) {
     cur->age = 0;
     cur->density--;
    }
    if (cur->density <= 0) { // Totally dissapated.
     grid[gridn]->field_count--;
     grid[gridn]->fld[locx][locy] = field();
    }
   }
  }
 }
 return found_field;
}
Esempio n. 13
0
void merge_invlet_test( player &dummy, inventory_location from )
{
    // invlet to assign
    constexpr char invlet_1 = '{';
    constexpr char invlet_2 = '}';

    // should merge from a place other than the inventory
    REQUIRE( from != INVENTORY );
    // cannot assign invlet to items on the ground
    REQUIRE( from != GROUND );

    for( int id = 0; id < INVLET_STATE_NUM * INVLET_STATE_NUM; ++id ) {
        // how to assign invlet to the first item
        invlet_state first_invlet_state = invlet_state( id % INVLET_STATE_NUM );
        // how to assign invlet to the second item
        invlet_state second_invlet_state = invlet_state( id / INVLET_STATE_NUM );
        // what the invlet should be for the merged stack
        invlet_state expected_merged_invlet_state = first_invlet_state != NONE ? first_invlet_state :
                second_invlet_state;
        char expected_merged_invlet = first_invlet_state != NONE ? invlet_1 : second_invlet_state != NONE ?
                                      invlet_2 : 0;

        // remove all items
        dummy.inv.clear();
        dummy.worn.clear();
        dummy.remove_weapon();
        g->m.i_clear( dummy.pos() );

        // some stackable item
        item tshirt( "tshirt" );

        // add the item
        add_item( dummy, tshirt, INVENTORY );
        add_item( dummy, tshirt, from );

        // assign the items with invlets
        assign_invlet( dummy, item_at( dummy, 0, INVENTORY ), invlet_1, first_invlet_state );
        assign_invlet( dummy, item_at( dummy, 0, from ), invlet_2, second_invlet_state );

        // merge the second item into inventory
        move_item( dummy, 0, from, INVENTORY );

        item &merged_item = item_at( dummy, 0, INVENTORY );
        invlet_state merged_invlet_state = check_invlet( dummy, merged_item, expected_merged_invlet );
        char merged_invlet = merged_item.invlet;

        std::stringstream ss;
        ss << "1. add two stackable items to the inventory and " << location_desc( from ) << std::endl;
        ss << "2. assign " << invlet_state_desc( first_invlet_state ) << " invlet " << invlet_1 <<
           " to the item in the inventory " << std::endl;
        ss << "3. assign " << invlet_state_desc( second_invlet_state ) << " invlet " << invlet_2 <<
           " to the " << location_desc( from ) << std::endl;
        ss << "4. " << move_action_desc( 0, from, INVENTORY ) << std::endl;
        ss << "expect the stack in the inventory to have " << invlet_state_desc(
               expected_merged_invlet_state ) << " invlet " << expected_merged_invlet << std::endl;
        ss << "the stack actually has " << invlet_state_desc( merged_invlet_state ) << " invlet " <<
           merged_invlet << std::endl;
        INFO( ss.str() );
        REQUIRE( merged_item.typeId() == tshirt.typeId() );
        CHECK( merged_invlet_state == expected_merged_invlet_state );
        CHECK( merged_invlet == expected_merged_invlet );
    }
}
Esempio n. 14
0
void swap_invlet_test( player &dummy, inventory_location loc )
{
    // invlet to assign
    constexpr char invlet_1 = '{';
    constexpr char invlet_2 = '}';

    // cannot swap invlets of items on the ground
    REQUIRE( loc != GROUND );

    // remove all items
    dummy.inv.clear();
    dummy.worn.clear();
    dummy.remove_weapon();
    g->m.i_clear( dummy.pos() );

    // two items of the same type that do not stack
    item tshirt1( "tshirt" );
    item tshirt2( "tshirt" );
    tshirt2.mod_damage( -1 );

    // add the items
    add_item( dummy, tshirt1, loc );
    add_item( dummy, tshirt2, loc );

    // assign the items with invlets
    assign_invlet( dummy, item_at( dummy, 0, loc ), invlet_1, CACHED );
    assign_invlet( dummy, item_at( dummy, 1, loc ), invlet_2, CACHED );

    // swap the invlets (invoking twice to make the invlet non-player-assigned)
    dummy.reassign_item( item_at( dummy, 0, loc ), invlet_2 );
    dummy.reassign_item( item_at( dummy, 0, loc ), invlet_2 );

    // drop the items
    move_item( dummy, 0, loc, GROUND );
    move_item( dummy, 0, loc, GROUND );

    // get them again
    move_item( dummy, 0, GROUND, loc );
    move_item( dummy, 0, GROUND, loc );

    std::stringstream ss;
    ss << "1. add two items of the same type to " << location_desc( loc ) <<
       ", and ensure them do not stack" << std::endl;
    ss << "2. assign different invlets to the two items" << std::endl;
    ss << "3. swap the invlets by assign one of the items with the invlet of the other item" <<
       std::endl;
    ss << "4. move the items to " << location_desc( GROUND ) << std::endl;
    ss << "5. move the items to " << location_desc( loc ) << " again" << std::endl;
    ss << "expect the items to keep their swapped invlets" << std::endl;
    if( item_at( dummy, 0, loc ).invlet == invlet_2 && item_at( dummy, 1, loc ).invlet == invlet_1 ) {
        ss << "the items actually keep their swapped invlets" << std::endl;
    } else {
        ss << "the items actually does not keep their swapped invlets" << std::endl;
    }
    INFO( ss.str() );
    REQUIRE( item_at( dummy, 0, loc ).typeId() == tshirt1.typeId() );
    REQUIRE( item_at( dummy, 1, loc ).typeId() == tshirt2.typeId() );
    // invlets should not disappear and should still be swapped
    CHECK( item_at( dummy, 0, loc ).invlet == invlet_2 );
    CHECK( item_at( dummy, 1, loc ).invlet == invlet_1 );
    CHECK( check_invlet( dummy, item_at( dummy, 0, loc ), invlet_2 ) == CACHED );
    CHECK( check_invlet( dummy, item_at( dummy, 1, loc ), invlet_1 ) == CACHED );

    // clear invlets
    assign_invlet( dummy, item_at( dummy, 0, loc ), invlet_2, NONE );
    assign_invlet( dummy, item_at( dummy, 1, loc ), invlet_1, NONE );
}
Esempio n. 15
0
void C_ConfigManager::setup_item(std::vector< int > * pointer, std::string name) {
	add_item(pointer, name.c_str(), "vector<int>");
}
Esempio n. 16
0
void inventory::restack(player *p)
{
    // tasks that the old restack seemed to do:
    // 1. reassign inventory letters
    // 2. remove items from non-matching stacks
    // 3. combine matching stacks

    if (!p) {
        return;
    }

    binned = false;
    std::list<item> to_restack;
    int idx = 0;
    for (invstack::iterator iter = items.begin(); iter != items.end(); ++iter, ++idx) {
        std::list<item> &stack = *iter;
        item &topmost = stack.front();

        const int ipos = p->invlet_to_position(topmost.invlet);
        if( !inv_chars.valid( topmost.invlet ) || ( ipos != INT_MIN && ipos != idx ) ) {
            assign_empty_invlet(topmost);
            for( std::list<item>::iterator stack_iter = stack.begin();
                 stack_iter != stack.end(); ++stack_iter ) {
                stack_iter->invlet = topmost.invlet;
            }
        }

        // remove non-matching items, stripping off end of stack so the first item keeps the invlet.
        while( stack.size() > 1 && !topmost.stacks_with(stack.back()) ) {
            to_restack.splice(to_restack.begin(), *iter, --stack.end());
        }
    }

    // combine matching stacks
    // separate loop to ensure that ALL stacks are homogeneous
    for (invstack::iterator iter = items.begin(); iter != items.end(); ++iter) {
        for (invstack::iterator other = iter; other != items.end(); ++other) {
            if (iter != other && iter->front().stacks_with( other->front() ) ) {
                if( other->front().count_by_charges() ) {
                    iter->front().charges += other->front().charges;
                } else {
                    iter->splice(iter->begin(), *other);
                }
                other = items.erase(other);
                --other;
            }
        }
    }

    //re-add non-matching items
    for( auto &elem : to_restack ) {
        add_item( elem );
    }

    //Ensure that all items in the same stack have the same invlet.
    for( std::list< item > &outer : items ) {
        for( item &inner : outer ) {
            inner.invlet = outer.front().invlet;
        }
    }
}
Esempio n. 17
0
void Expand_TestHarness(::AST::Crate& crate)
{
    // Create the following module:
    // ```
    // mod `#test` {
    //   extern crate std;
    //   extern crate test;
    //   fn main() {
    //     self::test::test_main_static(&::`#test`::TESTS);
    //   }
    //   static TESTS: [test::TestDescAndFn; _] = [
    //     test::TestDescAndFn { desc: test::TestDesc { name: "foo", ignore: false, should_panic: test::ShouldPanic::No }, testfn: ::path::to::foo },
    //     ];
    // }
    // ```

    // ---- main function ----
    auto main_fn = ::AST::Function { Span(), {}, ABI_RUST, false, false, false, TypeRef(TypeRef::TagUnit(), Span()), {} };
    {
        auto call_node = NEWNODE(_CallPath,
                ::AST::Path("test", { ::AST::PathNode("test_main_static") }),
                ::make_vec1(
                    NEWNODE(_UniOp, ::AST::ExprNode_UniOp::REF,
                        NEWNODE(_NamedValue, ::AST::Path("", { ::AST::PathNode("test#"), ::AST::PathNode("TESTS") }))
                        )
                    )
                );
        main_fn.set_code( mv$(call_node) );
    }


    // ---- test list ----
    ::std::vector< ::AST::ExprNodeP>    test_nodes;

    for(const auto& test : crate.m_tests)
    {
        // HACK: Don't emit should_panic tests
        if( test.panic_type != ::AST::TestDesc::ShouldPanic::No )
            continue ;

        ::AST::ExprNode_StructLiteral::t_values   desc_vals;
        // `name: "foo",`
        desc_vals.push_back({ {}, "name", NEWNODE(_CallPath,
                        ::AST::Path("test", { ::AST::PathNode("StaticTestName") }),
                        ::make_vec1( NEWNODE(_String,  test.name) )
                        ) });
        // `ignore: false,`
        desc_vals.push_back({ {}, "ignore", NEWNODE(_Bool,  test.ignore) });
        // `should_panic: ShouldPanic::No,`
        {
            ::AST::ExprNodeP    should_panic_val;
            switch(test.panic_type)
            {
            case ::AST::TestDesc::ShouldPanic::No:
                should_panic_val = NEWNODE(_NamedValue,  ::AST::Path("test", { ::AST::PathNode("ShouldPanic"), ::AST::PathNode("No") }));
                break;
            case ::AST::TestDesc::ShouldPanic::Yes:
                should_panic_val = NEWNODE(_NamedValue,  ::AST::Path("test", { ::AST::PathNode("ShouldPanic"), ::AST::PathNode("Yes") }));
                break;
            case ::AST::TestDesc::ShouldPanic::YesWithMessage:
                should_panic_val = NEWNODE(_CallPath,
                        ::AST::Path("test", { ::AST::PathNode("ShouldPanic"), ::AST::PathNode("YesWithMessage") }),
                        make_vec1( NEWNODE(_String, test.expected_panic_message) )
                        );
                break;
            }
            desc_vals.push_back({ {}, "should_panic", mv$(should_panic_val) });
        }
        auto desc_expr = NEWNODE(_StructLiteral,  ::AST::Path("test", { ::AST::PathNode("TestDesc")}), nullptr, mv$(desc_vals));

        ::AST::ExprNode_StructLiteral::t_values   descandfn_vals;
        descandfn_vals.push_back({ {}, ::std::string("desc"), mv$(desc_expr) });

        auto test_type_var_name  = test.is_benchmark ? "StaticBenchFn" : "StaticTestFn";
        descandfn_vals.push_back({ {}, ::std::string("testfn"), NEWNODE(_CallPath,
                        ::AST::Path("test", { ::AST::PathNode(test_type_var_name) }),
                        ::make_vec1( NEWNODE(_NamedValue, AST::Path(test.path)) )
                        ) });

        test_nodes.push_back( NEWNODE(_StructLiteral,  ::AST::Path("test", { ::AST::PathNode("TestDescAndFn")}), nullptr, mv$(descandfn_vals) ) );
    }
    auto* tests_array = new ::AST::ExprNode_Array(mv$(test_nodes));

    size_t test_count = tests_array->m_values.size();
    auto tests_list = ::AST::Static { ::AST::Static::Class::STATIC,
        TypeRef(TypeRef::TagSizedArray(), Span(),
                TypeRef(Span(), ::AST::Path("test", { ::AST::PathNode("TestDescAndFn") })),
                ::std::shared_ptr<::AST::ExprNode>( new ::AST::ExprNode_Integer(test_count, CORETYPE_UINT) )
               ),
        ::AST::Expr( mv$(tests_array) )
        };

    // ---- module ----
    auto newmod = ::AST::Module { ::AST::Path("", { ::AST::PathNode("test#") }) };
    // - TODO: These need to be loaded too.
    //  > They don't actually need to exist here, just be loaded (and use absolute paths)
    newmod.add_ext_crate(false, "std", "std", {});
    newmod.add_ext_crate(false, "test", "test", {});

    newmod.add_item(false, "main", mv$(main_fn), {});
    newmod.add_item(false, "TESTS", mv$(tests_list), {});

    crate.m_root_module.add_item(false, "test#", mv$(newmod), {});
    crate.m_lang_items["mrustc-main"] = ::AST::Path("", { AST::PathNode("test#"), AST::PathNode("main") });
}
Esempio n. 18
0
void inventory::form_from_map( const tripoint &origin, int range, bool assign_invlet )
{
    items.clear();

    std::set<vehicle *> vehs;

    for( const tripoint &p : g->m.points_in_radius( origin, range ) ) {
        if (g->m.has_furn( p ) && g->m.accessible_furniture( origin, p, range )) {
            const furn_t &f = g->m.furn( p ).obj();
            const itype *type = f.crafting_pseudo_item_type();
            if (type != NULL) {
                const itype *ammo = f.crafting_ammo_item_type();
                item furn_item( type, calendar::turn, ammo ? count_charges_in_list( ammo, g->m.i_at( p ) ) : 0 );
                furn_item.item_tags.insert("PSEUDO");
                add_item(furn_item);
            }
        }
        if( !g->m.accessible_items( origin, p, range ) ) {
            continue;
        }
        for (auto &i : g->m.i_at( p )) {
            if (!i.made_of(LIQUID)) {
                add_item(i, false, assign_invlet);
            }
        }
        // Kludges for now!
        if (g->m.has_nearby_fire( p, 0 )) {
            item fire("fire", 0);
            fire.charges = 1;
            add_item(fire);
        }
        // Handle any water from infinite map sources.
        item water = g->m.water_from( p );
        if( !water.is_null() ) {
            add_item( water );
        }
        // kludge that can probably be done better to check specifically for toilet water to use in
        // crafting
        if (g->m.furn( p ).obj().examine == &iexamine::toilet) {
            // get water charges at location
            auto toilet = g->m.i_at( p );
            auto water = toilet.end();
            for( auto candidate = toilet.begin(); candidate != toilet.end(); ++candidate ) {
                if( candidate->typeId() == "water" ) {
                    water = candidate;
                    break;
                }
            }
            if( water != toilet.end() && water->charges > 0) {
                add_item( *water );
            }
        }

        // keg-kludge
        if (g->m.furn( p ).obj().examine == &iexamine::keg) {
            auto liq_contained = g->m.i_at( p );
            for( auto &i : liq_contained ) {
                if( i.made_of(LIQUID) ) {
                    add_item(i);
                }
            }
        }

        int vpart = -1;
        vehicle *veh = g->m.veh_at( p, vpart );

        if( veh == nullptr ) {
            continue;
        }

        vehs.insert( veh );

        const int cargo = veh->part_with_feature(vpart, "CARGO");
        if (cargo >= 0) {
            *this += std::list<item>( veh->get_items(cargo).begin(),
                                      veh->get_items(cargo).end() );
        }

        for( const auto pt : veh->get_parts( p ) ) {
            // does any part on this tile provide any pseudo-tools?
            for( const auto &e : pt->info().tools ) {
                item obj( e );
                obj.ammo_set( obj.ammo_default(), veh->fuel_left( obj.ammo_default() ) );
                add_item( obj.set_flag( "PSEUDO" ) );
            }
        }
    }

    for( const vehicle *v : vehs ) {
        // if vehicle has FAUCET can use contents from any of the tanks
        if( v->has_part( "FAUCET" ) ) {
            for( const auto &pt : v->parts ) {
                if( pt.is_tank() ) {
                    for( const auto &obj : pt.contents() ) {
                        add_item( obj );
                    }
                }
            }
        }
    }
}
Esempio n. 19
0
static void
add_obj(void *opaque, void *parent, const char *name, void *child)
{
  add_item(opaque, parent, name, OBJECT_TO_JSVAL(child));
}
Esempio n. 20
0
Item*
Bchart::
edgesFromTree(InputTree* tree)
{
  int b, b0;
  b0 = tree->num();
  const Term* trm = Term::get(tree->term());
  assert(trm);
  //cerr << "ARI " << *trm << " " << b0 << endl;
  if(printDebug() > 1005)
    cerr << "EFIE " << trm->name() << " " << b0 << endl;
  /* If this is a terminal node, the rhs will be a word; otherwise it
     will be a rule expansion consisting of several Item s.
   */
  if(trm->terminal_p())
    {
      ECString tmpW1 = tree->word();
      char chars[512];
      ECString tmpW = toLower(tmpW1.c_str(), chars);
      
      int wInt = wtoInt(tmpW);
      Item* lhs = add_item(b0, trm, tree->start());
      lhs->start() = tree->start();
      lhs->finish() = tree->finish();
      Item* rhs = add_item2(b0, trm, wInt,tmpW);
      rhs->finish() = tree->finish();
      rhs->start() = tree->start();
      if(!lhs && !rhs)
	{
	  return NULL;
	}

      Items subItems;
      subItems.push_back(stops[tree->start()]);
      subItems.push_back(rhs);
      subItems.push_back(stops[tree->finish()]);
      Edge* edg = add_edge(lhs, subItems);
      if(!edg)
	{
	  return NULL;
	}
      edg->prob() = pHst(wInt,trm->toInt());
      edg->num() = b0;
      if(printDebug() > 5)
	cerr << "LHS " << *lhs << " " << tmpW  << edg->prob() << endl;
	  
      return lhs;
    }
  else
    {
      Item* lhs = add_item(b0, trm, -1);
      lhs->start() = tree->start();
      lhs->finish() = tree->finish();
      assert(lhs);
      Items subItems;
      subItems.push_back(stops[tree->start()]);
      InputTreesIter iti = tree->subTrees().begin();
      for( ; iti != tree->subTrees().end() ; iti++)
	{
	  InputTree* stree = (*iti);
	  cerr << "WBA "<< stree->term() << *stree   << endl;
	  Item* itm = edgesFromTree(stree);
	  if(!itm)
	    {
	      return NULL;
	    }
	  subItems.push_back(itm);
	}
      subItems.push_back(stops[tree->finish()]);
      Edge* edg = add_edge(lhs, subItems);
      if(!edg)
	{
	  return false;
	}
      edg->num() = b0;
      assignRProb(edg);
      if (printDebug() > 5)
	{
	  cerr << "Saw edge " << *edg << ": p=" << edg->prob() << endl;
	}
      //cerr << "endeFE " << *edg << endl;
      return lhs;
      rPendFactor();
    }
}
Esempio n. 21
0
static void 
add_null(void *opaque, void *parent, const char *name)
{
  add_item(opaque, parent, name, JSVAL_NULL);
}
Esempio n. 22
0
void C_ConfigManager::setup_item(bool * pointer, bool value, std::string name) {
	add_item(pointer, name.c_str(), "bool");
	*pointer = value;
}
Esempio n. 23
0
inventory& inventory::operator+= (const std::vector<item> &rhs)
{
 for (int i = 0; i < rhs.size(); i++)
  add_item(rhs[i]);
 return *this;
}
Esempio n. 24
0
void C_ConfigManager::setup_item(float * pointer, float value, std::string name) {
	add_item(pointer, name.c_str(), "float");
	*pointer = value;
}
Esempio n. 25
0
void inventory::add_item_keep_invlet(item newit)
{
 add_item(newit, true);
}
Esempio n. 26
0
void C_ConfigManager::setup_item(ButtonCode_t * pointer, ButtonCode_t value, std::string name) {
	add_item(pointer, name.c_str(), "ButtonCode");
	*pointer = value;
}
Esempio n. 27
0
void inventory::form_from_map(game *g, point origin, int range, bool assign_invlet)
{
 items.clear();
 for (int x = origin.x - range; x <= origin.x + range; x++) {
  for (int y = origin.y - range; y <= origin.y + range; y++) {
   int junk;
   if (g->m.has_flag("SEALED", x, y) ||
       ((origin.x != x || origin.y != y) &&
        !g->m.clear_path( origin.x, origin.y, x, y, range, 1, 100, junk ) ) ) {
     continue;
   }
   for (int i = 0; i < g->m.i_at(x, y).size(); i++)
    if (!g->m.i_at(x, y)[i].made_of(LIQUID))
     add_item(g->m.i_at(x, y)[i], false, assign_invlet);
// Kludges for now!
   ter_id terrain_id = g->m.ter(x, y);
   if ((g->m.field_at(x, y).findField(fd_fire)) || (terrain_id == t_lava)) {
    item fire(itypes["fire"], 0);
    fire.charges = 1;
    add_item(fire);
   }
   if (terrain_id == t_water_sh || terrain_id == t_water_dp){
    item water(itypes["water"], 0);
    water.charges = 50;
    add_item(water);
   }
   // kludge that can probably be done better to check specifically for toilet water to use in
   // crafting
   if (furnlist[g->m.furn(x,y)].examine == &iexamine::toilet){
    // get water charges at location
     std::vector<item> toiletitems = g->m.i_at(x,y);
     int waterindex = -1;
     for (int i = 0; i < toiletitems.size(); ++i){
        if (toiletitems[i].typeId() == "water"){
            waterindex = i;
            break;
        }
     }
     if (waterindex >= 0 && toiletitems[waterindex].charges > 0){
        add_item(toiletitems[waterindex]);
     }

   }

   int vpart = -1;
   vehicle *veh = g->m.veh_at(x, y, vpart);

   if (veh) {
     const int kpart = veh->part_with_feature(vpart, "KITCHEN");
     const int weldpart = veh->part_with_feature(vpart, "WELDRIG");
     const int craftpart = veh->part_with_feature(vpart, "CRAFTRIG");
     const int forgepart = veh->part_with_feature(vpart, "FORGE");
     const int chempart = veh->part_with_feature(vpart, "CHEMLAB");

     if (kpart >= 0) {
       item hotplate(itypes["hotplate"], 0);
       hotplate.charges = veh->fuel_left("battery", true);
       add_item(hotplate);

       item water(itypes["water_clean"], 0);
       water.charges = veh->fuel_left("water");
       add_item(water);

       item pot(itypes["pot"], 0);
       add_item(pot);
       item pan(itypes["pan"], 0);
       add_item(pan);
       }
     if (weldpart >= 0) {
       item welder(itypes["welder"], 0);
       welder.charges = veh->fuel_left("battery", true);
       add_item(welder);

       item soldering_iron(itypes["soldering_iron"], 0);
       soldering_iron.charges = veh->fuel_left("battery", true);
       add_item(soldering_iron);
       }
     if (craftpart >= 0) {
       item vac_sealer(itypes["vac_sealer"], 0);
       vac_sealer.charges = veh->fuel_left("battery", true);
       add_item(vac_sealer);

       item dehydrator(itypes["dehydrator"], 0);
       dehydrator.charges = veh->fuel_left("battery", true);
       add_item(dehydrator);

       item press(itypes["press"], 0);
       press.charges = veh->fuel_left("battery", true);
       add_item(press);
       }
     if (forgepart >= 0) {
       item forge(itypes["forge"], 0);
       forge.charges = veh->fuel_left("battery", true);
       add_item(forge);
       }
     if (chempart >= 0) {
       item hotplate(itypes["hotplate"], 0);
       hotplate.charges = veh->fuel_left("battery", true);
       add_item(hotplate);

       item chemistry_set(itypes["chemistry_set"], 0);
       chemistry_set.charges = veh->fuel_left("battery", true);
       add_item(chemistry_set);
       }
     }
   }

  }
 }
Esempio n. 28
0
void C_ConfigManager::setup_item(Color * pointer, Color value, std::string name) {
	add_item(pointer, name.c_str(), "Color");
	*pointer = value;
}
Esempio n. 29
0
/* Compute the disk submenu */
int compute_disk_module(struct s_my_menu *menu, int nb_sub_disk_menu,
                        struct diskinfo *d, int disk_number)
{
  char buffer[MENULEN + 1];
  char statbuffer[STATLEN + 1];

  /* No need to add no existing devices */
  if (strlen(d[disk_number].aid.model) <= 0)
    return -1;

  snprintf(buffer, sizeof buffer, " Disk <%d> ", nb_sub_disk_menu);
  menu[nb_sub_disk_menu].menu = add_menu(buffer, -1);
  menu[nb_sub_disk_menu].items_count = 0;

  snprintf(buffer, sizeof buffer, "Model        : %s",
     d[disk_number].aid.model);
  snprintf(statbuffer, sizeof statbuffer, "Model: %s",
     d[disk_number].aid.model);
  add_item(buffer, statbuffer, OPT_INACTIVE, NULL, 0);
  menu[nb_sub_disk_menu].items_count++;

  /* Compute device size */
  char previous_unit[3], unit[3]; //GB
  int previous_size, size = d[disk_number].sectors / 2; // Converting to bytes
  strlcpy(unit, "KB", 2);
  strlcpy(previous_unit, unit, 2);
  previous_size = size;
  if (size > 1000) {
    size = size / 1000;
    strlcpy(unit, "MB", 2);
    if (size > 1000) {
      previous_size = size;
      size = size / 1000;
      strlcpy(previous_unit, unit, 2);
      strlcpy(unit, "GB", 2);
      if (size > 1000) {
        previous_size = size;
        size = size / 1000;
        strlcpy(previous_unit, unit, 2);
        strlcpy(unit, "TB", 2);
      }
    }
  }

  snprintf(buffer, sizeof buffer, "Size         : %d %s (%d %s)", size,
     unit, previous_size, previous_unit);
  snprintf(statbuffer, sizeof statbuffer, "Size: %d %s (%d %s)", size,
     unit, previous_size, previous_unit);
  add_item(buffer, statbuffer, OPT_INACTIVE, NULL, 0);
  menu[nb_sub_disk_menu].items_count++;

  snprintf(buffer, sizeof buffer, "Firmware Rev.: %s",
     d[disk_number].aid.fw_rev);
  snprintf(statbuffer, sizeof statbuffer, "Firmware Revision: %s",
     d[disk_number].aid.fw_rev);
  add_item(buffer, statbuffer, OPT_INACTIVE, NULL, 0);
  menu[nb_sub_disk_menu].items_count++;

  snprintf(buffer, sizeof buffer, "Serial Number: %s",
     d[disk_number].aid.serial_no);
  snprintf(statbuffer, sizeof statbuffer, "Serial Number: %s",
     d[disk_number].aid.serial_no);
  add_item(buffer, statbuffer, OPT_INACTIVE, NULL, 0);
  menu[nb_sub_disk_menu].items_count++;

  snprintf(buffer, sizeof buffer, "Interface    : %s",
     d[disk_number].interface_type);
  snprintf(statbuffer, sizeof statbuffer, "Interface: %s",
     d[disk_number].interface_type);
  add_item(buffer, statbuffer, OPT_INACTIVE, NULL, 0);
  menu[nb_sub_disk_menu].items_count++;

  snprintf(buffer, sizeof buffer, "Host Bus     : %s",
     d[disk_number].host_bus_type);
  snprintf(statbuffer, sizeof statbuffer, "Host Bus Type: %s",
     d[disk_number].host_bus_type);
  add_item(buffer, statbuffer, OPT_INACTIVE, NULL, 0);
  menu[nb_sub_disk_menu].items_count++;

  snprintf(buffer, sizeof buffer, "Sectors      : %d",
     d[disk_number].sectors);
  snprintf(statbuffer, sizeof statbuffer, "Sectors: %d",
     d[disk_number].sectors);
  add_item(buffer, statbuffer, OPT_INACTIVE, NULL, 0);
  menu[nb_sub_disk_menu].items_count++;

  snprintf(buffer, sizeof buffer, "Heads        : %d",
     d[disk_number].heads);
  snprintf(statbuffer, sizeof statbuffer, "Heads: %d",
     d[disk_number].heads);
  add_item(buffer, statbuffer, OPT_INACTIVE, NULL, 0);
  menu[nb_sub_disk_menu].items_count++;

  snprintf(buffer, sizeof buffer, "Cylinders    : %d",
     d[disk_number].cylinders);
  snprintf(statbuffer, sizeof statbuffer, "Cylinders: %d",
     d[disk_number].cylinders);
  add_item(buffer, statbuffer, OPT_INACTIVE, NULL, 0);
  menu[nb_sub_disk_menu].items_count++;

  snprintf(buffer, sizeof buffer, "Sectors/Track: %d",
     d[disk_number].sectors_per_track);
  snprintf(statbuffer, sizeof statbuffer, "Sectors per Track: %d",
     d[disk_number].sectors_per_track);
  add_item(buffer, statbuffer, OPT_INACTIVE, NULL, 0);
  menu[nb_sub_disk_menu].items_count++;

  snprintf(buffer, sizeof buffer, "Port         : 0x%X", disk_number);
  snprintf(statbuffer, sizeof statbuffer, "Port: 0x%X", disk_number);
  add_item(buffer, statbuffer, OPT_INACTIVE, NULL, 0);
  menu[nb_sub_disk_menu].items_count++;

  snprintf(buffer, sizeof buffer, "EDD Version  : %s",
     d[disk_number].edd_version);
  snprintf(statbuffer, sizeof statbuffer, "EDD Version: %s",
     d[disk_number].edd_version);
  add_item(buffer, statbuffer, OPT_INACTIVE, NULL, 0);
  menu[nb_sub_disk_menu].items_count++;

  return 0;
}
Esempio n. 30
0
int main (int argc, char **argv) {

	int *table;
	int table_size = 4; // 0,1,2,3 are special
	int nbits = 9; // Always start with 512 item table.	
	int max_bits = 0, prev_code = 0;
	int maxed = 0;
	int choose;

	choose = which(argv);

	table = calloc( (1 << nbits), sizeof(int));
	init_table(table, nbits, &table_size);


	// Encode
	if ( choose == 1 ) {
	
		// Prove that ncode created the file.
		putBits(nbits, MAGIC1);
		putBits(nbits, MAGIC2);

		// Get max_bits
		int tmp;
		tmp = get_arg(argv, argc, 'm');
		max_bits = get_m_arg(argv, tmp);
		if (max_bits < 0) {
			exit(0);
		}
		putBits(nbits, max_bits);

		// Get ratio
		int c, check_time;
		int code_bits = 0, char_bits = 0, count = 0;
		double ratio;
		tmp = get_arg(argv, argc, 'r');
		check_time = get_r_arg(argv, tmp, &ratio);
		if (check_time < 0) {
			exit(0);
		}
	
	
		// Let's go
		while ((c = getchar()) != EOF) {
			char_bits += 8;
			// Item found, read next char
			if ( (tmp = item_exists(prev_code, c, table, nbits))) {
				prev_code = tmp;
				continue;
			}
			// item not found. Add item to table. Output prev_code. 
			// new prev_code is c's index
			else {
				code_bits += nbits;
				count++;
				if (!maxed) {
					add_item(prev_code, c, table, nbits, &table_size);
				}
				putBits(nbits, prev_code);

				prev_code = item_exists(0, c, table, nbits);

				// Resize table
				if (table_size > (0.99 * TABLE_SIZE) && !maxed) {
					if (nbits != max_bits) {
						code_bits += (2 * nbits) + 1;
						putBits(nbits++, 1);
						putBits(nbits, c);
						table = init_new(table, TABLE_SIZE, table_size, nbits);
					}
					else {
						maxed = 1;
						putBits(nbits, 2);
						code_bits += nbits;
					}
				}
				// -r
				if (check_time && !(count % check_time) && 
				(code_bits > ratio * char_bits)) {
					// re init
					putBits(nbits, 3);
					nbits = 9;
					free(table);
					table = calloc( (1 << nbits), sizeof(int));
					init_table(table, nbits, &table_size);

					maxed = 0;
					code_bits = 0;
					char_bits = 0;
				}
			}
		}
		putBits(nbits, prev_code);
		putBits(nbits, 0);
		flushBits();
		free(table);
	}


	// Decode
	else {

		int i, code, hold = 0, tmp_code, mx=0;
		len_array outstring;
		outstring.array = malloc(MAX_LEN * sizeof(int));

		// Check that there are no args
		if (argc != 1) {
			fprintf(stderr, "Unexpected argument to decode\n");
			exit(0);
		}

		// Check that this is actually a file we encoded
		if ( (getBits(nbits) != MAGIC1) || (getBits(nbits) != MAGIC2)) {
			fprintf(stderr, "Wrong file");
			exit(0);
		}

		// Let's go
		max_bits = getBits(nbits);

		while ( (code = getBits(nbits)) ) {
			outstring.len = 0;

			// Table resize
			if (code == 1) {
				nbits++;
				// get the next letter, add and resize
				code = getBits(nbits); 
				tmp_code = add_item(prev_code, code, table, nbits-1, 
				                    &table_size);
				table = init_new(table, TABLE_SIZE, table_size, nbits);
				hold = 1;
				continue;
			}

			// Size is maxed, set maxed after next add
			else if (code == 2) {
				mx = 1;
				continue;
			}

			// Reinit table
			else if (code == 3) {
				nbits = 9;
				free(table);
				table = calloc( (1 << nbits), sizeof(int));
				init_table(table, nbits, &table_size);
				prev_code = 0;
				maxed = 0;
				mx = 0;
				continue;
			}
			
			// Code in table
			else if ( (table[code] % 2)) {
				backtrace(table, code, &outstring);
				for (i=0; i<outstring.len; i++) {
					printf("%c", outstring.array[i]);
				}
				// If !prev_code, item has len 1 & will be there already
				// If maxed, table full
				// If hold, first add after resize - already there
				if (prev_code && !hold && !maxed) { 
					add_item(prev_code, outstring.array[0], table, nbits, 
					         &table_size);
				}
				prev_code = code;
			}

			// Item not found in table. Item must be the result of 
			// table[prev_code] + table[prev_code][0]
			// We also MUST be able to add it - no worries about max_bits
			else {
				backtrace(table, prev_code, &outstring);
				outstring.array[outstring.len++] = outstring.array[0];

				for (i=0; i<outstring.len; i++) {
					printf("%c", outstring.array[i]);
				}
				// If it is not the first one after a resize
				if (!hold) {
					prev_code = add_item(prev_code, outstring.array[0], table,
					                     nbits, &table_size);
				}
				else {
					prev_code = tmp_code;
				}

				// Check that we the code we get from adding is the expected
				if (prev_code != code) {
					fprintf(stderr, "File corrupted\n");
					exit(0);
				}
			}
			if (hold) {
				hold = 0;
			}
			if (mx) {
				mx = 0;
				maxed = 1;
			}
		}
		free(table);
		free(outstring.array);
	}
	return(0);
}