DELTA 15803 2819 789
SVN  ‰$ÍBa¿< …Q €„S M €…X M €‡ M €ƒ8 M €„X M €„n M €†
 M €†! M €ˆ% @ €L @ €" @ €‚  @ €‚" @ €‚) @ € M €Wfc_config.h>
#endif

#include <string.h>

/* utility */
#include "fcintl.h"
#include "log.h"                /* fc_assert */
#include "mem.h"
#include "timing.h"

/* common */
#include "ai.h"
#include "player.h"

static struct ai_type ai_types[FC_AI_LAST];

static int ai_type_count = 0;

#ifdef DEBUG_AITIMERS
struct ai_timer {
  int count;
  struct timer *timer;
};

static struct ai_timer *ai_timer_get(const struct ai_type *ai);
static struct ai_timer *ai_timer_player_get(const struct player *pplayer);

static struct ai_timer *aitimers = NULL;
static struct ai_timer *aitimer_plrs = NULL;

*
  Allocate memory for Start the timer for the AI of a player.
*****************************************************************************/
void ai_timer_init(void)
{
  int i;

  fc_assert_ret(aitimers == NULL);
  fc_assert_ret(aitimer_plrs == NULL);

  aitimers = fc_calloc(FC_AI_LAST, sizeof(*aitimers));
  for (i = 0; i < FC_AI_LAST; i++) {
    struct ai_timer *aitimer = aitimers + i;
    aitimer->count = 0;
    aitimer->timer = NULL;
  }

  aitimer_plrs = fc_calloc(FC_AI_LAST * MAX_NUM_PLAYER_SLOTS,
                           sizeof(*aitimer_plrs));
  for (i = 0; i < FC_AI_LAST * MAX_NUM_PLAYER_SLOTS; i++) {
    struct ai_timer *aitimer = aitimer_plrs + i;
    aitimer->count = 0;
    aitimer->timer = NULL;
  }
}

*
  Allocate memory for Start the timer for the AI of a player.
*****************************************************************************/
void ai_timer_free(void)
{
  int i,j;
  struct ai_timer *aitimer;

  for (i = 0; i < FC_AI_LAST; i++) {
    struct ai_type *ai = get_ai_type(i);

    aitimer = aitimers + i;

    if (aitimer->timer) {
      log_normal("AI timer stats: [%15.3f] ---- (AI type: %s)",
                 read_timer_seconds(aitimer->timer), ai_name(ai));
      free_timer(aitimer->timer);
    }

    for (j = 0; j < MAX_NUM_PLAYER_SLOTS; j++) {
      aitimer = aitimer_plrs + j * FC_AI_LAST + i;

      if (aitimer->timer) {
        log_normal("AI timer stats: [%15.3f] P%03d (AI type: %s)",
                   read_timer_seconds(aitimer->timer), j, ai_name(ai));
        free_timer(aitimer->timer);
      }
    }
  }
  free(aitimers);
  aitimers = NULL;

  free(aitimer_plrs);
  aitimer_plrs = NULL;
}

*
  Get the timer for the AI.
*****************************************************************************/
static struct ai_timer *ai_timer_get(const struct ai_type *ai)
{
  struct ai_timer *aitimer;

  fc_assert_ret_val(ai != NULL, NULL);

  fc_assert_ret_val(aitimers != NULL, NULL);

  aitimer = aitimers + ai_type_number(ai);

  if (!aitimer->timer) {
    aitimer->timer = new_timer(TIMER_CPU, TIMER_DEBUG);
  }

  return aitimer;
}

*
  Get the timer for the AI of a player.
*****************************************************************************/
static struct ai_timer *ai_timer_player_get(const struct player *pplayer)
{
  struct ai_timer *aitimer;

  fc_assert_ret_val(pplayer != NULL, NULL);
  fc_assert_ret_val(pplayer->ai != NULL, NULL);

  fc_assert_ret_val(aitimer_plrs != NULL, NULL);

  aitimer = aitimer_plrs + (player_index(pplayer) * FC_AI_LAST
                            + ai_type_number(pplayer->ai));

  if (!aitimer->timer) {
    aitimer->timer = new_timer(TIMER_CPU, TIMER_DEBUG);
  }

