Esempio n. 1
0
/****************************************************************************
  Return color for overview map tile.
****************************************************************************/
static struct color *overview_tile_color(struct tile *ptile)
{
  if (overview.layers[OLAYER_CITIES]) {
    struct city *pcity = tile_city(ptile);

    if (pcity) {
      if (NULL == client.conn.playing
          || city_owner(pcity) == client.conn.playing) {
	return get_color(tileset, COLOR_OVERVIEW_MY_CITY);
      } else if (pplayers_allied(city_owner(pcity), client.conn.playing)) {
	/* Includes teams. */
	return get_color(tileset, COLOR_OVERVIEW_ALLIED_CITY);
      } else {
	return get_color(tileset, COLOR_OVERVIEW_ENEMY_CITY);
      }
    }
  }
  if (overview.layers[OLAYER_UNITS]) {
    struct unit *punit = find_visible_unit(ptile);

    if (punit) {
      if (NULL == client.conn.playing
          || unit_owner(punit) == client.conn.playing) {
	return get_color(tileset, COLOR_OVERVIEW_MY_UNIT);
      } else if (pplayers_allied(unit_owner(punit), client.conn.playing)) {
	/* Includes teams. */
	return get_color(tileset, COLOR_OVERVIEW_ALLIED_UNIT);
      } else {
	return get_color(tileset, COLOR_OVERVIEW_ENEMY_UNIT);
      }
    }
  }
  if (overview.layers[OLAYER_BORDERS]) {
    struct player *owner = tile_owner(ptile);

    if (owner) {
      if (overview.layers[OLAYER_BORDERS_ON_OCEAN]) {
        return get_player_color(tileset, owner);
      } else if (!is_ocean_tile(ptile)) {
        return get_player_color(tileset, owner);
      }
    }
  }
  if (overview.layers[OLAYER_RELIEF] && tile_terrain(ptile) != T_UNKNOWN) {
    return get_terrain_color(tileset, tile_terrain(ptile));
  }
  if (overview.layers[OLAYER_BACKGROUND] && tile_terrain(ptile) != T_UNKNOWN) {
    if (is_ocean_tile(ptile)) {
      return get_color(tileset, COLOR_OVERVIEW_OCEAN);
    } else {
      return get_color(tileset, COLOR_OVERVIEW_LAND);
    }
  }

