Exemplo n.º 1
0
PyObject* get_buildable_units_in_city(struct city* pCity) {
    PyObject* list = PyList_New(0);
    bool can_build;

    unit_type_iterate(un) {
        can_build = can_player_build_unit_now(client.conn.playing, un);
        can_build = can_build && can_city_build_unit_now(pCity, un);

        if (can_build) {
            const char* name = utype_name_translation(un);
            int attack = un->attack_strength;
            int defense = un->defense_strength;
            int moves = un->move_rate;
            int stock = pCity->shield_stock;
            int cost = utype_build_shield_cost(un);
            int turns = -1; //city_turns_to_build(pCity, cid_production(cid_encode_unit(un)), TRUE)

            PyList_Append(list, Py_BuildValue(
                "lisiii(iii)O", (long)un, VUT_UTYPE, name, turns, stock, cost,
                attack, defense, moves, (PyObject*)get_unittype_sprite(tileset, un)
            ));
        }

    } unit_type_iterate_end;

    return list;
}
Exemplo n.º 2
0
/***************************************************************************
 ...
***************************************************************************/
void create_overlay_unit(struct canvas *pcanvas, struct unit_type *punittype)
{
  int x1, x2, y1, y2;
  int width, height;
  struct sprite *sprite = get_unittype_sprite(tileset, punittype);

  sprite_get_bounding_box(sprite, &x1, &y1, &x2, &y2);
  if (pcanvas->type == CANVAS_PIXBUF) {
    width = gdk_pixbuf_get_width(pcanvas->v.pixbuf);
    height = gdk_pixbuf_get_height(pcanvas->v.pixbuf);
    gdk_pixbuf_fill(pcanvas->v.pixbuf, 0x00000000);
  } else {
    if (pcanvas->type == CANVAS_PIXCOMM) {
      gtk_pixcomm_clear(pcanvas->v.pixcomm);
    }

    /* Guess */
    width = tileset_full_tile_width(tileset);
    height = tileset_full_tile_height(tileset);
  }

  /* Finally, put a picture of the unit in the tile */
  canvas_put_sprite(pcanvas, 0, 0, sprite, 
      (x2 + x1 - width) / 2, (y1 + y2 - height) / 2, 
      tileset_full_tile_width(tileset) - (x2 + x1 - width) / 2, 
      tileset_full_tile_height(tileset) - (y1 + y2 - height) / 2);
}
Exemplo n.º 3
0
/***************************************************************************
...
***************************************************************************/
Pixmap create_overlay_unit(const struct unit_type *punittype)
{
  Pixmap pm;
  enum color_std bg_color;
  
  pm=XCreatePixmap(display, root_window, 
		   tileset_full_tile_width(tileset), tileset_full_tile_height(tileset), display_depth);

  /* Give tile a background color, based on the type of unit */
  /* Should there be colors like COLOR_MAPVIEW_LAND etc? -ev */
  switch (unit_color_type(punittype)) {
    case UNIT_BG_LAND:
      bg_color = COLOR_OVERVIEW_LAND;
      break;
    case UNIT_BG_SEA:
      bg_color = COLOR_OVERVIEW_OCEAN;
      break;
    case UNIT_BG_HP_LOSS:
    case UNIT_BG_AMPHIBIOUS:
      bg_color = COLOR_OVERVIEW_MY_UNIT;
      break;
    case UNIT_BG_FLYING:
      bg_color = COLOR_OVERVIEW_ENEMY_CITY;
      break;
    default:
      bg_color = COLOR_OVERVIEW_UNKNOWN;
      break;
  }
  XSetForeground(display, fill_bg_gc,
		 get_color(tileset, bg_color)->color.pixel);
  XFillRectangle(display, pm, fill_bg_gc, 0,0, 
		 tileset_full_tile_width(tileset), tileset_full_tile_height(tileset));

  /* If we're using flags, put one on the tile */
  if(!solid_color_behind_units)  {
    struct sprite *flag = get_nation_flag_sprite(tileset, nation_of_player(client.conn.playing));

    XSetClipOrigin(display, civ_gc, 0,0);
    XSetClipMask(display, civ_gc, flag->mask);
    XCopyArea(display, flag->pixmap, pm, civ_gc, 0,0, 
    	      flag->width,flag->height, 0,0);
    XSetClipMask(display, civ_gc, None);
  }

  /* Finally, put a picture of the unit in the tile */
/*  if(i<utype_count()) */ {
    struct sprite *s = get_unittype_sprite(tileset, punittype,
                                           direction8_invalid());

    XSetClipOrigin(display,civ_gc,0,0);
    XSetClipMask(display,civ_gc,s->mask);
    XCopyArea(display, s->pixmap, pm, civ_gc,
	      0,0, s->width,s->height, 0,0 );
    XSetClipMask(display,civ_gc,None);
  }
  return(pm);
}
Exemplo n.º 4
0
struct sprite* city_get_production_image(struct city* pCity) {
    int kind = pCity->production.kind;
    if(kind == VUT_UTYPE) {
        struct unit_type *pUnitType = pCity->production.value.utype;
        return get_unittype_sprite(tileset, pUnitType);
    } else {
        struct impr_type *pImprove = pCity->production.value.building;
        return get_building_sprite(tileset, pImprove);
    }
}
Exemplo n.º 5
0
/****************************************************************
  Render worklist cell
*****************************************************************/
static void cell_render_func(GtkTreeViewColumn *col, GtkCellRenderer *rend,
			     GtkTreeModel *model, GtkTreeIter *it,
			     gpointer data)
{
  gint cid;
  struct universal target;

  gtk_tree_model_get(model, it, 0, &cid, -1);
  target = cid_production(cid);

  if (GTK_IS_CELL_RENDERER_PIXBUF(rend)) {
    GdkPixbuf *pix;
    struct sprite *sprite;

    if (VUT_UTYPE == target.kind) {
      sprite = sprite_scale(get_unittype_sprite(tileset, target.value.utype,
                                                DIR8_SOUTH, TRUE),
                            max_unit_width, max_unit_height);

    } else {
      sprite = get_building_sprite(tileset, target.value.building);

    }
    pix = sprite_get_pixbuf(sprite);
    g_object_set(rend, "pixbuf", pix, NULL);
    g_object_unref(G_OBJECT(pix));
    if (VUT_UTYPE == target.kind) {
      free_sprite(sprite);
    }
  } else {
    struct city **pcity = data;
    gint column;
    char *row[4];
    char  buf[4][64];
    guint   i;
    gboolean useless;

    for (i = 0; i < ARRAY_SIZE(row); i++) {
      row[i] = buf[i];
    }
    column = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(rend), "column"));

    get_city_dialog_production_row(row, sizeof(buf[0]), target, *pcity);
    g_object_set(rend, "text", row[column], NULL);

    if (NULL != *pcity  &&  VUT_IMPROVEMENT == target.kind) {
      useless = is_improvement_redundant(*pcity, target.value.building);
      /* Mark building redundant if we are really certain that there is
       * no use for it. */
      g_object_set(rend, "strikethrough", useless, NULL);
    } else {
      g_object_set(rend, "strikethrough", FALSE, NULL);
    }
  }
}
Exemplo n.º 6
0
/****************************************************************
  Setup max unit sprite size.
*****************************************************************/
static void update_max_unit_size(void)
{
  max_unit_height = 0;
  max_unit_width = 0;

  unit_type_iterate(i) {
    int x1, x2, y1, y2;
    struct sprite *sprite = get_unittype_sprite(tileset, i,
                                                direction8_invalid(), TRUE);

    sprite_get_bounding_box(sprite, &x1, &y1, &x2, &y2);
    max_unit_width = MAX(max_unit_width, x2 - x1);
    max_unit_height = MAX(max_unit_height, y2 - y1);
  } unit_type_iterate_end;
}
Exemplo n.º 7
0
struct sprite* get_unit_image(const struct unit* u) {
    return get_unittype_sprite(tileset, unit_type(u));
}