  return aitimer;
}

*
  Start the timer for the AI.
*****************************************************************************/
void ai_timer_start(const struct ai_type *ai)
{
  struct ai_timer *aitimer = ai_timer_get(ai);

  fc_assert_ret(aitimer != NULL);
  fc_assert_ret(aitimer->timer != NULL);

  if (aitimer->count == 0) {
    log_debug("AI timer start  [%15.3f] ---- (AI type: %s)",
              read_timer_seconds(aitimer->timer), ai_name(ai));
    start_timer(aitimer->timer);
  } else {
    log_debug("AI timer =====> [depth: %3d]      ---- (AI type: %s)",
              aitimer->count, ai_name(ai));
  }
  aitimer->count++;
}

*
  Stop the timer for the AI.
*****************************************************************************/
void ai_timer_stop(const struct ai_type *ai)
{
  struct ai_timer *aitimer = ai_timer_get(ai);

  fc_assert_ret(aitimer != NULL);
  fc_assert_ret(aitimer->timer != NULL);

  if (aitimer->count > 0) {
    if (aitimer->count == 1) {
      stop_timer(aitimer->timer);
      log_debug("AI timer stop   [%15.3f] ---- (AI type: %s)",
                read_timer_seconds(aitimer->timer), ai_name(ai));
    } else {
      log_debug("AI timer =====> [depth: %3d]      ---- (AI type: %s)",
                aitimer->count, ai_name(ai));
    }
    aitimer->count--;
  } else {
    log_debug("AI timer missing?                 ---- (AI type: %s)",
              ai_name(ai));
  }
}

*
  Start the timer for the AI of a player.
*****************************************************************************/
void ai_timer_player_start(const struct player *pplayer)
{
  struct ai_timer *aitimer = ai_timer_player_get(pplayer);

  fc_assert_ret(aitimer != NULL);
  fc_assert_ret(aitimer->timer != NULL);

  if (aitimer->count == 0) {
    log_debug("AI timer start  [%15.3f] P%03d (AI type: %s) %s",
              read_timer_seconds(aitimer->timer), player_index(pplayer),
              ai_name(pplayer->ai), player_name(pplayer));
    start_timer(aitimer->timer);
  } else {
    log_debug("AI timer =====> [depth: %3d]      P%03d (AI type: %s) %s",
              aitimer->count, player_index(pplayer), ai_name(pplayer->ai),
              player_name(pplayer));
  }
  aitimer->count++;
}

*
  Stop the timer for the AI of a player.
*****************************************************************************/
void ai_timer_player_stop(const struct player *pplayer)
{
  struct ai_timer *aitimer = ai_timer_player_get(pplayer);

  fc_assert_ret(aitimer != NULL);
  fc_assert_ret(aitimer->timer != NULL);

  if (aitimer->count > 0) {
    if (aitimer->count == 1) {
      stop_timer(aitimer->timer);
      log_debug("AI timer stop   [%15.3f] P%03d (AI type: %s) %s",
                read_timer_seconds(aitimer->timer), player_index(pplayer),
                ai_name(pplayer->ai), player_name(pplayer));
    } else {
      log_debug("AI timer =====> [depth: %3d]      P%03d (AI type: %s) %s",
                aitimer->count, player_index(pplayer), ai_name(pplayer->ai),
                player_name(pplayer));
    }
    aitimer->count--;
  } else {
    log_debug("AI timer missing?                 P%03d (AI type: %s) %s",
              player_index(pplayer), ai_name(pplayer->ai),
              player_name(pplayer));
  }
}
#endif /* DEBUG_AITIMERS */


  Returns ai_type of given id.
***************************************************************/
struct ai_type *get_ai_type(int id)
{
  fc_assert(id >= 0 && id < FC_AI_LAST);

  return &ai_types[id];
}


  Initializes AI structure.
***************************************************************/
void init_ai(struct ai_type *ai)
{
  memset(ai, 0, sizeof(*ai));
}


  Returns id of the given ai_type.
***************************************************************/
int ai_type_number(const struct ai_type *ai)
{
  int ainbr = ai - ai_types;

  fc_assert_ret_val(ainbr >= 0 && ainbr < FC_AI_LAST, 0);

  return ainbr;
}


  Find ai type with given name.
