コード例 #1
0
ファイル: unit.c プロジェクト: UweKopf/server
void u_setfaction(unit * u, faction * f)
{
  int cnt = u->number;

  if (u->faction == f)
    return;
  if (u->faction) {
    set_number(u, 0);
    if (count_unit(u))
      --u->faction->no_units;
    join_group(u, NULL);
    free_orders(&u->orders);
    set_order(&u->thisorder, NULL);

    if (u->nextF)
      u->nextF->prevF = u->prevF;
    if (u->prevF)
      u->prevF->nextF = u->nextF;
    else
      u->faction->units = u->nextF;
  }

  if (f != NULL) {
    if (f->units)
      f->units->prevF = u;
    u->prevF = NULL;
    u->nextF = f->units;
    f->units = u;
  } else
    u->nextF = NULL;

  u->faction = f;
  if (u->region)
    update_interval(f, u->region);
  if (cnt && f) {
    set_number(u, cnt);
    if (count_unit(u))
      ++f->no_units;
  }
}
コード例 #2
0
int main()
{
    int i,j;
    get_test_num(&T);
    while((T--)>0)
    {
        init_bulk(&b);
        get_a_bulk(&b);
        format_bulk(&b);
        count_unit(&b);
        printf("The bulk is composed of %d units.\n",b.U);
    }
    return 0;
}