/** @brief Busca una región de memoria contigua libre dentro del mapa de bits
   * de memoria.
   * @param length Tamaño de la región de memoria a asignar.
   * @return Dirección de inicio de la región en memoria.
   * @verbatim
     Al inicio de esta funcion se verifica si no existen regiones
     libres lo cual retornaria 0. caso contrario Busca una region de memoria que tenga
     un tamaño mayor o igual a length disponible. si al hacer la busqueda no encuentra
     una region disponible dentro del mapa de bits entonces retornara 0, caso contrario retorna
     la direccion de inicio de la region de memoria.
    @endverbatim
   */
  char * allocate_unit_region(unsigned int length) {
	unsigned int unit;
	unsigned int unit_count;
	unsigned int i;
	int result;

	unit_count = (length / MEMORY_UNIT_SIZE);

	if (length % MEMORY_UNIT_SIZE > 0) {
		unit_count++;
	}

	//printf("\tAllocating %d units\n", unit_count);

	if (free_units < unit_count) {
		 //printf("Warning! out of memory!\n");
		 return 0;
	}

	/* Iterar por el mapa de bits*/
	unit = next_free_unit;

	 /* Iterar por el mapa de bits*/
	unit = next_free_unit;
	 do {
		 if (test_unit(unit) &&
				 (unit + unit_count) < (base_unit + total_units)) {

			 result = 1;
			 for (i=unit; i<unit + unit_count; i++){
				 result = (result && test_unit(i));
			 }
			 /* Marcar la unidad como libre */
			 if (result) {
				 for (i=unit; i<unit + unit_count; i++){
					 //printf("\tFree unit at %x\n", i *  MEMORY_UNIT_SIZE);
					 /* Descontar la unidad tomada */
					 free_units--;
					 clear_unit(i);
				 }

				 /* Avanzar en la posicion de busqueda de la proxima unidad
				 			  * disponible */
				 next_free_unit = unit + unit_count;
				 if (next_free_unit > base_unit + total_units) {
					 next_free_unit = base_unit;
				 }

				return (char*)(unit * MEMORY_UNIT_SIZE);
			 }
		 }
		unit++;
		if (unit > base_unit + total_units) {
			unit = base_unit;
		}
	 }while (unit != next_free_unit);

	  return 0;
  }
Beispiel #2
0
/**
 * Clears shroud (and fog) around the provided location for @a view_team
 * as if @a viewer was standing there.
 * This will also record sighted events, which should be either fired or
 * explicitly dropped.
 *
 * This should only be called if delayed shroud updates is off.
 * It is wasteful to call this if view_team uses neither fog nor shroud.
 *
 * @param instant          If false, then drawing delays (used to make movement look better) are allowed.
 *
 * @return whether or not information was uncovered (i.e. returns true if any
 *         locations in visual range were fogged/shrouded under shared vision/maps).
 */
bool shroud_clearer::clear_unit(const map_location &view_loc, team &view_team,
                                const clearer_info &viewer, bool instant)
{
	// Locate the unit in question.
	unit_map::const_iterator find_it = resources::gameboard->units().find(viewer.underlying_id);
	const map_location & real_loc = find_it == resources::gameboard->units().end() ?
		                                map_location::null_location() :
		                                find_it->get_location();

	return clear_unit(view_loc, view_team, viewer.underlying_id,
	                  viewer.sight_range, viewer.slowed, viewer.costs,
	                  real_loc, nullptr, nullptr, nullptr, nullptr, instant);
}
Beispiel #3
0
/**
 * Clears shroud (and fog) around the provided location for @a view_team
 * as if @a viewer was standing there.
 * This will also record sighted events, which should be either fired or
 * explicitly dropped.
 *
 * This should only be called if delayed shroud updates is off.
 * It is wasteful to call this if view_team uses neither fog nor shroud.
 *
 * @param known_units      These locations are not checked for uncovered units.
 * @param enemy_count      Incremented for each enemy uncovered (excluding known_units).
 * @param friend_count     Incremented for each friend uncovered (excluding known_units).
 * @param spectator        Will be told of uncovered units (excluding known_units).
 * @param instant          If false, then drawing delays (used to make movement look better) are allowed.
 *
 * @return whether or not information was uncovered (i.e. returns true if any
 *         locations in visual range were fogged/shrouded under shared vision/maps).
 */
bool shroud_clearer::clear_unit(const map_location &view_loc,
                                const unit &viewer, team &view_team,
                                const std::set<map_location>* known_units,
                                std::size_t * enemy_count, std::size_t * friend_count,
                                move_unit_spectator * spectator, bool instant)
{
	// This is just a translation to the more general interface. It is
	// not inlined so that vision.hpp does not have to include unit.hpp.
	return clear_unit(view_loc, view_team, viewer.underlying_id(),
	                  viewer.vision(), viewer.get_state(unit::STATE_SLOWED),
	                  viewer.movement_type().get_vision(), viewer.get_location(),
	                  known_units, enemy_count, friend_count, spectator, instant);
}
Beispiel #4
0
/**
 * Clears shroud (and fog) around the provided location as if @a viewer
 * was standing there.
 * This version of shroud_clearer::clear_unit() will abort if the viewer's
 * team uses neither fog nor shroud. If @a can_delay is left as true, then
 * this function also aborts on the viewing team's turn if delayed shroud
 * updates is on. (Not supplying a team suggests that it would be inconvenient
 * for the caller to check these.)
 * In addition, if @a invalidate is left as true, invalidate_after_clear()
 * will be called.
 * Setting @a instant to false allows some drawing delays that are used to
 * make movement look better.
 *
 * @return whether or not information was uncovered (i.e. returns true if any
 *         locations in visual range were fogged/shrouded under shared vision/maps).
 */
bool shroud_clearer::clear_unit(const map_location &view_loc, const unit &viewer,
                                bool can_delay, bool invalidate, bool instant)
{
	team & viewing_team = resources::gameboard->get_team(viewer.side());

	// Abort if there is nothing to clear.
	if ( !viewing_team.fog_or_shroud() )
		return false;
	if ( can_delay  &&  !viewing_team.auto_shroud_updates()  &&
	     viewer.side() == resources::controller->current_side()  )
		return false;

	if ( !clear_unit(view_loc, viewer, viewing_team, instant) )
		// Nothing uncovered.
		return false;

	if ( invalidate )
		invalidate_after_clear();

	return true;
}
Beispiel #5
0
	/// Clears shroud (and fog) around the provided location for @a view_team
	/// as if @a viewer was standing there. Setting @a instant to true
	/// suppresses some drawing delays that are used to make animations look better.
	bool clear_unit(const map_location &view_loc, const unit &viewer,
	                team &view_team, bool instant)
	{ return clear_unit(view_loc, viewer, view_team, NULL, NULL, NULL, NULL, instant); }