Example #1
0
void EuclideanMenuSlice::resizeViews()
{
    if (!window) {
        return;
    }

    //The main view is the size of the RenderWindow, always.
    sf::Vector2u sz = window->getSize();
    mainView.setCenter(0, 0);
    mainView.setSize(sz.x, sz.y);

    //The minimap view is the size of the entire 2-D map area to render, and is centered on it. It's also off-center
    std::pair<double, double> xRng(-500, 500); //min/max
    std::pair<double, double> yRng(-500, 500); //min/max

    //
    // TODO: We need a spatial index to return the bounds. We *also* need to include the size of the object,
    //       not just its position. We *also* need to subclass Drawable (since we aren't always adding Shapes).
    //

    //Better init.
    if (!isItemsEmpty()) {
        //TEMP: casting...
        xRng.first = xRng.second = ((sf::Shape*)get_first_item())->getPosition().x;
        yRng.first = yRng.second = ((sf::Shape*)get_first_item())->getPosition().y;
    }

    //Measure it.
    check_all_items();
    items_sp.forAllItems([&xRng, &yRng](AbstractGameObject* item) {
//	for (sf::Drawable* item : items) {
        geom::Rectangle bounds = item->getBounds();
        xRng.first = std::min(xRng.first, bounds.x);
        xRng.second = std::max(xRng.second, bounds.x+bounds.width);
        yRng.first = std::min(yRng.first, bounds.y);
        yRng.second = std::max(yRng.second, bounds.y+bounds.height);
//	}
    });

    //Set it.
    float xDiff = xRng.second-xRng.first;
    float yDiff = yRng.second-yRng.first;

    //TEMP: Widen it
    xRng.first -= 300;
    yRng.first -= 300;
    xDiff += 600;
    yDiff += 600;

    minimapView.setCenter(xRng.first+xDiff/2.0, yRng.first+yDiff/2.0);
    minimapView.setSize(xDiff, yDiff);
    minimapView.setViewport(sf::FloatRect(0.79, 0.01, 0.2, 0.2));
}
Example #2
0
static void some_really_long_function_name(
    struct device *dev, struct device_driver *drv)
{
    if ((some_variable_name &&
         somefunction(param1, param2, param3))) {
        asdfghjk = asdfasdfasd.aasdfasd +
                   (asdfasd.asdas * 1234.65);
    }

    for (struct something_really_really_excessive *
         a_long_ptr_name = get_first_item();
         a_long_ptr_name != NULL;
         a_long_ptr_name = get_next_item(a_long_ptr_name))
    {
    }

    for (a = get_first(); a != NULL; a = get_next(a))
    {
    }

    for (a_ptr = get_first();
         a_ptr != NULL;
         a_ptr = get_next(a))
    {
    }

    register_clcmd(
        "examine", "do_examine", -1,
        "-Allows a player to examine the health and armor of a teammate" );
    register_clcmd(
        "/examine", "do_examine", -1,
        "-Allows a player to examine the health and armor of a teammate" );
}
Example #3
0
	bool del_item(uint32_t item_id, uint32_t item_count)
	{
		if( !check_del_item(item_id, item_count))return false;
		
		uint32_t total_del_count = item_count;

		while(total_del_count)
		{
			item* p_item = get_first_item(item_id);	
			uint32_t cur_heap_count = p_item->get_cur_heap_count();	

			if(cur_heap_count > item_count)
			{
				p_item->dec_cur_heap_count(item_count);
				total_del_count -= item_count;
			}
			else
			{
				p_item->dec_cur_heap_count(item_count);
				total_del_count -= cur_heap_count;	

				p_item->clear_to_item();
				item_grid[p_item->bag_index_] = NULL;
				item_factory::get_instance()->destroy_item(p_item);
				p_item = NULL;
			}	
		}
		return true;
	}
Example #4
0
	bool   check_add_item(uint32_t item_id, uint32_t item_count)
	{
		item_data* p_data = item_data_mgr::get_instance()->get_item_data_by_id(item_id);
		item* p_item = 	get_first_item(item_id);

		int32_t remain_count = item_count;
		uint32_t need_grid_count = 0;
		if(p_item == NULL)
		{
			need_grid_count = item_count / p_data->max_heap_num_  + (item_count % p_data->max_heap_num_ ? 1:0 );
		}
		else
		{
			while(p_item)
			{
				uint32_t count = p_item->get_cur_remain_heap_count();
				remain_count -= count; 
				p_item = get_next_item(p_item);	
				if(remain_count < 0)
				{
					remain_count = 0;
					break;
				}
			}
			need_grid_count = remain_count / p_data->max_heap_num_  + (remain_count % p_data->max_heap_num_ ? 1:0 );
		}
		return need_grid_count >= get_empty_grid_count();
	}
Example #5
0
	bool add_item(uint32_t item_id, uint32_t item_count)
	{
		if( !check_add_item(item_id, item_count))return false;

		uint32_t remain_count = item_count;	

		item* p_item =  get_first_item(item_id);

		if(p_item == NULL)
		{
			return add_item_to_empty_grid(item_id, item_count);
		}
		else
		{
			while(p_item)
			{
				uint32_t remain_heap_count = p_item->get_cur_remain_heap_count();
				if(remain_heap_count == 0)continue;
				
				if(remain_heap_count <= remain_count)
				{
					p_item->inc_cur_heap_count( remain_heap_count);	
					remain_count -= remain_heap_count;
				}
				else
				{
					p_item->inc_cur_heap_count(remain_count);	
					remain_count = 0;
					break;
				}	
				p_item = get_next_item(p_item);
			}
			if(remain_count > 0)
			{
				return add_item_to_empty_grid(item_id, remain_count);
			}	
		}
		return true;	
	}