Beispiel #1
0
/*****************************************************************************
  Find best tile the paratrooper should jump to.
*****************************************************************************/
static struct tile *find_best_tile_to_paradrop_to(struct ai_type *ait,
                                                  struct unit *punit)
{
  int best = 0;
  int val;
  struct tile* best_tile = NULL;
  int range = unit_type(punit)->paratroopers_range;
  struct city* acity;
  struct player* pplayer = unit_owner(punit);

  /* First, we search for undefended cities in danger */
  square_iterate(unit_tile(punit), range, ptile) {
    if (!map_is_known(ptile, pplayer)) {
      continue;
    }
  
    acity = tile_city(ptile);
    if (acity && city_owner(acity) == unit_owner(punit)
        && unit_list_size(ptile->units) == 0) {
      val = city_size_get(acity) * def_ai_city_data(acity, ait)->urgency;
      if (val > best) {
	best = val;
	best_tile = ptile;
      }
    }
  } square_iterate_end;
  
  if (best_tile != NULL) {
    acity = tile_city(best_tile);
    UNIT_LOG(LOGLEVEL_PARATROOPER, punit, 
             "Choose to jump in order to protect allied city %s (%d %d). "
	     "Benefit: %d",
	     city_name(acity), TILE_XY(best_tile), best);
    return best_tile;
  }