***************************************************************/
struct ai_type *ai_type_by_name(const char *search)
{
  ai_type_iterate(ai) {
    if (!fc_strcasecmp(ai_name(ai), search)) {
      return ai;
    }
  } ai_type_iterate_end;

  return NULL;
}


  Return next free ai_type
***************************************************************/
struct ai_type *ai_type_alloc(void)
{
  if (ai_type_count >= FC_AI_LAST) {
    log_error(_("Too many AI modules. Max is %d."), FC_AI_LAST);
    return NULL;
  }

  return get_ai_type(ai_type_count++);
}


  Return number of ai types
***************************************************************/
int ai_type_get_count(void)
{
  return ai_type_count;
}

*
  Return the name of the ai type.
*****************************************************************************/
const char *ai_name(const struct ai_type *ai)
{
  fc_assert_ret_val(ai, NULL);
  return ai->name;
}
ENDREP
id: 4go.5ii.r26586/8261
type: file
pred: 4go.5ck.r20385/11580
count: 16
text: 26586 0 8233 9922 e01441273014e5941743dd5e662adc91
cpath: /branches/S2_4/common/ai.c
copyroot: 20416 /branches/S2_4

PLAIN
K 11
Makefile.am
V 23
file 5h.5ii.r25191/1004
K 4
ai.c
V 24
file 4go.5ii.r26586/8261
K 4
ai.h
V 24
file 4gp.5ii.r26148/1351
K 6
aicore
V 22
dir 18t.5ii.r26479/974
K 6
base.c
V 24
file 3jw.5ii.r24787/4577
K 6
base.h
V 25
file 3jx.5ii.r24740/16216
K 9
borders.c
V 26
file 4f0.5ck.r19259/404033
K 9
borders.h
V 25
file 4f1.5ck.r18858/99721
K 8
capstr.c
V 22
file dv.5ii.r24978/289
K 8
capstr.h
V 24
file dw.5ck.r18858/97074
K 10
citizens.c
V 24
file 6mx.5ii.r20854/5448
K 10
citizens.h
V 24
file 6my.5ii.r20854/5648
K 6
city.c
V 24
file q.5ii.r26107/108235
K 6
city.h
V 25
file 3q.5ii.r26107/108496
K 8
combat.c
V 24
file wp.5ii.r24575/15368
K 8
combat.h
V 24
file wq.5ii.r24575/15628
K 12
connection.c
V 22
file un.5ii.r25724/183
K 12
connection.h
V 24
file uo.5ii.r22459/30795
K 8
dataio.c
V 24
file 15r.5ii.r22338/7523
K 8
dataio.h
V 24
file 15s.5ii.r22338/7781
K 11
diptreaty.c
V 25
file 3r.5ck.r19259/398261
K 11
diptreaty.h
V 24
file 3s.5ck.r18858/95921
K 9
effects.c
V 24
file 2eo.5ii.r24407/2935
K 9
effects.h
V 24
file 2ep.5ii.r23559/2198
K 8
events.c
V 24
file 33h.5ii.r20800/3501
K 8
events.h
V 23
file 3t.5ii.r20800/3754
K 12
fc_cmdhelp.c
V 24
file 76j.5ii.r20868/4017
K 12
fc_cmdhelp.h
V 23
file 76k.5ii.r23665/127
K 14
fc_interface.c
V 25
file 4up.5ck.r20355/12590
K 14
fc_interface.h
V 25
file 4uq.5ck.r20355/12782
K 10
fc_types.h
V 24
file 2ll.5ii.r20645/4864
K 15
featured_text.c
V 24
file 4h3.5ii.r24897/4867
K 15
featured_text.h
V 24
file 4h4.5ii.r24897/5076
K 6
game.c
V 23
file 3u.5ii.r26087/9553
K 6
game.h
V 23
file 3v.5ii.r25617/7942
K 19
generate_packets.py
V 24
file 2f4.5ii.r24183/3217
K 12
government.c
V 25
file he.5ck.r19259/403289
K 12
government.h
V 24
file hf.5ck.r18858/98787
K 6
idex.c
V 25
file qo.5ck.r19259/406132
K 6
idex.h
V 24
file qp.5ck.r18858/92434
K 13
improvement.c
V 24
file vb.5ii.r24794/52504
K 13
improvement.h
V 24
file vc.5ii.r24794/52767
K 5
map.c
V 22
file r.5ii.r26430/5919
K 5
map.h
V 23
file 41.5ii.r26439/3758
K 8
mapimg.c
V 25
file 6n9.5ii.r23661/12362
K 8
mapimg.h
V 24
file 6na.5ii.r22509/7699
K 10
movement.c
V 23
file 2xv.5ii.r25840/551
K 10
movement.h
V 25
file 2xw.5ii.r23640/17087
K 18
name_translation.h
V 25
file 4k1.5ck.r20375/19703
K 8
nation.c
V 23
file il.5ii.r25358/3356
K 8
nation.h
V 23
file im.5ii.r25358/3611
K 9
packets.c
V 22
file 43.5ii.r23802/718
K 11
packets.def
V 26
file 2f5.5ii.r26231/128236
K 9
packets.h
V 23
file 44.5ii.r22338/7266
K 8
player.c
V 23
file 45.5ii.r26461/5907
K 8
player.h
V 25
file 46.5ii.r26231/128759
K 14
requirements.c
V 25
file 2wq.5ii.r24794/53027
K 14
requirements.h
V 24
file 2wr.5ii.r24787/4314
K 10
research.c
V 23
file 4ro.5ii.r24930/986
K 10
research.h
V 26
file 4rp.5ii.r26231/128031
K 10
rgbcolor.c
V 25
file 6i6.5ii.r21337/22295
K 10
rgbcolor.h
V 25
file 6i7.5ii.r21337/22497
K 6
road.c
V 25
file 6pq.5ck.r20375/18244
K 6
road.h
V 23
file 6pr.5ck.r20158/663
K 10
scriptcore
V 23
dir 75a.5ii.r26378/1737
K 11
spaceship.c
V 25
file 98.5ck.r19259/405393
K 11
spaceship.h
V 25
file 99.5ck.r18858/100885
K 12
specialist.c
V 23
file 33f.5ii.r22373/258
K 12
specialist.h
V 26
file 33g.5ck.r19113/124404
K 6
team.c
V 23
file 33i.5ii.r25893/212
K 6
team.h
V 23
file 33j.5ii.r26185/314
K 6
tech.c
V 22
file t.5ii.r26277/6388
K 6
tech.h
V 23
file u.5ii.r26064/50165
K 9
terrain.c
V 24
file 2fp.5ii.r24787/4830
K 9
terrain.h
V 24
file qs.5ii.r21744/13069
K 6
tile.c
V 24
file 2ys.5ii.r26111/5328
K 6
tile.h
V 24
file 2yt.5ii.r26111/5582
K 6
unit.c
V 21
file v.5ii.r26246/194
K 6
unit.h
V 24
file 48.5ii.r26259/14584
K 10
unitlist.c
V 25
file 39m.5ck.r20387/34514
K 10
unitlist.h
V 24
file 39n.5ii.r24116/1816
K 10
unittype.c
V 22
file v9.5ii.r25547/788
K 10
unittype.h
V 23
file va.5ii.r25547/1044
K 9
version.c
V 23
file oe.5ii.r25788/3423
K 9
version.h
V 23
file e7.5ii.r24202/9010
K 8
vision.c
V 26
file 4dm.5ck.r19259/404222
K 8
vision.h
V 24
file 4dn.5ck.r19112/9796
K 10
worklist.c
V 25
file o8.5ck.r19259/402799
K 10
worklist.h
V 24
file o9.5ck.r18858/98299
END
ENDREP
id: p.5ii.r26586/12441
type: dir
pred: p.5ii.r26479/5212
count: 3290
text: 26586 8456 3972 3972 96a004326c6a02f2dbf8f9dfd1abb328
props: 23738 0 112 0 b2bc91bf125d83375389d51f25ff2c2f
cpath: /branches/S2_4/common
copyroot: 20416 /branches/S2_4

