Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2001:
[Freeciv-Dev] Corrected code
Home

[Freeciv-Dev] Corrected code

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Raimar Falke <hawk@xxxxxxxxxxxxxxxxxxxxxxx>
Cc: freeciv development list <freeciv-dev@xxxxxxxxxxx>
Subject: [Freeciv-Dev] Corrected code
From: Raahul Kumar <raahul_da_man@xxxxxxxxx>
Date: Sun, 23 Sep 2001 04:30:31 -0700 (PDT)

Thanks for all the feedback. Let me know if the
problems with my email continually recur, if so I will
send email
from a different provider. I have attached the
corrected code both as attachment and as inline text.

static void apply_result_on_server(struct city *pcity,
                                   const struct cma_result *const result)
{
  struct packet_city_request packet;
  int first_request_id = 0, last_request_id = 0, i,
extra_scientists = 0,extra_taxmans = 0,worker = 0;
  int req_scientists = 0, req_taxmans = 0;
struct cma_result current_state;

  get_current_as_result(pcity, &current_state);

  if (results_are_equal(result, &current_state)) {
    stats.apply_result_ignored++;
    return;
  }

  stats.apply_result_applied++;

  freelog(APPLY_RESULT_LOG_LEVEL,
"apply_result(city='%s'(%d))",
          pcity->name, pcity->id);

  connection_do_buffer(&aconnection);

  packet.city_id = pcity->id;
  packet.name[0] = '\0';
  packet.worklist.name[0] = '\0';

  /*
   * Do checks
   */
  city_map_iterate(x, y) {
    if (x == 2 && y == 2)
      continue;

    if (result->worker_positions_used[x][y]) {
      worker++;
    }
  }
  city_map_iterate_end;

  if (pcity->size !=
      (worker + result->entertainers +
result->scientists +
       result->taxmans)) {
    print_city(pcity);
    print_cma_result(result);
    assert(0);
  }

  /*
   * Remove all surplus workers
   */
  city_map_iterate(x, y) {
    if (x == 2 && y == 2)
      continue;
    if ((pcity->city_map[x][y] == C_TILE_WORKER) &&
(!result->worker_positions_used[x][y])) {
      last_request_id = set_worker(pcity, x, y, 0);
      if (!first_request_id) {
        first_request_id = last_request_id;
      }
    }
  }
  city_map_iterate_end;

  /*
   * Change surplus scientists to entertainers
   */
extra_scientists = (pcity->ppl_scientist -
result->scientists);
if (extra_scientists > 0)
  for (i = 0; i < extra_scientists; i++) {
    packet.specialist_from = SP_SCIENTIST;
    packet.specialist_to = SP_ELVIS;
    last_request_id =
send_packet_city_request(&aconnection, &packet,
                                               PACKET_CITY_CHANGE_SPECIALIST);
    if (!first_request_id) {
      first_request_id = last_request_id;
    }
  }

  /*
   * Change extra taxmans to entertainers
   */
extra_taxmans = (pcity->ppl_taxman - result->taxmans);
if (extra_taxmans > 0)
  for (i = 0; i < extra_taxmans; i++) {
    packet.specialist_from = SP_TAXMAN;
    packet.specialist_to = SP_ELVIS;
    last_request_id =
send_packet_city_request(&aconnection, &packet,
                                               PACKET_CITY_CHANGE_SPECIALIST);
    if (!first_request_id) {
      first_request_id = last_request_id;
    }
  }

  /* now all surplus people are enterainers */

  /*
   * Set workers
   */
  city_map_iterate(x, y) {
    if (x == 2 && y == 2)
      continue;

    if (result->worker_positions_used[x][y] &&
pcity->city_map[x][y] != C_TILE_WORKER) {
      last_request_id = set_worker(pcity, x, y, 1);
      if (!first_request_id) {
        first_request_id = last_request_id;
      }
    }
  }
  city_map_iterate_end;

  /*
   * Set scientists.
   */
req_scientists = (result->scientists -
pcity->ppl_scientist);
if (req_scientists > 0)
  for (i = 0; i < req_scientists; i++) {
    packet.specialist_from = SP_ELVIS;
    packet.specialist_to = SP_SCIENTIST;
    last_request_id =
send_packet_city_request(&aconnection, &packet,
                                               PACKET_CITY_CHANGE_SPECIALIST);
    if (!first_request_id) {
      first_request_id = last_request_id;
    }
  }

  /*
   * Set taxmans.
   */
req_taxmans = (result->taxmans - pcity->ppl_taxman);
if (req_taxmans > 0)
  for (i = 0; i < req_taxmans; i++) {
    packet.specialist_from = SP_ELVIS;
    packet.specialist_to = SP_TAXMAN;
    last_request_id =
send_packet_city_request(&aconnection, &packet,
                                               PACKET_CITY_CHANGE_SPECIALIST);
    if (!first_request_id) {
      first_request_id = last_request_id;
    }
  }

  connection_do_unbuffer(&aconnection);

  if (last_request_id) {
    wait_for_requests("CMA", first_request_id,
last_request_id);
  }

  /*
   * Do some checks
   */
  get_current_as_result(pcity, &current_state);

  if (!results_are_equal(result, &current_state)) {
    freelog(LOG_NORMAL, "city='%s' expected result:",
pcity->name);
    print_cma_result(result);
    freelog(LOG_NORMAL, "got:");
    print_cma_result(&current_state);
    assert(0);
  }

  freelog(APPLY_RESULT_LOG_LEVEL, "apply_result:
return");
}


__________________________________________________
Do You Yahoo!?
Get email alerts & NEW webcam video instant messaging with Yahoo! Messenger. 
http://im.yahoo.com
static void apply_result_on_server(struct city *pcity,
                                   const struct cma_result *const result)
{
  struct packet_city_request packet;
  int first_request_id = 0, last_request_id = 0, i, extra_scientists = 
0,extra_taxmans = 0,worker = 0;
  int req_scientists = 0, req_taxmans = 0;
struct cma_result current_state;

  get_current_as_result(pcity, &current_state);

  if (results_are_equal(result, &current_state)) {
    stats.apply_result_ignored++;
    return;
  }

  stats.apply_result_applied++;

  freelog(APPLY_RESULT_LOG_LEVEL, "apply_result(city='%s'(%d))",
          pcity->name, pcity->id);

  connection_do_buffer(&aconnection);

  packet.city_id = pcity->id;
  packet.name[0] = '\0';
  packet.worklist.name[0] = '\0';

  /*
   * Do checks
   */
  city_map_iterate(x, y) {
    if (x == 2 && y == 2)
      continue;

    if (result->worker_positions_used[x][y]) {
      worker++;
    }
  }
  city_map_iterate_end;

  if (pcity->size !=
      (worker + result->entertainers + result->scientists +
       result->taxmans)) {
    print_city(pcity);
    print_cma_result(result);
    assert(0);
  }

  /*
   * Remove all surplus workers
   */
  city_map_iterate(x, y) {
    if (x == 2 && y == 2)
      continue;
    if ((pcity->city_map[x][y] == C_TILE_WORKER) && 
(!result->worker_positions_used[x][y])) {
      last_request_id = set_worker(pcity, x, y, 0);
      if (!first_request_id) {
        first_request_id = last_request_id;
      }
    }
  }
  city_map_iterate_end;

  /*
   * Change surplus scientists to entertainers
   */
extra_scientists = (pcity->ppl_scientist - result->scientists);
if (extra_scientists > 0)
  for (i = 0; i < extra_scientists; i++) {
    packet.specialist_from = SP_SCIENTIST;
    packet.specialist_to = SP_ELVIS;
    last_request_id = send_packet_city_request(&aconnection, &packet,
                                               PACKET_CITY_CHANGE_SPECIALIST);
    if (!first_request_id) {
      first_request_id = last_request_id;
    }
  }

  /*
   * Change extra taxmans to entertainers
   */
extra_taxmans = (pcity->ppl_taxman - result->taxmans);
if (extra_taxmans > 0)
  for (i = 0; i < extra_taxmans; i++) {
    packet.specialist_from = SP_TAXMAN;
    packet.specialist_to = SP_ELVIS;
    last_request_id = send_packet_city_request(&aconnection, &packet,
                                               PACKET_CITY_CHANGE_SPECIALIST);
    if (!first_request_id) {
      first_request_id = last_request_id;
    }
  }

  /* now all surplus people are enterainers */

  /*
   * Set workers
   */
  city_map_iterate(x, y) {
    if (x == 2 && y == 2)
      continue;

    if (result->worker_positions_used[x][y] && pcity->city_map[x][y] != 
C_TILE_WORKER) {
      last_request_id = set_worker(pcity, x, y, 1);
      if (!first_request_id) {
        first_request_id = last_request_id;
      }
    }
  }
  city_map_iterate_end;

  /*
   * Set scientists.
   */
req_scientists = (result->scientists - pcity->ppl_scientist);
if (req_scientists > 0)
  for (i = 0; i < req_scientists; i++) {
    packet.specialist_from = SP_ELVIS;
    packet.specialist_to = SP_SCIENTIST;
    last_request_id = send_packet_city_request(&aconnection, &packet,
                                               PACKET_CITY_CHANGE_SPECIALIST);
    if (!first_request_id) {
      first_request_id = last_request_id;
    }
  }

  /*
   * Set taxmans.
   */
req_taxmans = (result->taxmans - pcity->ppl_taxman);
if (req_taxmans > 0)
  for (i = 0; i < req_taxmans; i++) {
    packet.specialist_from = SP_ELVIS;
    packet.specialist_to = SP_TAXMAN;
    last_request_id = send_packet_city_request(&aconnection, &packet,
                                               PACKET_CITY_CHANGE_SPECIALIST);
    if (!first_request_id) {
      first_request_id = last_request_id;
    }
  }

  connection_do_unbuffer(&aconnection);

  if (last_request_id) {
    wait_for_requests("CMA", first_request_id, last_request_id);
  }

  /*
   * Do some checks
   */
  get_current_as_result(pcity, &current_state);

  if (!results_are_equal(result, &current_state)) {
    freelog(LOG_NORMAL, "city='%s' expected result:", pcity->name);
    print_cma_result(result);
    freelog(LOG_NORMAL, "got:");
    print_cma_result(&current_state);
    assert(0);
  }

  freelog(APPLY_RESULT_LOG_LEVEL, "apply_result: return");
}

[Prev in Thread] Current Thread [Next in Thread]