  /* Second, we search for undefended enemy cities */
  square_iterate(unit_tile(punit), range, ptile) {
    acity = tile_city(ptile);
    if (acity && pplayers_at_war(unit_owner(punit), city_owner(acity)) &&
        (unit_list_size(ptile->units) == 0)) {
      if (!map_is_known_and_seen(ptile, pplayer, V_MAIN)
          && ai_handicap(pplayer, H_FOG)) {
        continue;
      }
      /* Prefer big cities on other continents */
      val = city_size_get(acity)
            + (tile_continent(unit_tile(punit)) != tile_continent(ptile));
      if (val > best) {
        best = val;
	best_tile = ptile;
      }
    }
  } square_iterate_end;
Beispiel #2
0
/**************************************************************************
  Update the information label which gives info on the current unit and the
  square under the current unit, for specified unit.  Note that in practice
  punit is almost always (or maybe strictly always?) the focus unit.
  Clears label if punit is NULL.
  Also updates the cursor for the map_canvas (this is related because the
  info label includes a "select destination" prompt etc).
  Also calls update_unit_pix_label() to update the icons for units on this
  square.
**************************************************************************/
void update_unit_info_label(struct unit_list *punitlist)
{
  char buffer[512];

  fc_snprintf(buffer, sizeof(buffer), "%s\n%s",
              get_unit_info_label_text1(punitlist),
              get_unit_info_label_text2(punitlist, 0));
  xaw_set_label(unit_info_label, buffer);

  if (punitlist && unit_list_size(punitlist) > 0) {
    switch (hover_state) {
    case HOVER_NONE:
      XUndefineCursor(display, XtWindow(map_canvas));
      break;
    case HOVER_PATROL:
      XDefineCursor(display, XtWindow(map_canvas), cursors[CURSOR_PATROL]);
      break;
    case HOVER_GOTO:
    case HOVER_CONNECT:
      XDefineCursor(display, XtWindow(map_canvas), cursors[CURSOR_GOTO]);
      break;
    case HOVER_NUKE:
      XDefineCursor(display, XtWindow(map_canvas), cursors[CURSOR_NUKE]);
      break;
    case HOVER_PARADROP:
      XDefineCursor(display, XtWindow(map_canvas), cursors[CURSOR_PARADROP]);
      break;
    }
  } else {
    xaw_set_label(unit_info_label, "");
    XUndefineCursor(display, XtWindow(map_canvas));
  }

  update_unit_pix_label(punitlist);
}
PyObject* py_mapper_unit_list(struct unit_list* s){
    if(s == NULL)
        return Py_BuildValue("");
    int length = unit_list_size(s);
    int i;
    PyObject* list = PyList_New(length);
    for(i=0; i<length; i++) {
        struct unit* u = unit_list_get(s, i);
        PyObject* item = py_mapper_unit(u);
        PyList_SetItem(list, i, item);
    }
    return list;
}
Beispiel #4
0
JNIEXPORT jboolean JNICALL Java_net_hackcasual_freeciv_NativeHarness_touchEvent
  (JNIEnv *je, jobject o, jint x, jint y, jint type) {

	struct timeval tvs, tve;
    int nif = 0;
    static int oldx = -1;
    static int oldy = -1;

    lastTouchX = x;
    lastTouchY = y;

    int deltax;
    int deltay;
	static bool cancelUp;

	struct tile *plasttile;

	switch (type) {
	case 0: {
		cancelUp = FALSE;
		oldx = x;
		oldy = y;
		plasttile = canvas_pos_to_tile(x,y);

		break;
	}
	case 1: {
		if (!cancelUp && abs(x - oldx) < 10 && abs(y - oldy) < 10) {
			can_slide = FALSE;
			LOGI("ABP Lock");
			civ_lock();
			action_button_pressed(x,y,SELECT_POPUP);
			can_slide = TRUE;
			flush_dirty();
			struct tile *ptile = canvas_pos_to_tile(x,y);
			civ_unlock();
			return (ptile && ptile->units)?unit_list_size(ptile->units):0;
		} else if (!cancelUp) {
			LOGI("Recenter Lock");
			civ_lock();
			can_slide = FALSE;
			recenter_button_pressed(x, y);
			can_slide = TRUE;
			flush_dirty();
			civ_unlock();
		}
		break;
	}
	case 2: {
		/*hover_state = HOVER_GOTO;
		control_mouse_cursor(canvas_pos_to_tile(x,y));
		update_line(x,y);
		break;*/
		if (cancelUp || abs(x - oldx) > 10 || abs(y - oldy) > 10) {
			cancelUp = TRUE;
			LOGI("Slide Lock");
			civ_lock();
			can_slide = FALSE;
			deltax = oldx - x;
			deltay = oldy - y;
			set_mapview_origin(mapview.gui_x0 + deltax, mapview.gui_y0 + deltay);
			flush_dirty();
			civ_unlock();
			oldx = x;
			oldy = y;
			can_slide = TRUE;
		}
		break;
	}
	case 3: {
		cancelUp = TRUE;
		break;
	}
	}

	return 0;
}
Beispiel #5
0
/****************************************************************
popup the dialog 10% inside the main-window 
*****************************************************************/
void unit_select_dialog_popup(struct tile *ptile)
{
  int i,n,r;
  char buffer[512];
  Arg args[4];
  int nargs;
  Widget unit_select_all_command, unit_select_close_command;
  Widget firstcolumn=0,column=0;
  Pixel bg;
  struct unit *unit_list[unit_list_size(ptile->units)];

  XtSetSensitive(main_form, FALSE);

  unit_select_dialog_shell =
    I_T(XtCreatePopupShell("unitselectdialogshell", 
			   transientShellWidgetClass,
			   toplevel, NULL, 0));

  unit_select_form = XtVaCreateManagedWidget("unitselectform", 
					     formWidgetClass, 
					     unit_select_dialog_shell, NULL);

  XtVaGetValues(unit_select_form, XtNbackground, &bg, NULL);
  XSetForeground(display, fill_bg_gc, bg);

  n = MIN(MAX_SELECT_UNITS, unit_list_size(ptile->units));
  r = number_of_rows(n);

  fill_tile_unit_list(ptile, unit_list);

  for(i=0; i<n; i++) {
    struct unit *punit = unit_list[i];
    struct unit_type *punittemp=unit_type(punit);
    struct city *pcity;
    struct canvas store;
    
    if(!(i%r))  {
      nargs=0;
      if(i)  { XtSetArg(args[nargs], XtNfromHoriz, column); nargs++;}
      column = XtCreateManagedWidget("column", formWidgetClass,
				     unit_select_form,
				     args, nargs);
      if(!i) firstcolumn=column;
    }

    unit_select_ids[i]=punit->id;

    pcity = player_city_by_number(client_player(), punit->homecity);
    
    fc_snprintf(buffer, sizeof(buffer), "%s(%s)\n%s", 
	    utype_name_translation(punittemp), 
	    pcity ? city_name(pcity) : "",
	    unit_activity_text(punit));

    unit_select_pixmaps[i]=XCreatePixmap(display, XtWindow(map_canvas), 
					 tileset_full_tile_width(tileset), tileset_full_tile_height(tileset),
					 display_depth);

    XFillRectangle(display, unit_select_pixmaps[i], fill_bg_gc,
		   0, 0, tileset_full_tile_width(tileset), tileset_full_tile_height(tileset));
    store.pixmap = unit_select_pixmaps[i];
    put_unit(punit, &store, 0, 0);

    nargs=0;
    XtSetArg(args[nargs], XtNbitmap, (XtArgVal)unit_select_pixmaps[i]);nargs++;
    XtSetArg(args[nargs], XtNsensitive, 
             can_unit_do_activity(punit, ACTIVITY_IDLE));nargs++;
    if(i%r)  {
      XtSetArg(args[nargs], XtNfromVert, unit_select_commands[i-1]); nargs++;
    }
    unit_select_commands[i]=XtCreateManagedWidget("unitselectcommands", 
						  commandWidgetClass,
						  column, args, nargs);

    nargs=0;
    XtSetArg(args[nargs], XtNlabel, (XtArgVal)buffer); nargs++;
    XtSetArg(args[nargs], XtNfromHoriz, unit_select_commands[i]); nargs++;
    if(i%r) {
      XtSetArg(args[nargs], XtNfromVert, unit_select_commands[i-1]); nargs++;
    }
    unit_select_labels[i]=XtCreateManagedWidget("unitselectlabels", 
						labelWidgetClass, 
						column, args, nargs);

    XtAddCallback(unit_select_commands[i],
		  XtNdestroyCallback,free_bitmap_destroy_callback, NULL);
    XtAddCallback(unit_select_commands[i],
                  XtNcallback, unit_select_callback, NULL);
  }

  unit_select_no=i;

  unit_select_close_command =
    I_L(XtVaCreateManagedWidget("unitselectclosecommand", 
				commandWidgetClass,
				unit_select_form,
				XtNfromVert, firstcolumn,
				NULL));

  unit_select_all_command =
    I_L(XtVaCreateManagedWidget("unitselectallcommand", 
				commandWidgetClass,
				unit_select_form,
				XtNfromVert, firstcolumn,
				NULL));

  XtAddCallback(unit_select_close_command, XtNcallback, unit_select_callback, NULL);
  XtAddCallback(unit_select_all_command, XtNcallback, unit_select_all_callback, NULL);

  xaw_set_relative_position(toplevel, unit_select_dialog_shell, 15, 10);
  XtPopup(unit_select_dialog_shell, XtGrabNone);
}