~ubuntu-branches/debian/sid/freeciv/sid

« back to all changes in this revision

Viewing changes to client/editor.c

  • Committer: Package Import Robot
  • Author(s): Clint Adams, Karl Goetz, Clint Adams
  • Date: 2011-08-28 22:40:00 UTC
  • mfrom: (1.2.19 upstream)
  • Revision ID: package-import@ubuntu.com-20110828224000-j2r1erewlem25dox
Tags: 2.3.0-1
[ Karl Goetz ]
* New upstream version.
* Fix themes_sdl_use_system_fonts.diff to apply cleanly on 2.3.0
* Massage work_around_unity_induced_breakage.diff to get it
  applying to the new codebase (The patch assumes commits made
  after 2.3.0 was tagged upstream).

[ Clint Adams ]
* Fudge build system to think there is no libtool mismatch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
#include <config.h>
16
16
#endif
17
17
 
18
 
#include <assert.h>
19
18
#include <stdarg.h>
20
19
#include <string.h>
21
20
 
22
21
/* utility */
 
22
#include "bitvector.h"
23
23
#include "fcintl.h"
24
 
#include "hash.h"
25
24
#include "log.h"
26
25
#include "support.h"
27
26
 
92
91
 
93
92
  enum selection_modes selection_mode;
94
93
 
95
 
  struct hash_table *selected_tile_table;
 
94
  struct tile_hash *selected_tile_table;
96
95
  struct edit_buffer *copybuf;
97
96
};
98
97
 
161
160
            _("Create city.\nShortcut: c"));
162
161
  tool_init(ETT_VISION, _("Vision"), ETF_HAS_SIZE,
163
162
            _("Modify player's tile knowledge.\nShortcut: v"));
164
 
  tool_init(ETT_STARTPOS, _("Start Position"), ETF_HAS_APPLIED_PLAYER,
165
 
            _("Place a player start position.\nShortcut: p"));
 
163
  tool_init(ETT_STARTPOS, _("Start Position"), ETF_NO_FLAGS,
 
164
            _("Place a start position which allows any nation to "
 
165
              "start at the tile. To allow only certain nations to "
 
166
              "start there, middle click on the start position on "
 
167
              "the map and use the property editor.\nShortcut: p"));
166
168
 
167
169
  tool_init(ETT_COPYPASTE, _("Copy/Paste"), ETF_HAS_SIZE,
168
170
            _("Copy and paste tiles.\n"
170
172
              "Shoftcut for paste mode: shift-v"));
171
173
  editor->copybuf = edit_buffer_new(EBT_ALL);
172
174
 
173
 
  editor->selected_tile_table = hash_new(hash_fval_keyval,
174
 
                                         hash_fcmp_keyval);
175
 
  hash_set_no_shrink(editor->selected_tile_table, TRUE);
 
175
  editor->selected_tile_table = tile_hash_new();
 
176
  tile_hash_set_no_shrink(editor->selected_tile_table, TRUE);
176
177
}
177
178
 