PLAIN
K 9
ABOUT-NLS
V 22
file fu.0.r13215/85704
K 7
AUTHORS
V 24
file 5u.5ii.r22144/14016
K 7
COPYING
V 19
file 1h.0.r9643/400
K 9
ChangeLog
V 26
file 6l.5ii.r25883/5694991
K 7
INSTALL
V 23
file 6.5ii.r23651/28514
K 11
Makefile.am
V 24
file 59.5ii.r23989/13807
K 4
NEWS
V 24
file 6m.5ii.r25632/75507
K 8
NEWS-2.4
V 25
file jp5.5ii.r25880/14898
K 6
README
V 20
file 7.0.r4421/96382
K 2
ai
V 21
dir 8.5ii.r26446/2828
K 10
autogen.sh
V 23
file 12o.5ii.r24093/115
K 9
bootstrap
V 23
dir 2p5.5ii.r25972/2965
K 6
client
V 21
dir d.5ii.r26560/6692
K 6
common
V 22
dir p.5ii.r26586/12441
K 12
config.mac.h
V 20
file hb.0.r6045/5982
K 12
configure.ac
V 24
file 149.5ii.r26148/1097
K 4
data
V 21
dir w.5ii.r26537/4687
K 6
debian
V 22
dir 5w.5ii.r22192/3202
K 12
dependencies
V 23
dir 2yu.5ii.r25596/4029
K 11
diff_ignore
V 22
file qq.5ck.r19346/607
K 3
doc
V 22
dir k7.5ii.r26412/9107
K 10
fc_version
V 26
file 2lo.5ij.r26231/136661
K 2
m4
V 23
dir 12p.5ii.r25030/2842
K 6
manual
V 23
dir 2m2.5ii.r24834/7345
K 7
modinst
V 24
dir 4pj.5ii.r25963/10460
K 2
po
V 25
dir fs.5ii.r26567/2125244
K 7
scripts
V 22
dir 2yo.5ii.r24504/875
K 6
server
V 22
dir z.5ii.r26549/11758
K 10
stamp-h.in
V 19
file 80.0.r1125/241
K 5
tests
V 22
dir 2g9.5ii.r22097/841
K 7
utility
V 22
dir 1c.5ii.r26472/3046
K 3
vms
V 25
dir u9.5ii.r21529/1398731
K 5
win32
V 23
dir 2eu.5ii.r24296/3491
END
ENDREP
id: 3.5ii.r26586/14051
type: dir
pred: 3.5ii.r26567/2126858
count: 16309
text: 26586 12685 1353 1353 c181c4d17065cc00c53b3cdfb2b106e3
props: 20140 3888 282 0 e4bb46e81629a60eef613b169b23a9ea
cpath: /branches/S2_4
copyroot: 20416 /branches/S2_4

