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

« back to all changes in this revision

Viewing changes to server/barbarian.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:
43
43
#include "terrain.h"
44
44
#include "unitlist.h"
45
45
 
46
 
/* ai */
47
 
#include "aidata.h"
48
 
#include "aitools.h"
49
 
 
50
46
/* server */
 
47
#include "citytools.h"
51
48
#include "gamehand.h"
52
49
#include "maphand.h"
53
50
#include "notify.h"
58
55
#include "unithand.h"
59
56
#include "unittools.h"
60
57
 
 
58
/* server/advisors */
 
59
#include "advdata.h"
 
60
 
61
61
#include "barbarian.h"
62
62
 
63
63
#define BARBARIAN_INITIAL_VISION_RADIUS 3
68
68
**************************************************************************/
69
69
bool is_land_barbarian(struct player *pplayer)
70
70
{
71
 
  return (pplayer->ai_data.barbarian_type == LAND_BARBARIAN);
 
71
  return (pplayer->ai_common.barbarian_type == LAND_BARBARIAN);
72
72
}
73
73
 
74
74
/**************************************************************************
76
76
**************************************************************************/
77
77
bool is_sea_barbarian(struct player *pplayer)
78
78
{
79
 
  return (pplayer->ai_data.barbarian_type == SEA_BARBARIAN);
 
79
  return (pplayer->ai_common.barbarian_type == SEA_BARBARIAN);
80
80
}
81
81
 
82
82
/**************************************************************************
97
97
      if (!barbarians->is_alive) {
98
98
        barbarians->economic.gold = 0;
99
99
        barbarians->is_alive = TRUE;
100
 
        barbarians->is_dying = FALSE;
101
 
        pick_random_player_name(nation_of_player(barbarians), barbarians->name);
102
 
        sz_strlcpy(barbarians->username, ANON_USER_NAME);
 
100
        player_status_reset(barbarians);
 
101
        sz_strlcpy(barbarians->name,
 
102
                   pick_random_player_name(nation_of_player(barbarians)));
 
103
        sz_strlcpy(barbarians->username, ANON_USER_NAME);
103
104
        /* I need to make them to forget the map, I think */
104
105
        whole_map_iterate(ptile) {
105
106
          map_clear_known(ptile, barbarians);
111
112
  } players_iterate_end;
112
113
 
113
114
  /* make a new player, or not */
114
 
  barbarians = server_create_player();
 
115
  barbarians = server_create_player(-1);
115
116
  if (!barbarians) {
116
117
    return NULL;
117
118
  }
120
121
 
121
122
  nation = pick_a_nation(NULL, FALSE, TRUE, type);
122
123
  player_set_nation(barbarians, nation);
123
 
  pick_random_player_name(nation, barbarians->name);
 
124
  sz_strlcpy(barbarians->name, pick_random_player_name(nation));
124
125
 
125
126
  server.nbarbarians++;
126
 
  game.info.max_players = MAX(player_count(), game.info.max_players);
 
127
  game.server.max_players = MAX(player_count(), game.server.max_players);
127
128
 
128
129
  sz_strlcpy(barbarians->username, ANON_USER_NAME);
129
130
  barbarians->is_connected = FALSE;
130
 
  barbarians->government = nation->init_government;
131
 
  assert(barbarians->revolution_finishes < 0);
132
 
  barbarians->capital = FALSE;
 
131
  barbarians->government = nation->server.init_government;
 
132
  fc_assert(barbarians->revolution_finishes < 0);
 
133
  barbarians->server.capital = FALSE;
133
134
  barbarians->economic.gold = 100;
134
135
 
135
136
  barbarians->phase_done = TRUE;
136
137
 
137
138
  /* Do the ai */
138
 
  barbarians->ai_data.control = TRUE;
139
 
  barbarians->ai_data.barbarian_type = type;
 
139
  barbarians->ai_controlled = TRUE;
 
140
  barbarians->ai_common.barbarian_type = type;
140
141
  set_ai_level_directer(barbarians, game.info.skill_level);
