map.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* $Id: map.c,v 1.19 2001/04/29 22:24:37 kilobug Exp $ */
  2. #include "client.h"
  3. static void destroy_player(player_t *player)
  4. {
  5. if (player == NULL)
  6. return;
  7. destroy_picture(player->akx);
  8. destroy_picture(player->r4d2);
  9. g_free(player->gdkcol);
  10. g_free(player);
  11. }
  12. void destroy_map(conf_t *conf)
  13. {
  14. int i;
  15. conf->ready = FALSE;
  16. if (conf->map == NULL)
  17. return;
  18. if (conf->map->players != NULL)
  19. {
  20. for (i = 0; i <= conf->map->nb_players; i++)
  21. destroy_player(conf->map->players[i]);
  22. g_free(conf->map->players);
  23. }
  24. if (conf->map->objects != NULL)
  25. {
  26. for (i = 0; i < conf->map->nb_objects; i++)
  27. if (conf->map->objects[i] != NULL)
  28. g_free(conf->map->objects[i]);
  29. g_free(conf->map->objects);
  30. }
  31. g_free(conf->map->sand_file);
  32. destroy_picture(conf->map->background);
  33. g_free(conf->map);
  34. conf->map = NULL;
  35. }
  36. static void update_players(conf_t *conf)
  37. {
  38. int id, i;
  39. while ((i = net_chk_str_list(conf->socket, "UPL", "END", NULL)) == 0)
  40. {
  41. id = net_get_int(conf->socket);
  42. conf->map->players[id]->score = net_get_float(conf->socket);
  43. }
  44. if (i < 0)
  45. protocol_error(conf, "UPL or END expected");
  46. net_send_ack(conf->file);
  47. player_list_refresh(conf);
  48. stats_refresh(conf);
  49. }
  50. static void update_objects(conf_t *conf)
  51. {
  52. int id, i;
  53. while ((i = net_chk_str_list(conf->socket, "UOB", "END", NULL)) == 0)
  54. {
  55. id = net_get_int(conf->socket);
  56. get_object_param(conf->socket, conf->map->objects[id], conf);
  57. conf->map->objects[id]->changed = TRUE;
  58. }
  59. if (i < 0)
  60. protocol_error(conf, "UOB or END expected");
  61. net_send_ack(conf->file);
  62. }
  63. static void update_map(conf_t *conf)
  64. {
  65. int i = 0;
  66. conf->ready = FALSE;
  67. i = net_chk_str_list(conf->socket, "TRN", "BYE", NULL);
  68. if (i == -1)
  69. {
  70. protocol_error(conf, "TRN expected");
  71. return;
  72. }
  73. if (i == 1)
  74. {
  75. net_send_ack(conf->file);
  76. close_socket(conf);
  77. set_status(conf, "Match terminé.");
  78. return;
  79. }
  80. i = net_get_int(conf->socket);
  81. conf->map->turn_num = CLAMP(i, 0, conf->map->nb_turns);
  82. net_send_ack(conf->file);
  83. update_players(conf);
  84. for (i = 0; i < conf->map->nb_objects; i++)
  85. conf->map->objects[i]->changed = FALSE;
  86. update_objects(conf);
  87. conf->ready = TRUE;
  88. gamearea_refresh(conf->main, conf);
  89. minimap_refresh(conf->mini, conf);
  90. if ((conf->debug) && (conf->turn.mode == tt_skip))
  91. {
  92. conf->turn.st_turns--;
  93. if (!conf->turn.st_turns)
  94. conf->turn.mode = tt_pause;
  95. allow_new_turn(conf);
  96. }
  97. if ((conf->debug) && (conf->turn.mode == tt_fwd))
  98. conf->turn.gtkto = gtk_timeout_add(conf->turn.spd, tb_new_turn, conf);
  99. }
  100. void update_map_callback(void *conf, gint src, GdkInputCondition cond)
  101. {
  102. update_map(conf);
  103. }