178
179
/****************************************************************************
395
396
    apno = player_number(tile_owner(ptile));
396
397
  }
397
398
  
398
 
  if (valid_player_by_number(apno) != NULL) {
 
399
  if (player_by_number(apno) != NULL) {
399
400
    editor_tool_set_applied_player(editor_get_tool(), apno);
400
401
    editgui_refresh();
401
402
  }
528
529
  tiles = tile_list_new();
529
530
 
530
531
  if (editor_tile_is_selected(ptile)) {
531
 
    hash_keys_iterate(editor->selected_tile_table, sel_tile) {
 
532
    tile_hash_iterate(editor->selected_tile_table, sel_tile) {
532
533
      if (can_edit_tile_properties(sel_tile)) {
533
534
        tile_list_append(tiles, sel_tile);
534
535
      }
535
 
    } hash_keys_iterate_end;
 
536
    } tile_hash_iterate_end;
536
537
  } else {
537
538
    if (can_edit_tile_properties(ptile)) {
538
539
      tile_list_append(tiles, ptile);
541
542
 
542
543
  editgui_popup_properties(tiles, NUM_OBJTYPES);
543
544
 
544
 
  tile_list_free(tiles);
 
545
  tile_list_destroy(tiles);
545
546
}
546
547
 
547
548
/****************************************************************************
800
801
{
801
802
  enum editor_tool_type ett;
802
803
  enum editor_tool_mode etm;
803
 
  int value, size, count, apno, x, y, id;
 
804
  int value, size, count, apno, tile, id;
804
805
  bool erase;
805
806
  struct connection *my_conn = &client.conn;
806
807
 
822
823
  }
823
824
 
824
825
  if (editor_tool_has_applied_player(ett)
825
 
      && valid_player_by_number(apno) == NULL) {
 
826
      && player_by_number(apno) == NULL) {
826
827
    return;
827
828
  }
828
829
 
848
849
  }
849
850
 
850
851
  erase = (etm == ETM_ERASE);
851
 
  x = ptile->x;
852
 
  y = ptile->y;
 
852
  tile = tile_index(ptile);
853
853
 
854
854
  switch (ett) {
855
855
 
856
856
  case ETT_TERRAIN:
857
 
    dsend_packet_edit_tile_terrain(my_conn, x, y, erase ? 0 : value, size);
 
857
    dsend_packet_edit_tile_terrain(my_conn, tile, erase ? 0 : value, size);
858
858
    break;
859
859
 
860
860
  case ETT_TERRAIN_RESOURCE:
861
 
    dsend_packet_edit_tile_resource(my_conn, x, y, erase ? -1 : value,
 
861
    dsend_packet_edit_tile_resource(my_conn, tile, erase ? -1 : value,
862
862
                                    size);
863
863
    break;
864
864
 
865
865
  case ETT_TERRAIN_SPECIAL:
866
 
    dsend_packet_edit_tile_special(my_conn, x, y, value, erase, size);
 
866
    dsend_packet_edit_tile_special(my_conn, tile, value, erase, size);
867
867
    break;
868
868
 
869
869
  case ETT_MILITARY_BASE:
870
 
    dsend_packet_edit_tile_base(my_conn, x, y, value, erase, size);
 
870
    dsend_packet_edit_tile_base(my_conn, tile, value, erase, size);
871
871
    break;
872
872
 
873
873
  case ETT_UNIT:
874
874
    if (erase) {
875
 
      dsend_packet_edit_unit_remove(my_conn, apno, x, y, value, count);
 
875
      dsend_packet_edit_unit_remove(my_conn, apno, tile, value, count);
876
876
    } else {
877
 
      dsend_packet_edit_unit_create(my_conn, apno, x, y, value, count, 0);
 
877
      dsend_packet_edit_unit_create(my_conn, apno, tile, value, count, 0);
878
878
    }
879
879
    break;
880
880
 
886
886
        dsend_packet_edit_city_remove(my_conn, id);
887
887
      }
888
888
    } else {
889
 
      dsend_packet_edit_city_create(my_conn, apno, x, y, size, 0);
 
889
      dsend_packet_edit_city_create(my_conn, apno, tile, size, 0);
890
890
    }
891
891
    break;
892
892
 
893
893
  case ETT_VISION:
894
894
    if (client_has_player()) {
895
895
      id = client_player_number();
896
 
      dsend_packet_edit_player_vision(my_conn, id, x, y, !erase, size);
 
896
      dsend_packet_edit_player_vision(my_conn, id, tile, !erase, size);
897
897
    }
898
898
    break;
899
899
 
900
900
  case ETT_STARTPOS:
901
 
    dsend_packet_edit_startpos(my_conn, x, y,
902
 
                               erase ? NATION_NONE :
903
 
                               nation_number(player_by_number(apno)->nation));
 
901
    dsend_packet_edit_startpos(my_conn, tile, erase, 0);
904
902
    break;
905
903
 
906
904
  default:
984
982
  if (!editor) {
985
983
    return;
986
984
  }
987
 
  hash_delete_all_entries(editor->selected_tile_table);
 
985
  tile_hash_clear(editor->selected_tile_table);
988
986
}
989
987
 
990
988
/****************************************************************************
995
993
  if (!editor || !ptile) {
996
994
    return;
997
995
  }
998
 
  hash_insert(editor->selected_tile_table, ptile, NULL);
 
996
  tile_hash_insert(editor->selected_tile_table, ptile, NULL);
999
997
}
1000
998
 
1001
999
/****************************************************************************
1006
1004
  if (!editor || !ptile) {
1007
1005
    return;
1008
1006
  }
1009
 
  hash_delete_entry(editor->selected_tile_table, ptile);
 
1007
  tile_hash_remove(editor->selected_tile_table, ptile);
1010
1008
}
1011
1009
 
1012
1010
/****************************************************************************
1017
1015
  if (!editor || !ptile) {
1018
1016
    return FALSE;
1019
1017
  }
1020
 
  return hash_key_exists(editor->selected_tile_table, ptile);
 
1018
  return tile_hash_lookup(editor->selected_tile_table, ptile, NULL);
1021
1019
}
1022
1020
 
1023
1021
/****************************************************************************
1040
1038
  }
1041
1039
 
1042
1040
  connection_do_buffer(&client.conn);
1043
 
  hash_keys_iterate(editor->selected_tile_table, ptile) {
 
1041
  tile_hash_iterate(editor->selected_tile_table, ptile) {
1044
1042
    editor_apply_tool(ptile, TRUE);
1045
 
  } hash_keys_iterate_end;
 
1043
  } tile_hash_iterate_end;
1046
1044
  editor_notify_edit_finished();
1047
1045
  connection_do_unbuffer(&client.conn);
1048
1046
 
1241
1239
/****************************************************************************
1242
1240
  Returns the current applied player number for the editor tool.
1243
1241
 
1244
 
  May return a player number for which valid_player_by_number returns NULL.
 
1242
  May return a player number for which player_by_number returns NULL.
1245
1243
****************************************************************************/
1246
1244
int editor_tool_get_applied_player(enum editor_tool_type ett)
1247
1245
{
1295
1293
  if (!editor) {
1296
1294
    return 0;
1297
1295
  }
1298
 
  return hash_num_entries(editor->selected_tile_table);
 
1296
  return tile_hash_size(editor->selected_tile_table);
1299
1297
}
1300
1298
 