141
142
  init_tech(barbarians, TRUE);
142
143
  give_global_initial_techs(barbarians);
145
146
  /* Ensure that we are at war with everyone else */
146
147
  players_iterate(pplayer) {
147
148
    if (pplayer != barbarians) {
148
 
      pplayer->diplstates[player_index(barbarians)].type = DS_WAR;
149
 
      barbarians->diplstates[player_index(pplayer)].type = DS_WAR;
 
149
      player_diplstate_get(pplayer, barbarians)->type = DS_WAR;
 
150
      player_diplstate_get(barbarians, pplayer)->type = DS_WAR;
150
151
    }
151
152
  } players_iterate_end;
152
153
 
153
 
  freelog(LOG_VERBOSE, "Created barbarian %s, player %d",
154
 
          player_name(barbarians),
155
 
          player_number(barbarians));
 
154
  log_verbose("Created barbarian %s, player %d", player_name(barbarians),
 
155
              player_number(barbarians));
156
156
  notify_player(NULL, NULL, E_UPRISING, ftc_server,
157
157
                _("%s gain a leader by the name %s. Dangerous "
158
158
                  "times may lie ahead."),
159
159
                nation_plural_for_player(barbarians),
160
160
                player_name(barbarians));
161
161
 
162
 
  send_player_info(barbarians, NULL);
 
162
  send_player_all_c(barbarians, NULL);
163
163
 
164
164
  return barbarians;
165
165
}
208
208
  int j = -1;
209
209
  int i;
210
210
 
211
 
  int num = myrand(possibilities);
 
211
  int num = fc_rand(possibilities);
212
212
  for (i = 0; i <= num; i++) {
213
213
    j++;
214
214
    while (checked[j]) {
215
215
      j++;
216
 
      assert(j < 8);
 
216
      fc_assert(j < 8);
217
217
    }
218
218
  }
219
219
 
249
249
   *        but L_BARBARIAN_TECH is already available,
250
250
   *        we should unleash those.
251
251
   *        Doesn't affect any ruleset I'm aware of. */