PLAIN
K 5
S1_14
V 21
dir 3.21.r18109/18803
K 4
S2_0
V 21
dir 3.10x.r21862/4178
K 4
S2_1
V 22
dir 3.59e.r20026/11014
K 4
S2_2
V 21
dir 3.5cy.r21861/5036
K 4
S2_3
V 21
dir 3.5f2.r24391/5183
K 4
S2_4
V 22
dir 3.5ii.r26586/14051
K 4
S2_5
V 21
dir 3.5kv.r26585/6526
K 11
freeciv-web
V 22
dir 3.5bl.r13594/14918
END
ENDREP
id: 1.0.r26586/14613
type: dir
pred: 1.0.r26585/7086
count: 8092
text: 26586 14296 304 304 5c939eba56752c6125d3b4aa35565ab9
cpath: /branches
copyroot: 0 /

PLAIN
K 8
branches
V 20
dir 1.0.r26586/14613
K 4
tags
V 19
dir 2.0.r25885/6524
K 5
trunk
V 21
dir 3.5ck.r26584/7410
K 7
website
V 21
dir 3ge.0.r22980/2263
END
ENDREP
id: 0.0.r26586/14935
type: dir
pred: 0.0.r26585/7406
count: 26586
text: 26586 14769 153 153 2a4d14dc8c64fae1a78fc7bf6ec33d95
cpath: /
copyroot: 0 /

4go.5ii.t26585-1 modify true false /branches/S2_4/common/ai.c


14935 15084