1301
1299
/****************************************************************************
1322
1320
  }
1323
1321
 
1324
1322
  apno = editor_tool_get_applied_player(ETT_UNIT);
1325
 
  pplayer = valid_player_by_number(apno);
 
1323
  pplayer = player_by_number(apno);
1326
1324
  if (!pplayer) {
1327
1325
    return NULL;
1328
1326
  }
1361
1359
 
1362
1360
  if (ebuf->vtiles) {
1363
1361
    tile_list_iterate(ebuf->vtiles, vtile) {
1364
 
      destroy_tile_virtual(vtile);
 
1362
      tile_virtual_destroy(vtile);
1365
1363
    } tile_list_iterate_end;
1366
 
    tile_list_free(ebuf->vtiles);
 
1364
    tile_list_destroy(ebuf->vtiles);
1367
1365
    ebuf->vtiles = NULL;
1368
1366
  }
1369
1367
  free(ebuf);
1379
1377
  }
1380
1378
 
1381
1379
  tile_list_iterate(ebuf->vtiles, vtile) {
1382
 
    destroy_tile_virtual(vtile);
 
1380
    tile_virtual_destroy(vtile);
1383
1381
  } tile_list_iterate_end;
1384
1382
  tile_list_clear(ebuf->vtiles);
1385
1383
 
1426
1424
    dx = 0;
1427
1425
    dy = 0;
1428
1426
  }
1429
 
  vtile = create_tile_virtual();
 
1427
  vtile = tile_virtual_new(NULL);
1430
1428
  vtile->x = dx;
1431
1429
  vtile->y = dy;
1432
1430
 
1475
1473
        char name[MAX_LEN_NAME];
1476
1474
 
1477
1475
        pcity = tile_city(ptile);
1478
 
        my_snprintf(name, sizeof(name), "Copy of %s",
 
1476
        fc_snprintf(name, sizeof(name), "Copy of %s",
1479
1477
                    city_name(pcity));
1480
1478
        vcity = create_city_virtual(city_owner(pcity), NULL, name);
1481
1479
        vcity->size = pcity->size;
1498
1496
  if (copied) {
1499
1497
    tile_list_append(ebuf->vtiles, vtile);
1500
1498
  } else {
1501
 
    destroy_tile_virtual(vtile);
 
1499
    tile_virtual_destroy(vtile);
1502
1500
  }
1503
1501
}
1504
1502
 
1510
1508
{
1511
1509
  const struct resource *presource;
1512
1510
  const struct terrain *pterrain;
1513
 
  const struct nation_type *pnation;
1514
1511
 
1515
1512
  if (!packet || !ptile) {
1516
1513
    return;
1517
1514
  }
1518
 
  packet->id = tile_index(ptile);
 
1515
  packet->tile = tile_index(ptile);
1519
1516
  packet->specials = tile_specials(ptile);
1520
1517
  packet->bases = tile_bases(ptile);
1521
1518
 
1524
1521
 
1525
1522
  pterrain = tile_terrain(ptile);
1526
1523
  packet->terrain = pterrain ? terrain_number(pterrain) : -1;
1527
 
 
1528
 
  pnation = map_get_startpos(ptile);
1529
 
  packet->startpos_nation = pnation ? nation_number(pnation) : -1;
1530
1524
}
1531
1525
 
1532
1526
/****************************************************************************
1540
1534
  struct connection *my_conn = &client.conn;
1541
1535
  struct packet_edit_tile tile_packet;
1542
1536
  struct city *vcity;
1543
 
  int value, owner, x, y;
 
1537
  int value, owner, tile;
1544
1538
  bool send_edit_tile = FALSE;
1545
1539
 
1546
1540
  if (!ebuf || !vtile || !ptile_dest) {
1547
1541
    return;
1548
1542
  }
1549
1543
 
1550
 
  x = ptile_dest->x;
1551
 
  y = ptile_dest->y;
 
1544
  tile = tile_index(ptile_dest);
1552
1545
 
1553
1546
  fill_tile_edit_packet(&tile_packet, ptile_dest);
1554
1547
 
1559
1552
        continue;
1560
1553
      }
1561
1554
      value = terrain_number(tile_terrain(vtile));
1562
 
      dsend_packet_edit_tile_terrain(my_conn, x, y, value, 1);
 
1555
      dsend_packet_edit_tile_terrain(my_conn, tile, value, 1);
1563
1556
      break;
1564
1557
    case EBT_RESOURCE:
1565
1558
      if (!tile_resource(vtile)) {
1566
1559
        continue;
1567
1560
      }
1568
1561
      value = resource_number(tile_resource(vtile));
1569
 
      dsend_packet_edit_tile_resource(my_conn, x, y, value, 1);
 
1562
      dsend_packet_edit_tile_resource(my_conn, tile, value, 1);
1570
1563
      break;
1571
1564
    case EBT_SPECIAL:
1572
1565
      tile_packet.specials = tile_specials(vtile);
1580
1573
      unit_list_iterate(vtile->units, vunit) {
1581
1574
        value = utype_number(unit_type(vunit));
1582
1575
        owner = player_number(unit_owner(vunit));
1583
 
        dsend_packet_edit_unit_create(my_conn, owner, x, y, value, 1, 0);
 
1576
        dsend_packet_edit_unit_create(my_conn, owner, tile, value, 1, 0);
1584
1577
      } unit_list_iterate_end;
1585
1578
      break;
1586
1579
    case EBT_CITY:
1590
1583
      }
1591
1584
      owner = player_number(city_owner(vcity));
1592
1585
      value = vcity->size;
1593
 
      dsend_packet_edit_city_create(my_conn, owner, x, y, value, 0);
 
1586
      dsend_packet_edit_city_create(my_conn, owner, tile, value, 0);
1594
1587
      break;
1595
1588
    default:
1596
1589
      break;
1664
1657
    return _("Paste");
1665
1658
    break;
1666
1659
  default:
1667
 
    freelog(LOG_ERROR, "Unrecognized editor tool mode %d "
1668
 
            "in editor_tool_get_mode_name().", etm);
 
1660
    log_error("Unrecognized editor tool mode %d "
 
1661
              "in editor_tool_get_mode_name().", etm);
1669
1662
    break;
1670
1663
  }
1671
1664
 
1741
1734
    return 0;
1742
1735
  }
1743
1736
 
1744
 
  ret = mystrlcpy(buf, _("Buffer empty."), buflen);
 
1737
  ret = fc_strlcpy(buf, _("Buffer empty."), buflen);
1745
1738
  if (!ebuf || !ebuf->vtiles) {
1746
1739
    return ret;
1747
1740
  }
1749
1742
  total = tile_list_size(ebuf->vtiles);
1750
1743
  if (total > 0) {
1751
1744
    fmt = PL_("%d tile copied.", "%d tiles copied.", total);
1752
 
    ret = my_snprintf(buf, buflen, fmt, total);
 
1745
    ret = fc_snprintf(buf, buflen, fmt, total);
1753
1746
  }
1754
1747
 
1755
1748
  return ret;
1806
1799
    return NULL;
1807
1800
  }
1808
1801
 
1809
 
  count = hash_num_entries(editor->selected_tile_table);
 
1802
  count = tile_hash_size(editor->selected_tile_table);
1810
1803
  if (count < 1) {
1811
1804
    return NULL;
1812
1805
  }
1813
1806
 
1814
1807
  origin = map_pos_to_tile(0, 0);
1815
 
  hash_keys_iterate(editor->selected_tile_table, ptile) {
 
1808
  tile_hash_iterate(editor->selected_tile_table, ptile) {
1816
1809
    map_distance_vector(&dx, &dy, origin, ptile);
1817
1810
    xsum += dx;
1818
1811
    ysum += dy;
1819
 
  } hash_keys_iterate_end;
 
1812
  } tile_hash_iterate_end;
1820
1813
 
1821
1814
  cx = xsum / count;
1822
1815
  cy = ysum / count;