  return get_color(tileset, COLOR_OVERVIEW_UNKNOWN);
}
Esempio n. 2
0
/******************************************************************************\
 Adjusts globe vertices to show the tile's height. Updates the globe with data
 from the [r_tiles] array.
\******************************************************************************/
void R_configure_globe(void)
{
        c_vec2_t tile;
        float left, right, top, bottom, tmp;
        int i, tx, ty, terrain;

        C_debug("Configuring globe");
        C_var_unlatch(&r_globe_transitions);

        /* UV dimensions of tile boundary box */
        tile.x = 2.f * (r_terrain_tex->surface->w / R_TILE_SHEET_W) /
                 r_terrain_tex->surface->w;
        tile.y = 2.f * (int)(C_SIN_60 * r_terrain_tex->surface->h /
                             R_TILE_SHEET_H / 2) / r_terrain_tex->surface->h;

        for (i = 0; i < r_tiles_max; i++) {
                set_tile_height(i, r_tiles[i].height);

                /* Tile terrain texture */
                terrain = tile_terrain(i);
                ty = terrain / R_TILE_SHEET_W;
                tx = terrain - ty * R_TILE_SHEET_W;
                left = tx / 2 * tile.x + C_SIN_60 * R_TILE_BORDER;
                right = (tx / 2 + 1) * tile.x - C_SIN_60 * R_TILE_BORDER;
                if (tx & 1) {
                        bottom = ty * tile.y + C_SIN_30 * R_TILE_BORDER;
                        top = (ty + 1.f) * tile.y - C_SIN_60 * R_TILE_BORDER;
                        left += tile.x / 2.f;
                        right += tile.x / 2.f;
                } else {
                        top = ty * tile.y + R_TILE_BORDER;
                        bottom = (ty + 1.f) * tile.y - C_SIN_30 * R_TILE_BORDER;
                }

                /* Flip tiles are mirrored over the middle */
                if (i < flip_limit) {
                        tmp = left;
                        left = right;
                        right = tmp;
                }

                r_globe_verts[3 * i].v.uv = C_vec2((left + right) / 2.f, top);
                r_globe_verts[3 * i + 1].v.uv = C_vec2(left, bottom);
                r_globe_verts[3 * i + 2].v.uv = C_vec2(right, bottom);
        }
        for (i = 0; i < r_tiles_max; i++)
                compute_tile_vectors(i);
        smooth_normals();

        /* We can update normals dynamically from now on */
        r_globe_smooth.edit = C_VE_FUNCTION;
        r_globe_smooth.update = globe_smooth_update;

        /* If Vertex Buffer Objects are supported, upload the vertices now */
        R_vbo_cleanup(&r_globe_vbo);
        R_vbo_init(&r_globe_vbo, &r_globe_verts[0].v,
                   3 * r_tiles_max, sizeof (*r_globe_verts),
                   R_VERTEX3_FORMAT, NULL, 0);
}
Esempio n. 3
0
/**************************************************************************
  Calculate the benefit of transforming the given tile.

  The return value is the goodness of the tile after the transform.  This
  should be compared to the goodness of the tile currently (see
  city_tile_value(); note that this depends on the AI's weighting
  values).
**************************************************************************/
static int adv_calc_transform(const struct city *pcity,
                             const struct tile *ptile)
{
  int goodness;
  struct tile *vtile;
  struct terrain *old_terrain, *new_terrain;

  fc_assert_ret_val(ptile != NULL, -1)

  old_terrain = tile_terrain(ptile);
  new_terrain = old_terrain->transform_result;

  if (old_terrain == new_terrain || new_terrain == T_NONE) {
    return -1;
  }

  if (is_ocean(old_terrain) && !is_ocean(new_terrain)
      && !can_reclaim_ocean(ptile)) {
    /* Can't change ocean into land here. */
    return -1;
  }
  if (is_ocean(new_terrain) && !is_ocean(old_terrain)
      && !can_channel_land(ptile)) {
    /* Can't change land into ocean here. */
    return -1;
  }

  if (tile_city(ptile) && terrain_has_flag(new_terrain, TER_NO_CITIES)) {
    return -1;
  }

  vtile = tile_virtual_new(ptile);
  tile_change_terrain(vtile, new_terrain);
  goodness = city_tile_value(pcity, vtile, 0, 0);
  tile_virtual_destroy(vtile);

  return goodness;
}
Esempio n. 4
0
// TODO: Support irrigation modes
JNIEXPORT jbyteArray JNICALL Java_net_hackcasual_freeciv_NativeHarness_getAvailableCommandsForActiveUnit
  (JNIEnv * env, jobject obj) {
	struct unit * pUnit;
	char availCommands[COM_UNIT_LAST];
	int commandCount = 0;

	pUnit = head_of_units_in_focus();

	if (pUnit) {

	    struct tile *pTile = pUnit->tile;
	    struct city *pCity = tile_city(pTile);
	    struct terrain *pTerrain = tile_terrain(pTile);
	    struct base_type *pbase;
	    struct unit_list *punits = get_units_in_focus();


		if (can_unit_build_city(pUnit)) {
			availCommands[commandCount++] = COM_BUILD_CITY;
		}

		if (can_unit_do_activity(pUnit, ACTIVITY_GOTO)) {
			availCommands[commandCount++] = COM_GO_TO;
			availCommands[commandCount++] = COM_GO_TO_CITY;
		}

		if (can_unit_do_activity(pUnit, ACTIVITY_SENTRY)) {
			availCommands[commandCount++] = COM_SENTRY;
		}

		if (can_unit_do_activity(pUnit, ACTIVITY_FORTIFYING)) {
			availCommands[commandCount++] = COM_FORTIFY;
		}

		if (can_unit_do_activity(pUnit, ACTIVITY_EXPLORE)) {
			availCommands[commandCount++] = COM_EXPLORE;
		}

		availCommands[commandCount++] = COM_DISBAND;

		if (can_unit_do_activity(pUnit, ACTIVITY_ROAD) || can_unit_do_activity(pUnit, ACTIVITY_RAILROAD)) {
			availCommands[commandCount++] = COM_ROAD;
		}

		if (can_unit_do_activity(pUnit, ACTIVITY_IRRIGATE)) {
			availCommands[commandCount++] = COM_IRRIGATION;
		}

		if (can_unit_do_autosettlers(pUnit)) {
			availCommands[commandCount++] = COM_AUTO_WORKER;
		}

		if (can_unit_do_connect(pUnit, ACTIVITY_IRRIGATE)) {
			availCommands[commandCount++] = COM_CONNECT_IRRIGATION;
		}

		if (can_unit_do_connect(pUnit, ACTIVITY_ROAD)) {
			availCommands[commandCount++] = COM_CONNECT_ROAD;
		}

		if (can_unit_do_connect(pUnit, ACTIVITY_RAILROAD)) {
			availCommands[commandCount++] = COM_CONNECT_RAILROAD;
		}

		availCommands[commandCount++] = COM_WAIT;

		if (unit_can_help_build_wonder_here(pUnit)) {
			availCommands[commandCount++] = COM_BUILD_WONDER;
		}

		if (unit_can_est_trade_route_here(pUnit)) {
			availCommands[commandCount++] = COM_TRADE_ROUTE;
		}

		if (can_unit_do_activity(pUnit, ACTIVITY_MINE)) {
			availCommands[commandCount++] = COM_MINE;
		}

		if (can_unit_do_activity(pUnit, ACTIVITY_TRANSFORM)) {
			availCommands[commandCount++] = COM_TRANSFORM;
		}

		pbase = get_base_by_gui_type(BASE_GUI_FORTRESS, pUnit, pUnit->tile);

		if (!pCity && pbase) {
			availCommands[commandCount++] = COM_FORTRESS;
		}

		pbase = get_base_by_gui_type(BASE_GUI_AIRBASE, pUnit, pUnit->tile);

		if (!pCity && pbase) {
			availCommands[commandCount++] = COM_AIRBASE;
		}

		if (can_unit_do_activity(pUnit, ACTIVITY_POLLUTION)) {
			availCommands[commandCount++] = COM_POLLUTION;
		}

		if (can_unit_do_activity(pUnit, ACTIVITY_FALLOUT)) {
			availCommands[commandCount++] = COM_FALLOUT;
		}

		if (can_unit_paradrop(pUnit)) {
			availCommands[commandCount++] = COM_PARADROP;
		}

		if (can_unit_do_activity(pUnit, ACTIVITY_PILLAGE)) {
			availCommands[commandCount++] = COM_FALLOUT;
		}

	    if (pCity && can_unit_change_homecity(pUnit)
			&& pCity->id != pUnit->homecity) {
	    	  availCommands[commandCount++] = COM_HOMECITY;
	    }

	    if (pUnit->occupy && get_transporter_occupancy(pUnit) > 0) {
	    	availCommands[commandCount++] = COM_UNLOAD_TRANSPORT;
	    }

	    if (units_can_load(punits)) {
	    	availCommands[commandCount++] = COM_LOAD;
	    }

	    if (units_can_unload(punits)) {
	    	availCommands[commandCount++] = COM_UNLOAD;
	    }

	    if (pCity && pCity->airlift) {
	    	availCommands[commandCount++] = COM_AIRLIFT;
	    }

	    if (pCity && can_upgrade_unittype(client.conn.playing, unit_type(pUnit))) {
	    	availCommands[commandCount++] = COM_UPGRADE;
	    }

	    if (diplomat_can_do_action(pUnit, DIPLOMAT_ANY_ACTION, pUnit->tile)) {
			availCommands[commandCount++] = COM_DIPLOMAT;
		}

	    if (unit_has_type_flag(pUnit, F_NUCLEAR)) {
	    	availCommands[commandCount++] = COM_NUKE;
	    }

	}



	jbyteArray commands;

	commands = (*env)->NewByteArray(env, commandCount);

	(*env)->SetByteArrayRegion(env, commands, 0,
			commandCount, (jbyte *)availCommands);

	return commands;
}
Esempio n. 5
0
/**************************************************************************
  Calculate the benefit of irrigating the given tile.

  The return value is the goodness of the tile after the irrigation.  This
  should be compared to the goodness of the tile currently (see
  city_tile_value(); note that this depends on the AI's weighting
  values).
**************************************************************************/
static int adv_calc_irrigate(const struct city *pcity,
                             const struct tile *ptile)
{
  int goodness;
  struct terrain *old_terrain, *new_terrain;

  fc_assert_ret_val(ptile != NULL, -1)

  old_terrain = tile_terrain(ptile);
  new_terrain = old_terrain->irrigation_result;

  if (new_terrain != old_terrain && new_terrain != T_NONE) {
    struct tile *vtile;

    if (tile_city(ptile) && terrain_has_flag(new_terrain, TER_NO_CITIES)) {
      /* Not a valid activity. */
      return -1;
    }
    /* Irrigation would change the terrain type, clearing conflicting
     * extras in the process.  Calculate the benefit of doing so. */
    vtile = tile_virtual_new(ptile);

    tile_change_terrain(vtile, new_terrain);
    goodness = city_tile_value(pcity, vtile, 0, 0);
    tile_virtual_destroy(vtile);

    return goodness;
  } else if (old_terrain == new_terrain) {
    struct extra_type *pextra = next_extra_for_tile(ptile, EC_IRRIGATION,
                                                    city_owner(pcity), NULL);

    if (pextra != NULL) {
      struct tile *vtile = tile_virtual_new(ptile);

      /* Try to add extra, and to remove conflicting ones. */
      if (tile_extra_apply(vtile, pextra)) {
        struct extra_type *pextra2 = next_extra_for_tile(vtile, EC_IRRIGATION,
                                                         city_owner(pcity), NULL);

        goodness = city_tile_value(pcity, vtile, 0, 0);

        if (pextra2 != NULL) {
          struct tile *vtile2 = tile_virtual_new(vtile);

          /* If the player can further irrigate to make farmland, consider the
           * potentially greater benefit.  Note the hack: autosettler ordinarily
           * discounts benefits by the time it takes to make them; farmland takes
           * twice as long, so make it look half as good. */
          if (tile_extra_apply(vtile2, pextra2)) {
            int second_goodness = city_tile_value(pcity, vtile2, 0, 0);
            int oldv = city_tile_value(pcity, ptile, 0, 0);

            second_goodness = oldv + (second_goodness - oldv) / 2;

            if (second_goodness > goodness) {
              goodness = second_goodness;
            }
          }
          tile_virtual_destroy(vtile2);
        }
        tile_virtual_destroy(vtile);

        return goodness;
      }
    }

    /* Cannot build irrigation extra */
    return -1;
  } else {
    return -1;
  }
}
Esempio n. 6
0
PyObject* get_unit_properties(struct unit* s) {
    struct terrain* t = tile_terrain(s->tile);
    return Py_BuildValue("llOs", (long)s, (long)s->tile, py_mapper_city(tile_city(s->tile)),
                terrain_rule_name(t));
}