252
 
  if (game.info.barbarianrate == 0
253
 
      || game.info.turn < game.info.onsetbarbarian
 
252
  if (BARBS_DISABLED == game.server.barbarianrate
 
253
      || game.info.turn < game.server.onsetbarbarian
254
254
      || num_role_units(L_BARBARIAN) == 0) {
255
255
    unit_list_iterate_safe((ptile)->units, punit) {
256
256
      wipe_unit(punit);
263
263
    return FALSE;
264
264
  }
265
265
 
266
 
  unit_cnt = 3 + myrand(4);
 
266
  ai_data_phase_init(barbarians, TRUE);
 
267
 
 
268
  unit_cnt = 3 + fc_rand(4);
267
269
  for (i = 0; i < unit_cnt; i++) {
268
270
    struct unit_type *punittype
269
271
      = find_a_unit_type(L_BARBARIAN, L_BARBARIAN_TECH);
275
277
      struct unit *barb_unit;
276
278
 
277
279
      barb_unit = create_unit(barbarians, ptile, punittype, 0, 0, -1);
278
 
      freelog(LOG_DEBUG, "Created barbarian unit %s",
279
 
              utype_rule_name(punittype));
 
280
      log_debug("Created barbarian unit %s", utype_rule_name(punittype));
280
281
      send_unit_info(NULL, barb_unit);
281
282
    }
282
283
  }
286
287
  for (dir = 0; dir < 8; dir++) {
287
288
    dir_tiles[dir] = mapstep(ptile, dir);
288
289
    if (dir_tiles[dir] == NULL) {
289
 
      terrainc[dir] = TC_LAST;
 
290
      terrainc[dir] = terrain_class_invalid();
290
291
    } else if (is_free_land(dir_tiles[dir], barbarians)) {
291
292
      terrainc[dir] = TC_LAND;
292
293
      land_tiles++;
294
295
      terrainc[dir] = TC_OCEAN;
295
296
      ocean_tiles++;
296
297
    } else {
297
 
      terrainc[dir] = TC_LAST;
 
298
      terrainc[dir] = terrain_class_invalid();
298
299
    }
299
300
  }
300
301
 
312
313
             checked_count++) {
313
314
          int rdir = random_unchecked_direction(land_tiles - checked_count, checked);
314
315
 
315
 
          if (can_unit_move_to_tile(punit2, dir_tiles[rdir], TRUE)) {
 
316
          if (unit_can_move_to_tile(punit2, dir_tiles[rdir], TRUE)) {
316
317
            (void) unit_move_handling(punit2, dir_tiles[rdir], TRUE, FALSE);
317
 
            freelog(LOG_DEBUG, "Moved barbarian unit from %d %d to %d, %d", 
318
 
                    ptile->x, ptile->y, dir_tiles[rdir]->x, dir_tiles[rdir]->y);
 
318
            log_debug("Moved barbarian unit from (%d, %d) to (%d, %d)", 
 
319
                      TILE_XY(ptile), TILE_XY(dir_tiles[rdir]));
319
320
            dest_found = TRUE;
320
321
          }
321
322
 
355
356
        /* We do have a boat. Try to get everybody in */
356
357
        unit_list_iterate_safe((ptile)->units, punit2) {
357
358
          if (unit_owner(punit2) == barbarians) {
358
 
            if (can_unit_move_to_tile(punit2, btile, TRUE)) {
 
359
            if (unit_can_move_to_tile(punit2, btile, TRUE)) {
359
360
              (void) unit_move_handling(punit2, btile, TRUE, FALSE);
360
361
            }
361
362
          }
376
377
            int rdir;
377
378
            rdir = random_unchecked_direction(land_tiles - checked_count, checked);
378
379
 
379
 
            if (can_unit_move_to_tile(punit2, dir_tiles[rdir], TRUE)) {
 
380
            if (unit_can_move_to_tile(punit2, dir_tiles[rdir], TRUE)) {
380
381
              (void) unit_move_handling(punit2, dir_tiles[rdir], TRUE, FALSE);
381
382
              dest_found = TRUE;
382
383
            }
482
483
    return;
483
484
  }
484
485
 
485
 
 
486
 
  if (!(pc = dist_nearest_city(NULL, ptile, TRUE, FALSE))) {
 
486
  if (!(pc = find_closest_city(ptile, NULL, NULL, FALSE, FALSE, FALSE, FALSE,
 
487
                               FALSE))) {
487
488
    /* any city */
488
489
    return;
489
490
  }
491
492
  victim = city_owner(pc);
492
493
 
493
494
  dist = real_map_distance(ptile, pc->tile);
494
 
  freelog(LOG_DEBUG,"Closest city (to %d,%d) is %s (at %d,%d) distance %d.", 
495
 
          TILE_XY(ptile), city_name(pc), TILE_XY(pc->tile), dist);
 
495
  log_debug("Closest city (to %d,%d) is %s (at %d,%d) distance %d.",
 
496
            TILE_XY(ptile), city_name(pc), TILE_XY(pc->tile), dist);
496
497
  if (dist > MAX_UNREST_DIST || dist < MIN_UNREST_DIST) {
497
498
    return;
498
499
  }
505
506
    return;
506
507
  }
507
508
 
 
509
  fc_assert(1 < game.server.barbarianrate);
 
510
 
508
511
  /* do not harass small civs - in practice: do not uprise at the beginning */
509
 
  if ((int)myrand(UPRISE_CIV_MORE) >
 
512
  if ((int)fc_rand(UPRISE_CIV_MORE) >
510
513
           (int)city_list_size(victim->cities) -
511
 
                UPRISE_CIV_SIZE/(game.info.barbarianrate-1)
512
 
      || myrand(100) > get_player_bonus(victim, EFT_CIVIL_WAR_CHANCE)) {
 
514
                UPRISE_CIV_SIZE/(game.server.barbarianrate-1)
 
515
      || fc_rand(100) > get_player_bonus(victim, EFT_CIVIL_WAR_CHANCE)) {
513
516
    return;
514
517
  }
515
 
  freelog(LOG_DEBUG, "Barbarians are willing to fight");
 
518
  log_debug("Barbarians are willing to fight");
516
519
 
517
520
  if (tile_has_special(utile, S_HUT)) {
518
521
    /* remove the hut in place of uprising */
520
523
    update_tile_knowledge(utile);
521
524
  }
522
525
 
523
 
  barb_count = myrand(3) + uprise * game.info.barbarianrate;
 
526
  barb_count = fc_rand(3) + uprise * game.server.barbarianrate;
524
527
  leader_type = get_role_unit(L_BARBARIAN_LEADER, 0);
525
528
 
526
529
  if (!is_ocean_tile(utile)) {
542
545
      if (is_native_tile(punittype, utile)) {
543
546
        (void) create_unit(barbarians, utile, punittype, 0, 0, -1);
544
547
        really_created++;
545
 
        freelog(LOG_DEBUG, "Created barbarian unit %s",
546
 
                utype_rule_name(punittype));
 
548
        log_debug("Created barbarian unit %s",utype_rule_name(punittype));
547
549
      }
548
550
    }
549
551
 
555
557
  } else {                   /* sea raiders - their units will be veteran */
556
558
    struct unit *ptrans;
557
559
    struct unit_type *boat;
 
560
    bool miniphase;
558
561
 
559
562
    barbarians = create_barbarian_player(SEA_BARBARIAN);
560
563
    if (!barbarians) {
561
564
      return;
562
565
    }
563
 
    ai_data_phase_init(barbarians, TRUE); /* Created ferry may need ai data */
 
566
 
 
567
    /* Setup data phase if it's not already set up. Created ferries may
 
568
       need that data.
 
569
       We don't know if create_barbarian_player() above created completely
 
570
       new player or did it just return existing one. If it was existing
 
571
       one, phase has already been set up at turn begin and will be closed
 
572
       at turn end. If this is completely new player, we have to take care
 
573
       of both opening and closing the data phase. Return value of
 
574
       ai_data_phase_init() tells us if data phase was already initialized
 
575
       at turn beginning. */
 
576
    miniphase = ai_data_phase_init(barbarians, TRUE);
564
577
 
565
578
    boat = find_a_unit_type(L_BARBARIAN_BOAT,-1);
566
579
 
581
594
          (void) create_unit_full(barbarians, utile, barb, 0, 0, -1, -1,
582
595
                                  ptrans);
583
596
          really_created++;
584
 
          freelog(LOG_DEBUG, "Created barbarian unit %s",
585
 
                  utype_rule_name(barb));
 
597
          log_debug("Created barbarian unit %s", utype_rule_name(barb));
586
598
        }
587
599
      }
588
600
 
593
605
      }
594
606
    }
595
607
 
596
 
    ai_data_phase_done(barbarians);
 
608
    if (miniphase) {
 
609
      ai_data_phase_done(barbarians);
 
610
    }
597
611
  }
598
612
 
599
613
  if (really_created == 0) {
631
645
{
632
646
  int i, n;
633
647
 
634
 
  if (game.info.barbarianrate == 0) {
 
648
  if (BARBS_DISABLED == game.server.barbarianrate
 
649
      || BARBS_HUTS_ONLY == game.server.barbarianrate) {
635
650
    return;
636
651
  }
637
652
 
638
 
  if (game.info.turn < game.info.onsetbarbarian) {
 
653
  if (game.info.turn < game.server.onsetbarbarian) {
639
654
    return;
640
655
  }
641
656
 
645
660
    n = 1;
646
661
  }
647
662
 
648
 
  for (i = 0; i < n * (game.info.barbarianrate - 1); i++) {
 
663
  for (i = 0; i < n * (game.server.barbarianrate - 1); i++) {
649
664
    try_summon_barbarians();
650
665
  }
651
666
}