Browse Source

Moved things around, started to update server to get rid of glib and handle file move, also added cmake files to build it

Godzil 6 years ago
parent
commit
3ea13e4f73
100 changed files with 3243 additions and 994 deletions
  1. 32 0
      CMakeLists.txt
  2. 0 106
      configure.in
  3. 0 0
      gclient/Makefile.am
  4. 0 0
      gclient/gamearea.c
  5. 0 0
      gclient/gen_bigmap.c
  6. 0 0
      gclient/gen_bigmap2.c
  7. 0 0
      gclient/gen_minimap.c
  8. 0 0
      gclient/gtk.c
  9. 0 0
      gclient/include/client.h
  10. 0 0
      gclient/include/client_gtk.h
  11. 0 0
      gclient/init.c
  12. 0 0
      gclient/load_map.c
  13. 0 0
      gclient/main.c
  14. 0 0
      gclient/mainbox.c
  15. 0 0
      gclient/map.c
  16. 0 0
      gclient/menubar.c
  17. 0 0
      gclient/minimap.c
  18. 0 0
      gclient/network.c
  19. 0 0
      gclient/pixbuf.c
  20. 0 0
      gclient/players.c
  21. 0 0
      gclient/stats.c
  22. 0 0
      gclient/statusbar.c
  23. 0 0
      gclient/toolbar.c
  24. 0 0
      gtkutil/Makefile.am
  25. 0 0
      gtkutil/callbacks.c
  26. 0 0
      gtkutil/clist.c
  27. 0 0
      gtkutil/create.c
  28. 0 0
      gtkutil/filesel.c
  29. 0 0
      include/client/c++/prolo.hh
  30. 0 0
      include/client/c/prolo.h
  31. 0 0
      include/client/cpp/prolo.hh
  32. 0 0
      include/client/pas/prolo.pas
  33. 12 0
      include/general.h
  34. 0 0
      include/gtkutil.h
  35. 2 0
      include/pulsarnet.h
  36. 0 0
      meta-client/Makefile.am
  37. 0 0
      meta-client/bitmaps.c
  38. 0 0
      meta-client/champions.c
  39. 0 0
      meta-client/gtk_main.c
  40. 0 0
      meta-client/include/mclient.h
  41. 0 0
      meta-client/include/mysql.h
  42. 0 0
      meta-client/include/tournois.h
  43. 0 0
      meta-client/init.c
  44. 0 0
      meta-client/main.c
  45. 0 0
      meta-client/maps.c
  46. 0 0
      meta-client/matchs.c
  47. 0 0
      meta-client/menubar.c
  48. 0 0
      meta-client/mysql.c
  49. 0 0
      meta-client/mysql_list.c
  50. 0 0
      meta-client/run_match.c
  51. 0 0
      meta-client/run_tournois.c
  52. 0 0
      meta-client/tournois.c
  53. 0 0
      pulsarnet/Makefile.am
  54. 0 0
      pulsarnet/check.c
  55. 0 0
      pulsarnet/error.c
  56. 0 0
      pulsarnet/misc.c
  57. 0 0
      pulsarnet/net_private.h
  58. 0 0
      pulsarnet/open.c
  59. 0 0
      pulsarnet/read.c
  60. 0 0
      pulsarnet/write.c
  61. 24 0
      server/CMakeLists.txt
  62. 23 0
      server/bouvier.c
  63. 735 0
      server/client.c
  64. 464 0
      server/exec.c
  65. 215 0
      server/game.c
  66. 80 0
      server/include/action.h
  67. 12 0
      server/include/client.h
  68. 8 3
      server/include/conf.h
  69. 0 0
      server/include/erreur.h
  70. 5 3
      server/include/exec.h
  71. 0 0
      server/include/game.h
  72. 12 0
      server/include/ipc.h
  73. 1 1
      server/include/message.h
  74. 35 0
      server/include/network.h
  75. 0 0
      server/include/parser.h
  76. 44 0
      server/include/plugins.h
  77. 68 0
      server/include/private.h
  78. 0 0
      server/include/public.h
  79. 23 0
      server/include/server.h
  80. 198 0
      server/init.c
  81. 92 0
      server/ipc.c
  82. 59 0
      server/main.c
  83. 62 0
      server/map.c
  84. 302 0
      server/map_parser.c
  85. 107 0
      server/message.c
  86. 192 0
      server/network.c
  87. 148 0
      server/network_connect.c
  88. 38 0
      server/objects.c
  89. 0 0
      server/parser.c
  90. 126 0
      server/plugins.c
  91. 77 0
      server/pulse.c
  92. 47 0
      server/time.c
  93. 0 25
      src/Makefile.am
  94. 0 10
      src/cleanshm.sh
  95. 0 52
      src/general.h
  96. 0 23
      src/server/Makefile.am
  97. 0 71
      src/server/action.h
  98. 0 25
      src/server/bouvier.c
  99. 0 663
      src/server/client.c
  100. 0 12
      src/server/client.h

+ 32 - 0
CMakeLists.txt

@@ -0,0 +1,32 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(ThePulsars)
+
+option(BUILD_SERVER "Build server" ON)
+# Currently does not build, do no enable
+option(BUILD_GCLIENT "Build graphical client" OFF)
+option(BUILD_METACLIENT "Build meta client" OFF)
+
+option(ENABLE_PASCAL "Enable pascal support" OFF)
+option(ENABLE_EFENCE "Enable ElectricFence" OFF)
+
+add_compile_options(-Wall -Werror)
+include_directories(include)
+
+#add_subdirectory(pulsarnet)
+
+if (BUILD_SERVER)
+    add_subdirectory(server)
+endif()
+
+if (BUILD_GCLIENT OR BUILD_METACLIENT)
+    add_subdirectory(gtkutil)
+endif()
+
+if (BUILD_GCLIENT)
+    add_subdirectory(gclient)
+endif()
+
+if (BUILD_METACLIENT)
+    add_subdirectory(meta-client)
+endif()

+ 0 - 106
configure.in

@@ -1,106 +0,0 @@
-dnl Process this file with autoconf to produce a configure script.
-dnl To build this package you'll need GNU autoconf, GNU automake and GNU 
-dnl libtool.
-dnl $Id: configure.in,v 1.44 2001/05/07 08:29:51 kilobug Exp $
-
-AC_INIT(configure.in)
-AM_CONFIG_HEADER(config.h)
-AM_INIT_AUTOMAKE(Finale, 0.8.1)
-
-dnl Checks for programs.
-AC_ISC_POSIX
-AC_PROG_CC
-AC_HEADER_STDC
-AM_PROG_CC_STDC
-
-dnl Libtool checks
-dnl AC_LIBTOOL_DLOPEN
-AC_PROG_RANLIB
-
-dnl Modules
-AC_ARG_ENABLE(server,
-        [  --disable-server         don't build server],
-        [SERVER="$enableval"], 
-        [SERVER="yes"])
-AC_ARG_ENABLE(gtk-client,
-        [  --disable-gtk-client     don't build gtk-client],
-        [GTKCLIENT="$enableval"], 
-        [GTKCLIENT="yes"])
-AC_ARG_ENABLE(meta-client,
-        [  --disable-meta-client    don't build meta-client],
-        [MCLIENT="$enableval"], 
-        [MCLIENT="yes"])
-
-dnl Library support
-AM_PATH_GLIB(1.2.0, , AC_MSG_ERROR(Cannot find GLIB: Is glib-config in path?))
-
-LIBGTK=no
-LIBPIXBUF=no
-LIBMYSQL=no
-
-AM_PATH_GTK(1.2.0, [ LIBGTK="yes" ], [ AC_MSG_WARN(Cannot find GTK: disabling gtk-client and meta-client.) ] )
-AM_PATH_GDK_PIXBUF(0.10.0, [ LIBPIXBUF="yes" ], [ AC_MSG_WARN(Cannot find GDK_PIXBUF: disabling gtk-client.) ] )
-
-LIBGPC="no"
-
-AC_CHECK_LIB(m, sin, [ LDFLAGS="$LDFLAGS -lm" ], [ AC_MSG_ERROR(Standard math library not found) ] )
-AC_CHECK_LIB(gpc, init_Gpc, [ LIBGPC="yes" ], [ AC_MSG_WARN(Cannot find GPC library. Pascal support will be disabled.) ] )
-
-AC_CHECK_LIB(z, uncompress, [ LDFLAGS="$LDFLAGS -lz" ], [ AC_MSG_ERROR(Zlib not found) ] )
-AC_CHECK_LIB(mysqlclient, mysql_real_connect, [ LIBMYSQL="yes" ], [ AC_MSG_WARN(Mysql library not found. Disabling meta-client.) ] )
-
-if test "$LIBGTK" = "no"
-then
-   GTKCLIENT="no"
-   MCLIENT="no"
-fi
-if test "$LIBPIXBUF" = "no"
-then
-   GTKCLIENT="no"
-fi
-if test "$LIBMYSQL" = "no"
-then
-   MCLIENT="no"
-fi
-
-AM_CONDITIONAL(AM_BUILD_GTKCLIENT, test "$GTKCLIENT" != "no")
-AM_CONDITIONAL(AM_BUILD_MCLIENT, test "$MCLIENT" != "no")
-AM_CONDITIONAL(AM_BUILD_SERVER, test "$SERVER" != "no")
-AM_CONDITIONAL(AM_BUILD_PASCAL, test "$LIBGPC" != "no")
-
-dnl Checks for header files.
-AC_CHECK_HEADERS(stdlib.h stdio.h unistd.h string.h errno.h fcntl.h math.h signal.h ctype.h)
-
-dnl Check for typedefs, structures, and compiler characteristics.
-AC_C_CONST
-
-dnl Support for --enable-debug
-AC_ARG_ENABLE(debug,
-        [  --enable-debug           enter debugging mode],
-        [FINALE_DEBUG=$enableval], 
-        [FINALE_DEBUG="no"])
-if test "$FINALE_DEBUG" != "no"
-then
-  CFLAGS="-O0 -ggdb -D__DEBUG__"
-dnl  AC_CHECK_LIB(efence, malloc, [ LDFLAGS="$LDFLAGS -lefence" ], [ AC_MSG_WARN(Electric-fence not found) ] )
-else
-  CFLAGS="-O9 -finline-functions -funroll-loops -malign-double -fno-rtti -fno-exceptions -march=i686 -fomit-frame-pointer -frerun-loop-opt -Werror"
-fi
-CFLAGS="$CFLAGS -Wall -I${HOME}/usr/lib/ocaml -I${HOME}/usr/include"
-
-dnl Output
-AC_SUBST(CFLAGS)
-AC_SUBST(LDFLAGS)
-
-AC_OUTPUT([
-Makefile
-doc/Makefile
-data/Makefile
-data/map/Makefile
-src/Makefile
-src/server/Makefile
-src/meta-client/Makefile
-src/gtk-client/Makefile
-src/netlib/Makefile
-src/gtkutil/Makefile
-])

+ 0 - 0
src/gtk-client/Makefile.am → gclient/Makefile.am


+ 0 - 0
src/gtk-client/gamearea.c → gclient/gamearea.c


+ 0 - 0
src/gtk-client/gen_bigmap.c → gclient/gen_bigmap.c


+ 0 - 0
src/gtk-client/gen_bigmap2.c → gclient/gen_bigmap2.c


+ 0 - 0
src/gtk-client/gen_minimap.c → gclient/gen_minimap.c


+ 0 - 0
src/gtk-client/gtk.c → gclient/gtk.c


+ 0 - 0
src/gtk-client/client.h → gclient/include/client.h


+ 0 - 0
src/gtk-client/client_gtk.h → gclient/include/client_gtk.h


+ 0 - 0
src/gtk-client/init.c → gclient/init.c


+ 0 - 0
src/gtk-client/load_map.c → gclient/load_map.c


+ 0 - 0
src/gtk-client/main.c → gclient/main.c


+ 0 - 0
src/gtk-client/mainbox.c → gclient/mainbox.c


+ 0 - 0
src/gtk-client/map.c → gclient/map.c


+ 0 - 0
src/gtk-client/menubar.c → gclient/menubar.c


+ 0 - 0
src/gtk-client/minimap.c → gclient/minimap.c


+ 0 - 0
src/gtk-client/network.c → gclient/network.c


+ 0 - 0
src/gtk-client/pixbuf.c → gclient/pixbuf.c


+ 0 - 0
src/gtk-client/players.c → gclient/players.c


+ 0 - 0
src/gtk-client/stats.c → gclient/stats.c


+ 0 - 0
src/gtk-client/statusbar.c → gclient/statusbar.c


+ 0 - 0
src/gtk-client/toolbar.c → gclient/toolbar.c


+ 0 - 0
src/gtkutil/Makefile.am → gtkutil/Makefile.am


+ 0 - 0
src/gtkutil/callbacks.c → gtkutil/callbacks.c


+ 0 - 0
src/gtkutil/clist.c → gtkutil/clist.c


+ 0 - 0
src/gtkutil/create.c → gtkutil/create.c


+ 0 - 0
src/gtkutil/filesel.c → gtkutil/filesel.c


+ 0 - 0
client-include/c++/prolo.hh → include/client/c++/prolo.hh


+ 0 - 0
client-include/c/prolo.h → include/client/c/prolo.h


+ 0 - 0
client-include/cpp/prolo.hh → include/client/cpp/prolo.hh


+ 0 - 0
client-include/pas/prolo.pas → include/client/pas/prolo.pas


+ 12 - 0
include/general.h

@@ -0,0 +1,12 @@
+/* $Id: general.h,v 1.11 2001/04/30 16:02:05 kilobug Exp $ */
+
+#ifndef __PROLO_GENERAL_H__
+#define __PROLO_GENERAL_H__
+
+#define False (0)
+#define True (!False)
+typedef int boolean_t;
+
+#endif
+
+

+ 0 - 0
src/gtkutil/gtkutil.h → include/gtkutil.h


+ 2 - 0
src/netlib/net.h → include/pulsarnet.h

@@ -9,6 +9,8 @@
 #include "../general.h"
 #include <glib.h>
 
+#define PROTOCOL_VERSION 0x4207
+
 typedef enum { net_type_int = 0x03, net_type_float = 0x0B, 
 	       net_type_char = 0x30, net_type_str = 0xB0,
                net_type_none = 0x33 } net_type_t;

+ 0 - 0
src/meta-client/Makefile.am → meta-client/Makefile.am


+ 0 - 0
src/meta-client/bitmaps.c → meta-client/bitmaps.c


+ 0 - 0
src/meta-client/champions.c → meta-client/champions.c


+ 0 - 0
src/meta-client/gtk_main.c → meta-client/gtk_main.c


+ 0 - 0
src/meta-client/mclient.h → meta-client/include/mclient.h


+ 0 - 0
src/meta-client/mysql.h → meta-client/include/mysql.h


+ 0 - 0
src/meta-client/tournois.h → meta-client/include/tournois.h


+ 0 - 0
src/meta-client/init.c → meta-client/init.c


+ 0 - 0
src/meta-client/main.c → meta-client/main.c


+ 0 - 0
src/meta-client/maps.c → meta-client/maps.c


+ 0 - 0
src/meta-client/matchs.c → meta-client/matchs.c


+ 0 - 0
src/meta-client/menubar.c → meta-client/menubar.c


+ 0 - 0
src/meta-client/mysql.c → meta-client/mysql.c


+ 0 - 0
src/meta-client/mysql_list.c → meta-client/mysql_list.c


+ 0 - 0
src/meta-client/run_match.c → meta-client/run_match.c


+ 0 - 0
src/meta-client/run_tournois.c → meta-client/run_tournois.c


+ 0 - 0
src/meta-client/tournois.c → meta-client/tournois.c


+ 0 - 0
src/netlib/Makefile.am → pulsarnet/Makefile.am


+ 0 - 0
src/netlib/check.c → pulsarnet/check.c


+ 0 - 0
src/netlib/error.c → pulsarnet/error.c


+ 0 - 0
src/netlib/misc.c → pulsarnet/misc.c


+ 0 - 0
src/netlib/net_private.h → pulsarnet/net_private.h


+ 0 - 0
src/netlib/open.c → pulsarnet/open.c


+ 0 - 0
src/netlib/read.c → pulsarnet/read.c


+ 0 - 0
src/netlib/write.c → pulsarnet/write.c


+ 24 - 0
server/CMakeLists.txt

@@ -0,0 +1,24 @@
+cmake_minimum_required(VERSION 3.0)
+
+project(PulsarServer)
+
+set(TARGET server)
+
+set(TARGET_HEADER_FILES include/action.h include/client.h include/conf.h include/erreur.h include/exec.h include/game.h
+        include/ipc.h include/message.h include/network.h include/parser.h include/private.h include/plugins.h
+        include/public.h include/server.h)
+
+add_executable(${TARGET} main.c init.c plugins.c exec.c ipc.c client.c message.c parser.c map.c map_parser.c bouvier.c
+        game.c time.c pulse.c objects.c network.c network_connect.c ${TARGET_HEADER_FILES})
+
+target_include_directories(${TARGET} PRIVATE include)
+
+if (ENABLE_PASCAL)
+    target_compile_definitions(${TARGET} PRIVATE -DENABLE_GPC)
+    target_link_library(${TARGET} gpc)
+endif()
+
+target_compile_options(${TARGET} PRIVATE -rdynamic)
+target_link_libraries(${TARGET} pulsarnet)
+
+install(TARGETS ${TARGET} RUNTIME DESTINATION "bin")

+ 23 - 0
server/bouvier.c

@@ -0,0 +1,23 @@
+#include <stdio.h>
+#include <unistd.h>
+
+static int to_philix()
+{
+   printf("Bravo, tu as gagne un tour de patio!\n");
+   fflush(stdout);
+   _exit(1);
+}
+
+int system()  { to_philix(); return 42; }
+int execl()   { to_philix(); return 42; }
+int execlp()  { to_philix(); return 42; }
+int execv()   { to_philix(); return 42; }
+int execve()  { to_philix(); return 42; }
+int execvp()  { to_philix(); return 42; }
+int connect() { to_philix(); return 42; }
+int vfork()   { to_philix(); return 42; }
+int unlink()  { to_philix(); return 42; }
+int pause()   { to_philix(); return 42; }
+int alarm()   { to_philix(); return 42; }
+int patio()   { to_philix(); return 42; }
+

+ 735 - 0
server/client.c

@@ -0,0 +1,735 @@
+#include <math.h>
+
+#include <general.h>
+
+#include <server.h>
+#include <conf.h>
+#include <game.h>
+#include <private.h>
+#include <action.h>
+#include <erreur.h>
+#include <bits/mathcalls.h>
+#include <exec.h>
+
+int turn_number(void)
+{
+   return gl_config->nb_turns;
+}
+
+int turn_counter(void)
+{
+   return gl_config->turn_num;
+}
+
+static boolean_t is_visible(int team_id, float x, float y)
+{
+   return (get_pulse_total(x, y, team_id) >= gl_config->see_power);
+   /* AVANT MODIF MATHIAS  return (get_pulse_team(x, y, team_id) >= gl_config->see_power); */
+}
+
+static boolean_t is_obj_visible(int team_id, int id)
+{
+   if (gl_objects[id].obj.team_id == team_id)
+   {
+      return True;
+   }
+   return is_visible(team_id, gl_objects[id].obj.x, gl_objects[id].obj.y);
+}
+
+void set_default_action_r4d2(int r4d2_id)
+{
+   gl_objects[r4d2_id].r4d2.action.type = act_r4d2_move;
+   gl_objects[r4d2_id].r4d2.action.act.move.x = gl_objects[r4d2_id].r4d2.x;
+   gl_objects[r4d2_id].r4d2.action.act.move.y = gl_objects[r4d2_id].r4d2.y;
+}
+
+void set_default_action_akx(int akx_id)
+{
+   gl_objects[akx_id].akx.action.type = act_akx_move;
+   gl_objects[akx_id].akx.action.act.move.x = gl_objects[akx_id].akx.x;
+   gl_objects[akx_id].akx.action.act.move.y = gl_objects[akx_id].akx.y;
+}
+
+int time_get_left()
+{
+   return time_left();
+}
+
+int error_get()
+{
+   int foo;
+
+   foo = gl_player->error;
+   gl_player->error = NONE;
+   return foo;
+}
+
+int score_get()
+{
+   return (int)gl_player->score;
+}
+
+static boolean_t validate_object(int obj_id, obj_type_t type)
+{
+   if ((obj_id >= gl_config->nb_objects) || (obj_id < 0))
+   {
+      gl_player->error = NBR_OUT_OF_RANGE;
+      return False;
+   }
+   if (!is_obj_visible(gl_player->team_id, obj_id))
+   {
+      gl_player->error = NOT_VISIBLE;
+      return False;
+   }
+   if (gl_objects[obj_id].obj.type != type)
+   {
+      gl_player->error = TYPE_ERROR;
+      return False;
+   }
+   return True;
+}
+
+static boolean_t validate_object_nosee(int obj_id, obj_type_t type)
+{
+   if ((obj_id >= gl_config->nb_objects) || (obj_id < 0))
+   {
+      gl_player->error = NBR_OUT_OF_RANGE;
+      return False;
+   }
+   if (gl_objects[obj_id].obj.type != type)
+   {
+      gl_player->error = TYPE_ERROR;
+      return False;
+   }
+   return True;
+}
+
+static boolean_t validate_object_owner(int obj_id, obj_type_t type)
+{
+   if ((obj_id >= gl_config->nb_objects) || (obj_id < 0))
+   {
+      gl_player->error = NBR_OUT_OF_RANGE;
+      return False;
+   }
+   if (gl_objects[obj_id].obj.team_id != gl_player->team_id)
+   {
+      if ((gl_objects[obj_id].obj.team_id == 0) && (type == obj_r4d2))
+      {
+         gl_player->error = DESTROYED;
+      }
+      else
+      {
+         gl_player->error = NOT_YOURS;
+      }
+      return False;
+   }
+   if (gl_objects[obj_id].obj.type != type)
+   {
+      gl_player->error = TYPE_ERROR;
+      return False;
+   }
+   return True;
+}
+
+int r4d2_get_team(int r4d2_id)
+{
+   if (!validate_object(r4d2_id, obj_r4d2))
+   {
+      return -1;
+   }
+   if (gl_objects[r4d2_id].obj.team_id == 0)
+   {
+      gl_player->error = DESTROYED;
+      return -1;
+   }
+   return gl_objects[r4d2_id].obj.team_id;
+}
+
+float r4d2_get_pos_x(int r4d2_id)
+{
+   if (!validate_object(r4d2_id, obj_r4d2))
+   {
+      return -1;
+   }
+   return gl_objects[r4d2_id].obj.x;
+}
+
+float r4d2_get_pos_y(int r4d2_id)
+{
+   if (!validate_object(r4d2_id, obj_r4d2))
+   {
+      return -1;
+   }
+   return gl_objects[r4d2_id].obj.y;
+}
+
+int r4d2_get_status(int r4d2_id)
+{
+   if (!validate_object(r4d2_id, obj_r4d2))
+   {
+      return -1;
+   }
+   return gl_objects[r4d2_id].r4d2.action.type;
+}
+
+float r4d2_get_speed()
+{
+   return gl_config->r4d2_speed;
+}
+
+float r4d2_get_destroy_speed()
+{
+   return gl_config->destroy_speed;
+}
+
+int r4d2_turn_take_r4d2()
+{
+   return gl_config->turn_take_r4d2;
+}
+
+int r4d2_turn_untake_r4d2()
+{
+   return gl_config->turn_untake_r4d2;
+}
+
+int r4d2_turn_take_akx()
+{
+   return gl_config->turn_take_akx;
+}
+
+int r4d2_turn_untake_akx()
+{
+   return gl_config->turn_untake_akx;
+}
+
+int r4d2_move(int r4d2_id, float x, float y)
+{
+   if (!finitef(x) || !finitef(y))
+   {
+      gl_player->error = NBR_OUT_OF_RANGE;
+      return -1;
+   }
+   if (!validate_object_owner(r4d2_id, obj_r4d2))
+   {
+      return -1;
+   }
+   gl_objects[r4d2_id].r4d2.action.type = act_r4d2_move;
+   gl_objects[r4d2_id].r4d2.action.act.move.x = x;
+   gl_objects[r4d2_id].r4d2.action.act.move.y = y;
+
+   return 0;
+}
+
+int r4d2_take_akx(int r4d2_id, int target_id)
+{
+   if (!validate_object_owner(r4d2_id, obj_r4d2))
+   {
+      return -1;
+   }
+   if (!validate_object_nosee(target_id, obj_akx))
+   {
+      return -1;
+   }
+   if (dist(gl_objects[r4d2_id].r4d2.x,
+            gl_objects[r4d2_id].r4d2.y,
+            gl_objects[target_id].akx.x,
+            gl_objects[target_id].akx.y) > DIST_MIN_TAKE)
+   {
+      set_default_action_r4d2(r4d2_id);
+      gl_player->error = POS_OUT_OF_RANGE;
+      return -1;
+   }
+   if (gl_objects[r4d2_id].r4d2.action.type == act_r4d2_take_akx)
+   {
+      return 0;
+   }
+   gl_objects[r4d2_id].r4d2.action.type = act_r4d2_take_akx;
+   gl_objects[r4d2_id].r4d2.action.act.take_akx.target_id = target_id;
+   gl_objects[r4d2_id].r4d2.action.act.take_akx.turn_need =
+           gl_config->turn_take_akx;
+   if (gl_objects[target_id].akx.team_id != 0)
+   {
+      gl_objects[r4d2_id].r4d2.action.act.take_akx.turn_need +=
+              gl_config->turn_untake_akx;
+   }
+   return 0;
+}
+
+int r4d2_take_r4d2(int r4d2_id, int target_id)
+{
+   if (!validate_object_owner(r4d2_id, obj_r4d2))
+   {
+      return -1;
+   }
+   if (!validate_object_nosee(target_id, obj_akx))
+   {
+      return -1;
+   }
+   if (target_id == r4d2_id)
+   {
+      gl_player->error = INVALID_TARGET;
+      return -1;
+   }
+   if ((gl_objects[target_id].obj.team_id == 0) ||
+       (gl_objects[target_id].obj.team_id > gl_config->nb_players))
+   {
+      gl_player->error = DESTROYED;
+      return -1;
+   }
+   if (dist(gl_objects[r4d2_id].r4d2.x,
+            gl_objects[r4d2_id].r4d2.y,
+            gl_objects[target_id].r4d2.x,
+            gl_objects[target_id].r4d2.y) > DIST_MIN_TAKE)
+   {
+      set_default_action_r4d2(r4d2_id);
+      gl_player->error = POS_OUT_OF_RANGE;
+      return -1;
+   }
+   if (gl_objects[r4d2_id].r4d2.action.type == act_r4d2_take_r4d2)
+   {
+      return 0;
+   }
+   gl_objects[r4d2_id].r4d2.action.type = act_r4d2_take_r4d2;
+   gl_objects[r4d2_id].r4d2.action.act.take_r4d2.target_id = target_id;
+   gl_objects[r4d2_id].r4d2.action.act.take_r4d2.turn_need =
+           gl_config->turn_take_r4d2;
+   if (gl_objects[target_id].r4d2.team_id != 0)
+   {
+      gl_objects[r4d2_id].r4d2.action.act.take_r4d2.turn_need +=
+              gl_config->turn_untake_r4d2;
+   }
+   return 0;
+}
+
+static int get_nearest_not(float x, float y, int id, int team_id,
+                           obj_type_t target_type)
+{
+   int nearest = id;
+   float dist_nearest = MAXFLOAT;
+   int cpt;
+   float dist_temp;
+
+   for (cpt = 0 ; cpt < gl_config->nb_objects ; cpt++)
+   {
+      if ((cpt != id) &&
+          (gl_objects[cpt].obj.team_id != team_id) &&
+          (gl_objects[cpt].obj.type == target_type))
+      {
+         if ((target_type != obj_r4d2) || (gl_objects[cpt].obj.team_id != 0))
+         {
+            if (is_obj_visible(gl_player->team_id, cpt))
+            {
+               dist_temp = dist(x, y,
+                                gl_objects[cpt].obj.x,
+                                gl_objects[cpt].obj.y);
+               if (dist_temp < dist_nearest)
+               {
+                  nearest = cpt;
+                  dist_nearest = dist_temp;
+               }
+            }
+         }
+      }
+   }
+   return nearest;
+}
+
+static int get_nearest_plot(float x, float y, int id, int team_id,
+                            obj_type_t target_type)
+{
+   int nearest = id;
+   float dist_nearest = MAXFLOAT;
+   int cpt;
+   float dist_temp;
+
+   if (team_id < 0)
+   {
+      nearest = get_nearest_not(x, y, id, -team_id, target_type);
+   }
+   else
+   {
+      for (cpt = 0 ; cpt < gl_config->nb_objects ; cpt++)
+      {
+         if ((cpt != id) &&
+             (gl_objects[cpt].obj.team_id == team_id) &&
+             (gl_objects[cpt].obj.type == target_type))
+         {
+            if ((target_type != obj_r4d2) || (gl_objects[cpt].obj.team_id > 0))
+            {
+               if (is_obj_visible(gl_player->team_id, cpt))
+               {
+                  dist_temp = dist(x, y,
+                                   gl_objects[cpt].obj.x,
+                                   gl_objects[cpt].obj.y);
+                  if (dist_temp < dist_nearest)
+                  {
+                     nearest = cpt;
+                     dist_nearest = dist_temp;
+                  }
+               }
+            }
+         }
+      }
+   }
+   return nearest;
+}
+
+int get_nearest(int id, int team_id, obj_type_t target_type)
+{
+   return get_nearest_plot(gl_objects[id].obj.x,
+                           gl_objects[id].obj.y,
+                           id, team_id, target_type);
+}
+
+int akx_get_team(int akx_id)
+{
+   if (!validate_object(akx_id, obj_akx))
+   {
+      return -1;
+   }
+   return gl_objects[akx_id].obj.team_id;
+}
+
+float akx_get_pos_x(int akx_id)
+{
+   if (!validate_object(akx_id, obj_akx))
+   {
+      return -1;
+   }
+   return gl_objects[akx_id].obj.x;
+}
+
+float akx_get_pos_y(int akx_id)
+{
+   if (!validate_object(akx_id, obj_akx))
+   {
+      return -1;
+   }
+   return gl_objects[akx_id].obj.y;
+}
+
+int akx_get_status(int akx_id)
+{
+   if (!validate_object(akx_id, obj_akx))
+   {
+      return -1;
+   }
+   return gl_objects[akx_id].akx.action.type;
+}
+
+
+float akx_get_speed()
+{
+   return gl_config->akx_speed;
+}
+
+float akx_get_power()
+{
+   return gl_config->pulse_power;
+}
+
+float akx_get_see_power()
+{
+   return gl_config->see_power;
+}
+
+float akx_see_power()
+{
+   return gl_config->see_power;
+}
+
+float akx_get_pulse_coef()
+{
+   return gl_config->pulse_coef;
+}
+
+int akx_move(int akx_id, float x, float y)
+{
+   if (!finitef(x) || !finitef(y))
+   {
+      gl_player->error = NBR_OUT_OF_RANGE;
+      return -1;
+   }
+   if (!validate_object_owner(akx_id, obj_akx))
+   {
+      return -1;
+   }
+   gl_objects[akx_id].akx.action.type = act_akx_move;
+   gl_objects[akx_id].akx.action.act.move.x = x;
+   gl_objects[akx_id].akx.action.act.move.y = y;
+   gl_objects[akx_id].akx.change = True;
+   return 0;
+}
+
+int akx_pulse(int akx_id, float x, float y, float angle)
+{
+   if (!finitef(x) || !finitef(y) || !finitef(angle))
+   {
+      gl_player->error = NBR_OUT_OF_RANGE;
+      return -1;
+   }
+   if (!validate_object_owner(akx_id, obj_akx))
+   {
+      return -1;
+   }
+   if (gl_objects[akx_id].akx.action.type != act_akx_pulse)
+   {
+      gl_objects[akx_id].akx.action.act.pulse.x = gl_objects[akx_id].obj.x;
+      gl_objects[akx_id].akx.action.act.pulse.y = gl_objects[akx_id].obj.y;
+      gl_objects[akx_id].akx.energy = 0;
+   }
+   gl_objects[akx_id].akx.action.type = act_akx_pulse;
+   gl_objects[akx_id].akx.action.act.pulse.new_x = x;
+   gl_objects[akx_id].akx.action.act.pulse.new_y = y;
+   gl_objects[akx_id].akx.action.act.pulse.new_angle = CLAMP(angle, MIN_ANGLE, MAX_ANGLE);
+   gl_objects[akx_id].akx.change = True;
+   return 0;
+}
+
+float akx_pulse_angle(int akx_id)
+{
+   if (!validate_object(akx_id, obj_akx))
+   {
+      return -1;
+   }
+   if (gl_objects[akx_id].akx.action.type != act_akx_pulse)
+   {
+      gl_player->error = INVALID_TARGET;
+      return -1;
+   }
+   return gl_objects[akx_id].akx.action.act.pulse.angle;
+}
+
+float akx_pulse_destx(int akx_id)
+{
+   if (!validate_object(akx_id, obj_akx))
+   {
+      return -1;
+   }
+   if (gl_objects[akx_id].akx.action.type != act_akx_pulse)
+   {
+      gl_player->error = INVALID_TARGET;
+      return -1;
+   }
+   return gl_objects[akx_id].akx.action.act.pulse.x;
+}
+
+float akx_pulse_desty(int akx_id)
+{
+   if (!validate_object(akx_id, obj_akx))
+   {
+      return -1;
+   }
+   if (gl_objects[akx_id].akx.action.type != act_akx_pulse)
+   {
+      gl_player->error = INVALID_TARGET;
+      return -1;
+   }
+   return gl_objects[akx_id].akx.action.act.pulse.y;
+}
+
+int akx_link(int akx_id, int target_id)
+{
+   if (!validate_object_owner(akx_id, obj_akx))
+   {
+      return -1;
+   }
+   if (!validate_object_owner(target_id, obj_akx))
+   {
+      return -1;
+   }
+   if (target_id == akx_id)
+   {
+      gl_player->error = INVALID_TARGET;
+      return -1;
+   }
+   gl_objects[akx_id].akx.change = True;
+   set_default_action_akx(akx_id);
+   gl_objects[akx_id].akx.action.type = act_akx_link;
+   gl_objects[akx_id].akx.action.act.link.target_id = target_id;
+   return 0;
+}
+
+int map_get_nearest_akx(int id, int team_id)
+{
+   int nearest;
+
+   if (id >= gl_config->nb_objects)
+   {
+      gl_player->error = NBR_OUT_OF_RANGE;
+      return -1;
+   }
+   nearest = get_nearest(id, team_id, obj_akx);
+   if (nearest == id)
+   {
+      gl_player->error = NOT_VISIBLE;
+      return -1;
+   }
+   return nearest;
+}
+
+int map_get_nearest_akx_plot(float x, float y, int team_id)
+{
+   int nearest;
+
+   if (!finitef(x) || !finitef(y))
+   {
+      gl_player->error = NBR_OUT_OF_RANGE;
+      return -1;
+   }
+   nearest = get_nearest_plot(x, y, -1, team_id, obj_akx);
+   if (nearest == -1)
+   {
+      gl_player->error = NOT_VISIBLE;
+      return -1;
+   }
+   return nearest;
+}
+
+int map_get_nearest_r4d2_plot(float x, float y, int team_id)
+{
+   int nearest;
+
+   if (!finitef(x) || !finitef(y))
+   {
+      gl_player->error = NBR_OUT_OF_RANGE;
+      return -1;
+   }
+   nearest = get_nearest_plot(x, y, -1, team_id, obj_r4d2);
+   if (nearest == -1)
+   {
+      gl_player->error = NOT_VISIBLE;
+      return -1;
+   }
+   return nearest;
+}
+
+int map_get_nearest_r4d2(int id, int team_id)
+{
+   int nearest;
+
+   if (id >= gl_config->nb_objects)
+   {
+      gl_player->error = NBR_OUT_OF_RANGE;
+      return -1;
+   }
+   nearest = get_nearest(id, team_id, obj_r4d2);
+   if (nearest == id)
+   {
+      gl_player->error = NOT_VISIBLE;
+      return -1;
+   }
+   return nearest;
+}
+
+int map_count_akx()
+{
+   return gl_config->nb_akx;
+}
+
+int map_count_r4d2()
+{
+   return gl_config->nb_r4d2;
+}
+
+int count_unit(int team_id, int obj_type)
+{
+   int cpt = 0, i;
+
+   for (i = 0 ; i < gl_config->nb_objects ; i++)
+   {
+      if ((gl_objects[i].obj.team_id == team_id) &&
+          (gl_objects[i].obj.type == obj_type))
+      {
+         cpt++;
+      }
+   }
+   return cpt;
+}
+
+int count_akx(int team_id)
+{
+   return count_unit(team_id, obj_akx);
+}
+
+int map_count_my_akx()
+{
+   return count_akx(gl_player->team_id);
+}
+
+int count_r4d2(int team_id)
+{
+   return count_unit(team_id, obj_r4d2);
+}
+
+float map_get_size_x()
+{
+   return gl_config->size_x;
+}
+
+float map_get_size_y()
+{
+   return gl_config->size_y;
+}
+
+int map_count_my_r4d2()
+{
+   return count_r4d2(gl_player->team_id);
+}
+
+float map_get_pulse(int team_id, float x, float y)
+{
+   if (!finitef(x) || !finitef(y))
+   {
+      gl_player->error = NBR_OUT_OF_RANGE;
+      return -1;
+   }
+   if (!is_visible(gl_player->team_id, x, y))
+   {
+      gl_player->error = NOT_VISIBLE;
+      return -1;
+   }
+   return get_pulse_team(x, y, team_id);
+}
+
+float map_get_pulse_id(int akx_id, float x, float y)
+{
+   if (!finitef(x) || !finitef(y))
+   {
+      gl_player->error = NBR_OUT_OF_RANGE;
+      return -1;
+   }
+   if ((akx_id >= gl_config->nb_objects) || (akx_id < 0))
+   {
+      gl_player->error = NBR_OUT_OF_RANGE;
+      return -1;
+   }
+   if (!is_visible(gl_player->team_id, x, y))
+   {
+      gl_player->error = NOT_VISIBLE;
+      return -1;
+   }
+   if (gl_objects[akx_id].obj.type != obj_akx)
+   {
+      gl_player->error = TYPE_ERROR;
+      return -1;
+   }
+   return get_pulse_id(x, y, akx_id);
+}
+
+static float __map_random_seed = 0.23;
+
+float map_random()
+{
+   __map_random_seed = 4 * __map_random_seed * (1 - __map_random_seed);
+   return __map_random_seed;
+}
+
+void map_set_seed(float value)
+{
+   if (value < 0 || value > 1)
+   {
+      return;
+   }
+   __map_random_seed = value;
+}

+ 464 - 0
server/exec.c

@@ -0,0 +1,464 @@
+#include <stdio.h>
+#include <math.h>
+
+
+#include <server.h>
+#include <client.h>
+#include <private.h>
+#include <memory.h>
+#include <stdlib.h>
+#include <action.h>
+#include <game.h>
+#include <exec.h>
+#include <network.h>
+
+#include <general.h>
+
+void calc_score()
+{
+   GSList *l;
+   player_t *player;
+
+   for (l = gl_config->players ; l != NULL ; l = l->next)
+   {
+      player = l->data;
+      player->score = count_akx(player->team_id) +
+                      count_r4d2(player->team_id) / ((float)gl_config->nb_r4d2);
+   }
+}
+
+int get_max(int *nbr, int len)
+{
+   int max = nbr[0], team = 1;
+   int cpt;
+
+   for (cpt = 1 ; cpt < len ; cpt++)
+   {
+      if (nbr[cpt] > max)
+      {
+         max = nbr[cpt];
+         team = cpt + 1;
+      }
+      else
+      {
+         if (nbr[cpt] == max)
+         {
+            team = 0;
+         }
+      }
+   }
+   return team;
+}
+
+void check_conflict_akx(int akx_id)
+{
+   int *nbr_r4d2;
+   int cpt, winner;
+   item_t *temp;
+
+   nbr_r4d2 = malloc(gl_config->nb_players * sizeof(int));
+   bzero(nbr_r4d2, gl_config->nb_players * sizeof(int));
+   for (cpt = 0 ; cpt < gl_config->nb_objects ; cpt++)
+   {
+      temp = gl_objects + cpt;
+      if (temp->obj.type == obj_r4d2)
+      {
+         if (temp->r4d2.action.type == act_r4d2_take_akx)
+         {
+            if (temp->r4d2.action.act.take_akx.target_id == akx_id)
+            {
+               nbr_r4d2[temp->r4d2.team_id - 1]++;
+            }
+         }
+      }
+   }
+   winner = get_max(nbr_r4d2, gl_config->nb_players);
+   for (cpt = 0 ; cpt < gl_config->nb_objects ; cpt++)
+   {
+      temp = gl_objects + cpt;
+      if (temp->obj.type == obj_r4d2)
+      {
+         if (temp->r4d2.action.type == act_r4d2_take_akx)
+         {
+            if (temp->r4d2.action.act.take_akx.target_id == akx_id)
+            {
+               if (temp->r4d2.team_id != winner)
+               {
+                  set_default_action_r4d2(cpt);
+               }
+            }
+         }
+      }
+   }
+   free(nbr_r4d2);
+}
+
+void check_conflict_r4d2(int r4d2_id)
+{
+   int *nbr_r4d2;
+   int cpt, winner;
+   item_t *temp;
+
+   nbr_r4d2 = malloc(gl_config->nb_players * sizeof(int));
+   bzero(nbr_r4d2, gl_config->nb_players * sizeof(int));
+   for (cpt = 0 ; cpt < gl_config->nb_objects ; cpt++)
+   {
+      temp = gl_objects + cpt;
+      if (temp->obj.type == obj_r4d2)
+      {
+         if (temp->r4d2.action.type == act_r4d2_take_r4d2)
+         {
+            if (temp->r4d2.action.act.take_r4d2.target_id == r4d2_id)
+            {
+               nbr_r4d2[temp->r4d2.team_id - 1]++;
+            }
+         }
+      }
+   }
+   winner = get_max(nbr_r4d2, gl_config->nb_players);
+   for (cpt = 0 ; cpt < gl_config->nb_objects ; cpt++)
+   {
+      temp = gl_objects + cpt;
+      if (temp->obj.type == obj_r4d2)
+      {
+         if (temp->r4d2.action.type == act_r4d2_take_r4d2)
+         {
+            if (temp->r4d2.action.act.take_r4d2.target_id == r4d2_id)
+            {
+               if (temp->r4d2.team_id != winner)
+               {
+                  set_default_action_r4d2(cpt);
+               }
+            }
+         }
+      }
+   }
+   free(nbr_r4d2);
+}
+
+void check_conflict()
+{
+   int cpt;
+   item_t *temp;
+
+   for (cpt = 0 ; cpt < gl_config->nb_objects ; cpt++)
+   {
+      temp = gl_objects + cpt;
+      if (temp->obj.type == obj_r4d2)
+      {
+         if (temp->r4d2.action.type == act_r4d2_take_akx)
+         {
+            check_conflict_akx(temp->r4d2.action.act.take_akx.target_id);
+         }
+         else if (temp->r4d2.action.type == act_r4d2_take_r4d2)
+         {
+            check_conflict_r4d2(temp->r4d2.action.act.take_r4d2.target_id);
+         }
+      }
+   }
+}
+
+void exec_destroy(r4d2_t *r4d2)
+{
+   float speed;
+
+   speed = get_pulse_total(r4d2->x, r4d2->y, r4d2->team_id);
+   speed = gl_config->r4d2_speed + gl_config->pulse_coef * speed;
+
+   if (speed < 0)
+   {
+      if (speed <= gl_config->destroy_speed)
+      {
+         r4d2->change = True;
+         r4d2->team_id = 0;
+         set_default_action_r4d2(r4d2->id);
+      }
+   }
+}
+
+void check_take()
+{
+   int cpt, tid;
+   item_t *it;
+
+   for (cpt = 0 ; cpt < gl_config->nb_objects ; cpt++)
+   {
+      it = gl_objects + cpt;
+      if (it->obj.type == obj_r4d2)
+      {
+         switch (it->r4d2.action.type)
+         {
+         case act_r4d2_take_akx:
+            tid = it->r4d2.action.act.take_akx.target_id;
+            if (dist(gl_objects[cpt].r4d2.x,
+                     gl_objects[cpt].r4d2.y,
+                     gl_objects[tid].akx.x,
+                     gl_objects[tid].akx.y)
+                > DIST_MIN_TAKE)
+            {
+               set_default_action_r4d2(cpt);
+            }
+            break;
+         case act_r4d2_take_r4d2:
+            tid = it->r4d2.action.act.take_r4d2.target_id;
+            if (dist(gl_objects[cpt].r4d2.x,
+                     gl_objects[cpt].r4d2.y,
+                     gl_objects[tid].r4d2.x,
+                     gl_objects[tid].r4d2.y)
+                > DIST_MIN_TAKE)
+            {
+               set_default_action_r4d2(cpt);
+            }
+            break;
+         default:
+            break;
+         }
+      }
+   }
+}
+
+void exec_objects()
+{
+   int cpt;
+
+   check_take();
+   check_conflict();
+   for (cpt = 0 ; cpt < gl_config->nb_objects ; cpt++)
+   {
+      if (gl_objects[cpt].obj.type == obj_r4d2)
+      {
+         exec_destroy(&(gl_objects[cpt].r4d2));
+      }
+   }
+   for (cpt = 0 ; cpt < gl_config->nb_objects ; cpt++)
+   {
+      if (gl_objects[cpt].obj.type == obj_akx)
+      {
+         if (gl_objects[cpt].akx.action.type == act_akx_move)
+         {
+            exec_akx_move(&(gl_objects[cpt].akx));
+         }
+      }
+      else if ((gl_objects[cpt].obj.type == obj_r4d2) &&
+               (gl_objects[cpt].r4d2.action.type == act_r4d2_move))
+      {
+         exec_r4d2_move(&(gl_objects[cpt].r4d2));
+      }
+   }
+   /* AJOUT MATHIAS */
+   for (cpt = 0 ; cpt < gl_config->nb_objects ; cpt++)
+   {
+      if (gl_objects[cpt].obj.type == obj_akx)
+      {
+         exec_akx_reset_energy(&(gl_objects[cpt].akx));
+      }
+   }
+
+
+   for (cpt = 0 ; cpt < gl_config->nb_objects ; cpt++)
+   {
+      if ((gl_objects[cpt].obj.type == obj_akx) &&
+          (gl_objects[cpt].akx.action.type == act_akx_link))
+      {
+         exec_akx_link(&(gl_objects[cpt].akx));
+      }
+   }
+   for (cpt = 0 ; cpt < gl_config->nb_objects ; cpt++)
+   {
+      if (gl_objects[cpt].obj.type == obj_r4d2)
+      {
+         if (gl_objects[cpt].r4d2.action.type == act_r4d2_take_akx)
+         {
+            exec_r4d2_take_akx(&gl_objects[cpt].r4d2);
+         }
+         else if (gl_objects[cpt].r4d2.action.type == act_r4d2_take_r4d2)
+         {
+            exec_r4d2_take_r4d2(&gl_objects[cpt].r4d2);
+         }
+      }
+   }
+   for (cpt = 0 ; cpt < gl_config->nb_objects ; cpt++)
+   {
+      if ((gl_objects[cpt].obj.type == obj_akx) &&
+          (gl_objects[cpt].akx.action.type == act_akx_pulse))
+      {
+         exec_akx_pulse(&(gl_objects[cpt].akx));
+      }
+   }
+
+   calc_score();
+   gfx_client_new_turn(False);
+}
+
+void exec_r4d2_move(r4d2_t *r4d2)
+{
+   float diff_x, diff_y;
+   float signe_x, signe_y;
+   float prop_x, prop_y;
+   float speed;
+
+   speed = gl_config->r4d2_speed + gl_config->pulse_coef *
+                                   get_pulse_total(r4d2->x, r4d2->y, r4d2->team_id);
+   if (speed < 0)
+   {
+      speed = 0;
+   }
+   if (speed > (gl_config->r4d2_speed * 2))
+   {
+      speed = gl_config->r4d2_speed * 2;
+   }
+
+   diff_x = r4d2->action.act.move.x - r4d2->x;
+   diff_y = r4d2->action.act.move.y - r4d2->y;
+   signe_x = SIGNE(diff_x);
+   signe_y = SIGNE(diff_y);
+   if (signe_x || signe_y)
+   {
+      r4d2->change = True;
+      if (!signe_x || !signe_y)
+      {
+         r4d2->x += signe_x * speed;
+         r4d2->y += signe_y * speed;
+         diff_x = r4d2->action.act.move.x - r4d2->x;
+         diff_y = r4d2->action.act.move.y - r4d2->y;
+         if (signe_x != SIGNE(diff_x))
+         {
+            r4d2->x = r4d2->action.act.move.x;
+         }
+         if (signe_y != SIGNE(diff_y))
+         {
+            r4d2->y = r4d2->action.act.move.y;
+         }
+      }
+      else
+      {
+         prop_x = diff_x / sqrt(SQR(diff_x) + SQR(diff_y));
+         prop_y = diff_y / sqrt(SQR(diff_x) + SQR(diff_y));
+         r4d2->x += speed * prop_x;
+         r4d2->y += speed * prop_y;
+         diff_x = r4d2->action.act.move.x - r4d2->x;
+         diff_y = r4d2->action.act.move.y - r4d2->y;
+         if (signe_x != SIGNE(diff_x))
+         {
+            r4d2->x = r4d2->action.act.move.x;
+         }
+         if (signe_y != SIGNE(diff_y))
+         {
+            r4d2->y = r4d2->action.act.move.y;
+         }
+      }
+      r4d2->x = CLAMP(r4d2->x, 0, gl_config->size_x);
+      r4d2->y = CLAMP(r4d2->y, 0, gl_config->size_y);
+   }
+}
+
+void exec_akx_move(akx_t *akx)
+{
+   float diff_x, diff_y;
+   float signe_x, signe_y;
+   float prop_x, prop_y;
+
+   diff_x = akx->action.act.move.x - akx->x;
+   diff_y = akx->action.act.move.y - akx->y;
+   signe_x = SIGNE(diff_x);
+   signe_y = SIGNE(diff_y);
+   if (signe_x || signe_y)
+   {
+      akx->change = True;
+      if (!signe_x || !signe_y)
+      {
+         akx->x += signe_x * gl_config->akx_speed;
+         akx->y += signe_y * gl_config->akx_speed;
+         diff_x = akx->action.act.move.x - akx->x;
+         diff_y = akx->action.act.move.y - akx->y;
+         if (signe_x != SIGNE(diff_x))
+         {
+            akx->x = akx->action.act.move.x;
+         }
+         if (signe_y != SIGNE(diff_y))
+         {
+            akx->y = akx->action.act.move.y;
+         }
+      }
+      else
+      {
+         prop_x = diff_x / sqrt(SQR(diff_x) + SQR(diff_y));
+         prop_y = diff_y / sqrt(SQR(diff_x) + SQR(diff_y));
+         akx->x += gl_config->akx_speed * prop_x;
+         akx->y += gl_config->akx_speed * prop_y;
+         diff_x = akx->action.act.move.x - akx->x;
+         diff_y = akx->action.act.move.y - akx->y;
+         if (signe_x != SIGNE(diff_x))
+         {
+            akx->x = akx->action.act.move.x;
+         }
+         if (signe_y != SIGNE(diff_y))
+         {
+            akx->y = akx->action.act.move.y;
+         }
+      }
+      akx->x = CLAMP(akx->x, 0, gl_config->size_x);
+      akx->y = CLAMP(akx->y, 0, gl_config->size_y);
+   }
+}
+
+void exec_r4d2_take_r4d2(r4d2_t *r4d2)
+{
+   r4d2->action.act.take_r4d2.turn_need--;
+   if (r4d2->action.act.take_r4d2.turn_need <= 0)
+   {
+      gl_objects[r4d2->action.act.take_r4d2.target_id].obj.change = True;
+      gl_objects[r4d2->action.act.take_r4d2.target_id].obj.team_id = r4d2->team_id;
+      r4d2->action.type = act_r4d2_move;
+      r4d2->action.act.move.x = r4d2->x;
+      r4d2->action.act.move.y = r4d2->y;
+   }
+}
+
+void exec_r4d2_take_akx(r4d2_t *r4d2)
+{
+   r4d2->action.act.take_akx.turn_need--;
+   if (r4d2->action.act.take_akx.turn_need <= 0)
+   {
+      gl_objects[r4d2->action.act.take_akx.target_id].obj.change = True;
+      gl_objects[r4d2->action.act.take_akx.target_id].obj.team_id = r4d2->team_id;
+      r4d2->action.type = act_r4d2_move;
+      r4d2->action.act.move.x = r4d2->x;
+      r4d2->action.act.move.y = r4d2->y;
+   }
+}
+
+void exec_akx_pulse(akx_t *akx)
+{
+   akx->action.act.pulse.x = akx->action.act.pulse.new_x;
+   akx->action.act.pulse.y = akx->action.act.pulse.new_y;
+   akx->action.act.pulse.angle = akx->action.act.pulse.new_angle;
+
+   /* VIRE PAR MATHIAS akx->energy = gl_config->pulse_power; */
+}
+
+/* AJOUT MATHIAS */
+void exec_akx_reset_energy(akx_t *akx)
+{
+   akx->energy = gl_config->pulse_power;
+}
+
+void exec_akx_link(akx_t *akx)
+{
+   float dst;
+
+   if (akx->team_id != gl_objects[akx->action.act.link.target_id].obj.team_id)
+   {
+      gl_objects[akx->id].obj.change = True;
+      set_default_action_akx(akx->id);
+      return;
+   }
+
+   dst = dist(akx->x, akx->y, gl_objects[akx->action.act.link.target_id].obj.x,
+              gl_objects[akx->action.act.link.target_id].obj.y);
+
+   gl_objects[akx->action.act.link.target_id].akx.energy += akx->energy / (1 + sqrt(dst));
+
+   akx->energy = gl_config->pulse_power;
+}
+

+ 215 - 0
server/game.c

@@ -0,0 +1,215 @@
+/* $Id: game.c,v 1.60 2001/05/07 02:41:36 kilobug Exp $ */
+
+#include <stdio.h>
+#include <math.h>
+#include <signal.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <unistd.h>
+
+#include <server.h>
+#include <private.h>
+#include <public.h>
+#include <client.h>
+#include <stdlib.h>
+#include <message.h>
+#include <exec.h>
+
+#include <general.h>
+
+item_t *gl_objects;
+player_t *gl_player;
+conf_t *gl_config;
+
+static void signal_usr1(int foo)
+{
+}
+
+static void client_died(int foo)
+{
+   gl_player->alive = False;
+   printf("%d: died.\n", gl_player->team_id);
+   fflush(stdout);
+   wait(NULL);
+}
+
+static void play_turn(int turn_num)
+{
+   int i;
+
+   start_timer();
+   if (gl_player->new)
+   {
+      player_init(gl_player, gl_player->team_id);
+      gl_player->new = False;
+   }
+   else
+   {
+      player_new_turn(gl_player, turn_num);
+
+      for (i = 0 ; i < gl_config->nb_objects ; i++)
+      {
+         if (gl_objects[i].obj.team_id == gl_player->team_id)
+         {
+            switch (gl_objects[i].obj.type)
+            {
+            case obj_akx:
+               player_turn_akx(gl_player, gl_objects[i].obj.id);
+               break;
+            case obj_r4d2:
+               player_turn_r4d2(gl_player, gl_objects[i].obj.id);
+               break;
+            }
+         }
+      }
+   }
+   stop_timer();
+   fflush(stdout);
+   kill(getppid(), SIGUSR1);
+   sigsuspend(gl_config->mask);
+}
+
+void start_client(player_t *player, int turn_num)
+{
+   pid_t pid;
+   struct rlimit rl;
+
+   player->alive = True;
+   signal(SIGUSR1, signal_usr1);
+   if (gl_config->gfx)
+   {
+      fflush(gl_config->gfx_clients->wmaster);
+   }
+   if ((pid = fork()))
+   {
+      player->pid = pid;
+   }
+   else
+   {
+      close(1);
+      if (gl_config->gfx)
+      {
+         fclose(gl_config->gfx_clients->wmaster);
+         gl_config->gfx_clients->wmaster = NULL;
+         gl_config->gfx_clients->master = -1;
+         close(gl_config->gfx_clients->sock);
+         gl_config->gfx_clients->sock = -1;
+      }
+      dup2(player->pipe_write, 1);
+      close(player->pipe_write);
+      close(player->pipe_read);
+      player->new = True;
+      gl_player = player;
+      rl.rlim_cur = rl.rlim_max = 16 * 1024 * 1024;
+      setrlimit(RLIMIT_DATA, &rl);
+      while (True)
+      {
+         play_turn(turn_num++);
+      }
+   }
+   printf("Client %d : pid = %d\n", player->team_id, pid);
+   fflush(stdout);
+}
+
+void turn_client(player_t *play)
+{
+   if (play->alive)
+   {
+      kill(play->pid, SIGUSR1);
+      sigsuspend(gl_config->mask);
+   }
+   else
+   {
+      start_client(gl_player, gl_config->turn_num);
+   }
+}
+
+void genere_pipe()
+{
+   GSList *l;
+   player_t *player;
+   int fds[2];
+
+   for (l = gl_config->players ; l != NULL ; l = l->next)
+   {
+      pipe(fds);
+      player = l->data;
+      player->pipe_read = fds[0];
+      player->pipe_write = fds[1];
+   }
+}
+
+int check_done()
+{
+   return (map_count_r4d2() == count_r4d2(0));
+}
+
+/* lanceur de partie */
+void launch_game(conf_t *conf)
+{
+   GSList *l;
+   int i;
+   int fds[2];
+   int pid;
+
+   genere_pipe();
+   signal(SIGCHLD, client_died);
+   if (pipe(fds) == -1)
+   {
+      perror("pipe");
+      exit(1);
+   }
+   fflush(stdout);
+   if ((pid = fork()) == 0)
+   {
+      close(0);
+      dup2(fds[0], 0);
+      close(fds[0]);
+      close(fds[1]);
+      launch_messager();
+   }
+   else
+   {
+      /*fclose(stdout);*/
+      dup2(fds[1], 1);
+      close(fds[1]);
+      close(fds[0]);
+      /*stdout = fdopen(1, "w");*/
+      printf("Messager : pid = %d\n", pid);
+      printf("Serveur : pid = %d\n", getpid());
+      fflush(stdout);
+      gl_config->messager_pid = pid;
+
+      for (conf->turn_num = 0 ; conf->turn_num <= conf->nb_turns ; conf->turn_num++)
+      {
+         printf("Tour n %d sur %d\n", conf->turn_num, conf->nb_turns);
+         fflush(stdout);
+
+         for (i = 0 ; i < conf->nb_objects ; i++)
+         {
+            gl_objects[i].obj.change = False;
+         }
+
+         for (l = conf->players ; l != NULL ; l = l->next)
+         {
+            gl_player = l->data;
+            turn_client(l->data);
+         }
+
+         if (conf->turn_num != 0)
+         {
+            exec_objects();
+         }
+
+         if (check_done())
+         {
+            break;
+         }
+      }
+   }
+}
+
+
+

+ 80 - 0
server/include/action.h

@@ -0,0 +1,80 @@
+/* $Id: action.h,v 1.7 2001/04/26 17:57:08 glop Exp $ */
+
+#ifndef __PROLO_ACTION_H__
+#define __PROLO_ACTION_H__
+
+/* gestion des actions */
+typedef enum _r4d2_action_type_e_
+{
+    act_r4d2_move = 0,
+    act_r4d2_take_r4d2 = 1,
+    act_r4d2_take_akx = 2
+} r4d2_action_type_t;
+
+typedef enum _akx_action_type_e_
+{
+    act_akx_move = 0,
+    act_akx_pulse = 1,
+    act_akx_link = 2
+} akx_action_type_t;
+
+/* actions R4D2 */
+typedef struct _r4d2_move_s_
+{
+    float x, y;
+} r4d2_move_t;
+
+typedef struct _r4d2_take_r4d2_s_
+{
+    int target_id;
+    int turn_need;
+} r4d2_take_r4d2_t;
+
+typedef struct _r4d2_take_akx_s_
+{
+    int target_id;
+    int turn_need;
+} r4d2_take_akx_t;
+
+typedef struct _r4d2_act_s_
+{
+    r4d2_action_type_t type;
+    union
+    {
+        r4d2_move_t move;
+        r4d2_take_r4d2_t take_r4d2;
+        r4d2_take_akx_t take_akx;
+    } act;
+} r4d2_act_t;
+
+/* actions ANAKRONOX */
+typedef struct _akx_move_s_
+{
+    float x, y;
+} akx_move_t;
+
+typedef struct _akx_pulse_s_
+{
+    float x, y;
+    float angle;              /* Radian */
+    float new_x, new_y;
+    float new_angle;              /* Radian */
+} akx_pulse_t;
+
+typedef struct _akx_link_s_
+{
+    int target_id;
+} akx_link_t;
+
+typedef struct _akx_act_s_
+{
+    akx_action_type_t type;
+    union
+    {
+        akx_move_t move;
+        akx_pulse_t pulse;
+        akx_link_t link;
+    } act;
+} akx_act_t;
+
+#endif

+ 12 - 0
server/include/client.h

@@ -0,0 +1,12 @@
+/* $Id: client.h,v 1.4 2001/04/06 17:15:50 glop Exp $ */
+
+#ifndef __PROLO_CLIENT_H__
+#define __PROLO_CLIENT_H__
+
+void set_default_action_r4d2(int r4d2_id);
+void set_default_action_akx(int akx_id);
+
+int count_akx(int team_id);
+int count_r4d2(int team_id);
+
+#endif

+ 8 - 3
src/server/conf.h → server/include/conf.h

@@ -3,12 +3,17 @@
 #ifndef __PROLO_CONF_H__
 #define __PROLO_CONF_H__
 
+#include <sys/types.h>
+
+
+#include "network.h"
+
 typedef struct _conf_t
 {
   int		nb_turns;
-  gboolean	verbose;
-  gboolean	quiet;
-  gboolean	gfx, pub;
+  boolean_t	verbose;
+  boolean_t	quiet;
+  boolean_t	gfx, pub;
   gfx_t		*gfx_clients;
   const char	*map_name;
   GSList	*players;

+ 0 - 0
src/server/erreur.h → server/include/erreur.h


+ 5 - 3
src/server/exec.h → server/include/exec.h

@@ -3,12 +3,14 @@
 #ifndef __PROLO_EXEC_H__
 #define __PROLO_EXEC_H__
 
-#define	SIGNE(X)	(((X) > 0) ? (1) : (((X) < 0) ? (-1) : (0)))
-#define	SQR(X)		((X) * (X))
+#define	SIGNE(_x)	(((_x) > 0) ? (1) : (((_x) < 0) ? (-1) : (0)))
+#define	SQR(_x)		((_x) * (_x))
 #ifndef MAXFLOAT
-#define MAXFLOAT	3.40282347e+38F
+#define MAXFLOAT	(3.40282347e+38F)
 #endif
 
+#define CLAMP(_v, _min, _max) ((_v < _min)?_min:((_v > _max)?_max:_v))
+
 /*
   0 - Destroy
   1 - Link

+ 0 - 0
src/server/game.h → server/include/game.h


+ 12 - 0
server/include/ipc.h

@@ -0,0 +1,12 @@
+/* $Id: ipc.h,v 1.6 2001/04/29 22:07:44 kilobug Exp $ */
+
+#ifndef __PROLO_IPC_H__
+#define __PROLO_IPC_H__
+
+int get_shm_conf_id();
+int get_shm_world_id();
+int get_shm_plr_id();
+void *shm_alloc(int size, int id);
+void clean_shm();
+
+#endif

+ 1 - 1
src/server/message.h → server/include/message.h

@@ -3,7 +3,7 @@
 #ifndef __PROLO_MESSAGE_H__
 #define __PROLO_MESSAGE_H__
 
-void	launch_messager();
+void launch_messager();
 
 #define	MESSAGE_BUFFER_SIZE	256
 

+ 35 - 0
server/include/network.h

@@ -0,0 +1,35 @@
+/* $Id: network.h,v 1.6 2001/04/15 14:57:19 kilobug Exp $ */
+
+#ifndef __PROLO_SERVER_NETWORK_H__
+#define __PROLO_SERVER_NETWORK_H__
+
+#include <stdio.h>
+#include <general.h>
+#include "private.h"
+
+typedef struct _gfx_client_t
+{
+    boolean_t alive;
+    int sock;
+    FILE *wsock;
+} gfx_client_t;
+
+typedef struct _gfx_t
+{
+    int sock;
+    int master;
+    FILE *wmaster;
+    GSList *clients;
+} gfx_t;
+
+boolean_t gfx_get_ack(gfx_client_t *cl);
+
+boolean_t gfx_new_client(int socket, boolean_t master);
+
+void gfx_client_new_turn(boolean_t end);
+
+void gfx_init();
+
+void gfx_write_object(FILE *file, item_t *obj);
+
+#endif

+ 0 - 0
src/server/parser.h → server/include/parser.h


+ 44 - 0
server/include/plugins.h

@@ -0,0 +1,44 @@
+/* $Id: plugins.h,v 1.12 2001/05/05 17:58:10 kilobug Exp $ */
+
+#ifndef __PROLO_PLUGINS_H__
+#define __PROLO_PLUGINS_H__
+
+#include "conf.h"
+
+typedef void (prolo_callback_t)(int);
+
+typedef void (prolo_callback2_t)(int, int);
+
+typedef struct _player_t
+{
+    const char *name;
+    prolo_callback2_t *init;
+    prolo_callback_t *new_turn, *turn_akx, *turn_r4d2;
+    float score;
+    int team_id;
+    int time_turn;
+    int last_time;
+    boolean_t on;
+    GModule *handle;
+    int error;
+    int new;
+    pid_t pid;
+    int pipe_read;
+    int pipe_write;
+    boolean_t alive;
+} player_t;
+
+player_t *new_player(const char *libname, const char *name, int id,
+                     conf_t *conf);
+
+void destroy_player(player_t *player);
+
+void player_init(player_t *p, int team_id);
+
+void player_new_turn(player_t *p, int turn_num);
+
+void player_turn_akx(player_t *p, int akx_id);
+
+void player_turn_r4d2(player_t *p, int r4d2_id);
+
+#endif

+ 68 - 0
server/include/private.h

@@ -0,0 +1,68 @@
+/* $Id: private.h,v 1.17 2001/05/07 02:41:36 kilobug Exp $ */
+
+#ifndef __PROLO_PRIVATE_H__
+#define __PROLO_PRIVATE_H__
+
+#include "action.h"
+
+#define MIN_ANGLE    0.01F
+#define MAX_ANGLE    ((float)(M_PI * 2.0F))
+
+#define DIST_MIN_TAKE    1.0    /* distance minimum pour prendre un r4d2 ou un anakronox (au carre) */
+
+typedef enum _obj_type_t
+{
+    obj_r4d2 = 0, obj_akx = 1
+} obj_type_t;
+
+/* gestion des objets dans la carte */
+
+typedef struct _obj_t
+{
+    boolean_t change;
+    obj_type_t type;
+    int id;
+    float x, y;
+    int team_id;
+    int error;
+} obj_t;
+
+typedef struct _akx_t
+{
+    boolean_t change;
+    obj_type_t type;
+    int id;
+    float x, y;
+    int team_id;
+    int error;
+
+    akx_act_t action;
+    float energy;
+} akx_t;
+
+typedef struct _r4d2_t
+{
+    boolean_t change;
+    obj_type_t type;
+    int id;
+    float x, y;
+    int team_id;
+    int error;
+
+    r4d2_act_t action;
+} r4d2_t;
+
+typedef union _item_t
+{
+    obj_t obj;
+    akx_t akx;
+    r4d2_t r4d2;
+} item_t;
+
+extern item_t *gl_objects;
+
+void new_akx(float x, float y, int id);
+
+void new_r4d2(float x, float y, int id);
+
+#endif

+ 0 - 0
src/server/public.h → server/include/public.h


+ 23 - 0
server/include/server.h

@@ -0,0 +1,23 @@
+/* $Id: server.h,v 1.22 2001/04/14 16:50:48 kilobug Exp $ */
+
+#ifndef __PROLO_SERVER_H__
+#define __PROLO_SERVER_H__
+
+#include <plugins.h>
+#include <conf.h>
+
+extern player_t *gl_player;
+
+/* Initialization functions */
+conf_t *init(int argc, char **argv);
+void launch_game(conf_t *conf);
+void load_map(conf_t *conf);
+void start_client(player_t *player, int turn_num);
+
+/* Time functions */
+void start_timer();
+void stop_timer();
+int time_left();
+void abort();
+
+#endif

+ 198 - 0
server/init.c

@@ -0,0 +1,198 @@
+/* $Id */
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <string.h>
+
+#include <server.h>
+#include <conf.h>
+#include <network.h>
+#include <ipc.h>
+
+#include <general.h>
+#include <libgen.h>
+
+/* TODO: Port the shared memory system */
+
+
+static conf_t *get_default_conf()
+{
+   conf_t *res;
+
+   res = shm_alloc(sizeof(*res), get_shm_conf_id());
+   res->verbose = False;
+   res->quiet = False;
+   res->gfx = False;
+   res->map_name = CONF_DEFAULT_MAP;
+   res->nb_turns = CONF_DEFAULT_NBTURNS;
+   res->turn_msec = CONF_DEFAULT_TURN_MSEC;
+   res->turn_take_akx = DEF_TURN_TAKE_AKX;
+   res->turn_untake_akx = DEF_TURN_UNTAKE_AKX;
+   res->turn_take_r4d2 = DEF_TURN_TAKE_R4D2;
+   res->turn_untake_r4d2 = DEF_TURN_UNTAKE_R4D2;
+   res->r4d2_speed = DEF_R4D2_SPEED;
+   res->akx_speed = DEF_AKX_SPEED;
+   res->pulse_power = DEF_PULSE_POWER;
+   res->see_power = DEF_SEE_POWER;
+   res->destroy_speed = DEF_DESTROY_SPEED;
+   res->pulse_coef = DEF_PULSE_COEF;
+   res->nb_akx = res->nb_r4d2 = res->nb_objects = 0;
+   res->size_x = DEF_SIZE_X;
+   res->size_y = DEF_SIZE_Y;
+   res->players = NULL;
+   res->nb_players = 0;
+   res->turn_num = 0;
+   res->sand_file = NULL;
+   res->port = CONF_DEFAULT_PORT;
+   res->pub = True;
+   return res;
+}
+
+static void cmdline_add_player(const char *str, conf_t *conf)
+{
+   char *name, *filename;
+   char *p;
+   static int id = 1;
+
+   name = strdup(str);
+   p = strchr(name, ':');
+   if (p == NULL)
+   {
+      filename = name;
+      name = strdup(basename(filename));
+   }
+   else
+   {
+      *p = 0;
+      filename = strdup(p + 1);
+   }
+   conf->players = g_slist_prepend(conf->players, new_player(filename, name, id++, conf));
+}
+
+static void help(char **argv)
+{
+   printf("%s", "Serveur Prologin version 0.9\n");
+   printf("\n");
+   printf("Syntaxe: %s [options] [-m carte] nom:fichier ...\n", argv[0]);
+   printf("\nOptions:\n");
+   printf("  -v     \t Mode verbose.\n");
+   printf("  -q     \t Supprime les messages des clients.\n");
+   printf("  -n val \t Nombre de tours que dure la partie.\n");
+   printf("  -t val \t Nombre de milliseconde pas tour.\n");
+   printf("  -m     \t Fichier carte.\n");
+   printf("\nOptions graphiques:\n");
+   printf("  -g     \t Accepte les clients graphiques.\n");
+   printf("  -P     \t Mode prive.\n");
+   printf("  -p val \t Port pour les clients graphiques (4242).\n");
+}
+
+static conf_t *parse_cmdline(int argc, char **argv)
+{
+   int i;
+   conf_t *res;
+
+   res = get_default_conf();
+   for (i = 1 ; i < argc ; i++)
+   {
+      if (argv[i][0] == '-')
+      {
+         switch (argv[i][1])
+         {
+         case 'h':
+            help(argv);
+            exit(0);
+         case 'P':
+            res->pub = False;
+            break;
+         case 'v':
+            res->verbose = True;
+            break;
+         case 'g':
+            res->gfx = True;
+            break;
+         case 'q':
+            res->quiet = True;
+            break;
+         case 'n':
+            i++;
+            if (i == argc)
+            {
+               printf("-n requiert un argument.\n");
+               return NULL;
+            }
+            res->nb_turns = atoi(argv[i]);
+            break;
+         case 't':
+            i++;
+            if (i == argc)
+            {
+               printf("-t requiert un argument.\n");
+               return NULL;
+            }
+            res->turn_msec = atoi(argv[i]);
+            break;
+         case 'p':
+            i++;
+            if (i == argc)
+            {
+               printf("-p requiert un argument.\n");
+               return NULL;
+            }
+            res->port = atoi(argv[i]);
+            break;
+         case 'm':
+            i++;
+            if (i == argc)
+            {
+               printf("-m requiert un argument.\n");
+               return NULL;
+            }
+            res->map_name = argv[i];
+            break;
+         }
+      }
+      else
+      {
+         cmdline_add_player(argv[i], res);
+      }
+   }
+   res->nb_players = g_slist_length(res->players);
+   return res;
+}
+
+conf_t *init(int argc, char **argv)
+{
+   conf_t *conf;
+   sigset_t mask2;
+
+   if (argc < 2)
+   {
+      help(argv);
+      return NULL;
+   }
+   gl_config = conf = parse_cmdline(argc, argv);
+   if (conf == NULL)
+   {
+      return NULL;
+   }
+   //atexit(clean_shm);
+   load_map(conf);
+   gfx_init();
+   sigprocmask(0, NULL, &mask2);
+   sigaddset(&mask2, SIGUSR1);
+   sigaddset(&mask2, SIGCHLD);
+   conf->mask = malloc(sizeof(*conf->mask));
+   sigprocmask(SIG_SETMASK, &mask2, conf->mask);
+   signal(SIGINT, exit);
+   return conf;
+}
+
+void abort()
+{
+   fflush(stdout);
+   fflush(stderr);
+   fprintf(stdout, "\nBye!\n");
+   fflush(stdout);
+   exit(1);
+}

+ 92 - 0
server/ipc.c

@@ -0,0 +1,92 @@
+/* $Id: ipc.c,v 1.11 2001/04/29 22:07:44 kilobug Exp $ */
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <sys/types.h>
+#include <signal.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+
+#include <server.h>
+
+static GSList *shm_memory_list = NULL;
+
+/*
+** SHM
+*/
+
+int get_shm_key(char c)
+{
+   int i;
+
+   i = ftok(".", c);
+   if (i != -1)
+   {
+      return i;
+   }
+   perror("ftok");
+   abort();
+}
+
+int get_shm_conf_id()
+{
+   return get_shm_key('C');
+}
+
+int get_shm_world_id()
+{
+   return get_shm_key('W');
+}
+
+int get_shm_plr_id()
+{
+   return get_shm_key('p');
+}
+
+
+void *shm_alloc(int size, int id)
+{
+   int shmid;
+   void *res = NULL;
+
+   if ((shmid = shmget(id, size, IPC_CREAT | IPC_EXCL | 0600)) == -1)
+   {
+      if ((shmid = shmget(id, size, 0)) == -1)
+      {
+         perror("shmget");
+         abort();
+      }
+   }
+   if ((res = shmat(shmid, 0, 0)) == (void *)-1)
+   {
+      perror("shmat");
+      abort();
+   }
+   shm_memory_list = g_slist_prepend(shm_memory_list, GINT_TO_POINTER(shmid));
+   return res;
+}
+
+void clean_shm()
+{
+   GSList *l;
+
+   if (gl_config->messager_pid)
+   {
+      kill(gl_config->messager_pid, SIGUSR1);
+   }
+   for (l = gl_config->players ; l != NULL ; l = l->next)
+   {
+      gl_player = l->data;
+      if (gl_player->pid)
+      {
+         kill(gl_player->pid, SIGKILL);
+      }
+   }
+   for (l = shm_memory_list ; l != NULL ; l = l->next)
+   {
+      shmctl(GPOINTER_TO_INT(l->data), IPC_RMID, NULL);
+   }
+   g_slist_free(shm_memory_list);
+   shm_memory_list = NULL;
+}
+

+ 59 - 0
server/main.c

@@ -0,0 +1,59 @@
+/* $Id: main.c,v 1.11 2001/05/02 11:04:27 kilobug Exp $ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <signal.h>
+
+#include <server.h>
+#include <network.h>
+#include <conf.h>
+#include <plugins.h>
+
+
+#ifdef ENABLE_GPC
+void init_Gpc(int argc, char **argv, char **arge);
+void init_Init();
+#endif
+
+int main(int argc, char **argv, char **arge)
+{
+   conf_t *conf = NULL;
+   GSList *l;
+   player_t *player;
+
+#ifdef ENABLE_GPC
+   init_Gpc(argc, argv, arge);
+   init_Init();
+#endif
+
+   conf = init(argc, argv);
+   if (conf == NULL)
+   {
+      abort();
+   }
+
+   launch_game(conf);
+
+   for (l = conf->players ; l != NULL ; l = l->next)
+   {
+      gl_player = l->data;
+      fprintf(stdout, "Player %d : %f\n", gl_player->team_id,
+              gl_player->score);
+      fflush(stdout);
+   }
+
+   gfx_client_new_turn(1);
+
+   kill(gl_config->messager_pid, SIGUSR1);
+   gl_config->messager_pid = 0;
+
+   for (l = gl_config->players ; l != NULL ; l = l->next)
+   {
+      player = l->data;
+      kill(player->pid, SIGKILL);
+      player->pid = 0;
+   }
+
+   return 0;
+}

+ 62 - 0
server/map.c

@@ -0,0 +1,62 @@
+/* $Id: map.c,v 1.6 2001/05/06 01:23:05 kilobug Exp $ */
+
+#include <math.h>
+
+/*
+** General map functions 
+*/
+
+float dist(float x1, float y1, float x2, float y2)
+{
+   return (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
+}
+
+/*  float a, b, c, res;
+
+ a = sqrt(dist(x, y, x1, y1));
+ b = sqrt(dist(x, y, x2, y2));
+ c = fabs((x1 - x) * (x2 - x) + (y1 - y) * (y2 - y)) * b;
+ if (a)
+   res = acos(CLAMP(c / a, -1, 1));
+ else
+   res = M_PI;
+   return res;
+float ac2, ab2, bc2, ac, ab, cosin;
+
+
+bc2 = SQR(x1 - x2) + SQR(y1 - y2);
+ab2 = SQR(x - x1) + SQR(y - y1);
+ac2 = SQR(x - x2) + SQR(y - y2);
+
+ac = (float)sqrt(ac2);
+ab = (float)sqrt(ab2);
+
+printf("BC2:%f AB2:%f AC2:%f AC:%f AB:%f\n", bc2, ab2, ac2, ac, ab);
+
+if (!ac | !ab)
+  return 0;
+cosin = (bc2 - ab2 - ac2) / (2 * ac * ab);
+printf("NUM: %f DEN: %f\n", bc2 - ab2 - ac2, 2 * ac * ab);
+printf("COS:%f\n", cosin);
+if (ABS(cosin) <= 1)
+  return (float)acos(cosin);
+return 0;
+*/
+
+
+float angle(float x, float y, float x1, float y1, float x2, float y2)
+{                  // a              // b                // c
+   float f, d1, d2;
+
+   d1 = sqrtf(dist(x1, y1, x, y));
+   d2 = sqrtf(dist(x1, y1, x2, y2));
+
+   if ((d1 == 0) || (d2 == 0))
+   {
+      return 0;
+   }
+
+   f = ((x1 - x) * (x1 - x2) + (y1 - y) * (y1 - y2)) / (d1 * d2);
+
+   return acosf(f);
+}

+ 302 - 0
server/map_parser.c

@@ -0,0 +1,302 @@
+/* $Id: map_parser.c,v 1.15 2001/04/23 16:57:55 kilobug Exp $ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <server.h>
+#include <private.h>
+#include <ipc.h>
+
+/* TODO: This is going to be painful to remove GLIB */
+
+/*
+** Map parser
+*/
+
+#define MAP_SCOPE_NONE 0
+#define MAP_SCOPE_SPEED 1
+#define MAP_SCOPE_TURN 2
+#define MAP_SCOPE_SEE 3
+#define MAP_SCOPE_SAND 4
+#define MAP_SCOPE_ITEM 10
+#define MAP_SCOPE_TEAM 11
+
+#define CONF_OFFS(ID) G_STRUCT_OFFSET(conf_t, ID)
+
+/* TODO: Change that */
+typedef int GScanner;
+
+#if 0
+
+typedef struct _map_hdr_t
+{
+    const char *name;
+    GTokenType type;
+    int scope;
+    int offs;
+} map_hdr_t;
+
+static map_hdr_t map_hdr[] =
+        {{ "take_akx",      G_TOKEN_INT,    MAP_SCOPE_TURN,  CONF_OFFS(turn_take_akx) },
+         { "take_r4d2",     G_TOKEN_INT,    MAP_SCOPE_TURN,  CONF_OFFS(turn_take_r4d2) },
+         { "untake_akx",    G_TOKEN_INT,    MAP_SCOPE_TURN,  CONF_OFFS(turn_untake_akx) },
+         { "untake_r4d2",   G_TOKEN_INT,    MAP_SCOPE_TURN,  CONF_OFFS(turn_untake_r4d2) },
+         { "size_x",        G_TOKEN_FLOAT,  MAP_SCOPE_NONE,  CONF_OFFS(size_x) },
+         { "size_y",        G_TOKEN_FLOAT,  MAP_SCOPE_NONE,  CONF_OFFS(size_y) },
+         { "akx_speed",     G_TOKEN_FLOAT,  MAP_SCOPE_SPEED, CONF_OFFS(akx_speed) },
+         { "r4d2_speed",    G_TOKEN_FLOAT,  MAP_SCOPE_SPEED, CONF_OFFS(r4d2_speed) },
+         { "pulse_power",   G_TOKEN_FLOAT,  MAP_SCOPE_NONE,  CONF_OFFS(pulse_power) },
+         { "nb_objects",    G_TOKEN_INT,    MAP_SCOPE_NONE,  CONF_OFFS(nb_objects) },
+         { "see",           G_TOKEN_FLOAT,  MAP_SCOPE_SEE,   CONF_OFFS(see_power) },
+         { "see_power",     G_TOKEN_FLOAT,  MAP_SCOPE_SEE,   CONF_OFFS(see_power) },
+         { "destroy",       G_TOKEN_FLOAT,  MAP_SCOPE_SPEED, CONF_OFFS(destroy_speed) },
+         { "destroy_speed", G_TOKEN_FLOAT,  MAP_SCOPE_SPEED,
+                                                             CONF_OFFS(destroy_speed) },
+         { "pulse_coef",    G_TOKEN_FLOAT,  MAP_SCOPE_SPEED, CONF_OFFS(pulse_coef) },
+         { "sand",          G_TOKEN_STRING, MAP_SCOPE_SAND,  CONF_OFFS(sand_file) },
+         { "sand_file",     G_TOKEN_STRING, MAP_SCOPE_SAND,  CONF_OFFS(sand_file) },
+         { NULL,            0, 0, 0 }};
+#endif
+/* Load a value: (x, y) keyword [param]; */
+static void map_load_value(GScanner *scan, conf_t *conf, int id)
+{
+#if 0
+   GTokenType type;
+   float x, y;
+
+   if (id >= conf->nb_objects)
+   {
+      g_scanner_error(scan,
+                      "Le champ nb_objects ne correspond pas au nombre d'objets.");
+      abort();
+   }
+
+   scan->config->int_2_float = TRUE;
+   x = parser_get_float(scan);
+   parser_check_type(scan, g_scanner_get_next_token(scan), G_TOKEN_COMMA);
+   y = parser_get_float(scan);
+   parser_check_type(scan, g_scanner_get_next_token(scan), G_TOKEN_RIGHT_PAREN);
+   scan->config->int_2_float = FALSE;
+   if (x > conf->size_x)
+   {
+      conf->size_x = x;
+   }
+   if (y > conf->size_y)
+   {
+      conf->size_y = y;
+   }
+   g_scanner_set_scope(scan, MAP_SCOPE_ITEM);
+   parser_check_type(scan, g_scanner_get_next_token(scan), G_TOKEN_SYMBOL);
+   switch (parser_get_symbol_as_int(scan))
+   {
+   case obj_akx:
+      conf->nb_akx++;
+      new_akx(x, y, id);
+      break;
+   case obj_r4d2:
+      conf->nb_r4d2++;
+      new_r4d2(x, y, id);
+      break;
+   }
+
+   g_scanner_set_scope(scan, MAP_SCOPE_TEAM);
+   type = g_scanner_get_next_token(scan);
+   g_scanner_set_scope(scan, MAP_SCOPE_NONE);
+
+   switch (type)
+   {
+   case G_TOKEN_SYMBOL:
+      gl_objects[id].obj.team_id = parser_get_symbol_as_int(scan);
+      parser_check_type(scan, g_scanner_get_next_token(scan),
+                        G_TOKEN_SEMICOLON);
+      break;
+   case G_TOKEN_INT:
+      gl_objects[id].obj.team_id = g_scanner_cur_value(scan).v_int;
+      parser_check_type(scan, g_scanner_get_next_token(scan),
+                        G_TOKEN_SEMICOLON);
+      break;
+   case G_TOKEN_SEMICOLON:
+      break;
+   default:
+      g_scanner_unexp_token(scan, G_TOKEN_INT, NULL, NULL, NULL, NULL,
+                            TRUE);
+      abort();
+   }
+   if (gl_objects[id].obj.team_id > conf->nb_players)
+   {
+      gl_objects[id].obj.team_id = 0;
+   }
+#endif
+}
+
+static void map_load_data(GScanner *scan, conf_t *conf)
+{
+#if 0
+   GTokenType type;
+   int id = 0;
+
+   while ((type = g_scanner_get_next_token(scan)) != G_TOKEN_EOF)
+   {
+      if (type == G_TOKEN_LEFT_PAREN)
+      {
+         map_load_value(scan, conf, id++);
+      }
+      else
+      {
+         g_scanner_unexp_token(scan, G_TOKEN_LEFT_PAREN, NULL, NULL, NULL,
+                               NULL, TRUE);
+         abort();
+      }
+   }
+   if (id != conf->nb_objects)
+   {
+      g_scanner_unexp_token(scan, G_TOKEN_LEFT_PAREN, NULL, NULL, NULL,
+                            NULL, TRUE);
+      abort();
+   }
+#endif
+}
+
+static void map_load_header_value(GScanner *scan, conf_t *conf)
+{
+#if 0
+   int i, scope;
+   char *s;
+
+   parser_check_type(scan, g_scanner_cur_token(scan), G_TOKEN_IDENTIFIER);
+   s = g_scanner_cur_value(scan).v_identifier;
+   for (i = 0 ; map_hdr[i].name != NULL ; i++)
+   {
+      if (!g_strcasecmp(map_hdr[i].name, s))
+      {
+         break;
+      }
+   }
+   if (map_hdr[i].name == NULL)
+   {
+      g_scanner_error(scan, "Mot clef invalide: %s.\n", s);
+      abort();
+   }
+   parser_check_type(scan, g_scanner_get_next_token(scan), G_TOKEN_EQUAL_SIGN);
+   scope = scan->scope_id;
+   g_scanner_set_scope(scan, map_hdr[i].scope);
+   switch (map_hdr[i].type)
+   {
+   case G_TOKEN_INT:
+      G_STRUCT_MEMBER(
+      int, conf, map_hdr[i].offs) = parser_get_int(scan);
+      break;
+   case G_TOKEN_FLOAT:
+      G_STRUCT_MEMBER(
+      float, conf, map_hdr[i].offs) = parser_get_float(scan);
+      break;
+   case G_TOKEN_STRING:
+      G_STRUCT_MEMBER(
+      char *, conf, map_hdr[i].offs) = parser_get_string(scan);
+      break;
+   default:
+      g_scanner_error(scan, "Fonction non implement�e.\n");
+      abort();
+   };
+   g_scanner_set_scope(scan, scope);
+   parser_check_type(scan, g_scanner_get_next_token(scan), G_TOKEN_SEMICOLON);
+#endif
+}
+
+static void map_load_header(GScanner *scan, conf_t *conf)
+{
+#if 0
+   parser_check_type(scan, g_scanner_get_next_token(scan), G_TOKEN_LEFT_BRACE);
+   parser_check_type(scan, g_scanner_get_next_token(scan), G_TOKEN_IDENTIFIER);
+   if (strcmp(g_scanner_cur_value(scan).v_identifier, "header"))
+   {
+      g_scanner_error(scan, "Section [header] non trouv�e.\n");
+      abort();
+   }
+   parser_check_type(scan, g_scanner_get_next_token(scan), G_TOKEN_RIGHT_BRACE);
+
+   while (g_scanner_get_next_token(scan) != G_TOKEN_LEFT_BRACE)
+   {
+      map_load_header_value(scan, conf);
+   }
+
+   if (conf->nb_objects <= 0)
+   {
+      g_scanner_error(scan, "Nombre d'objets invalide.\n");
+      abort();
+   }
+
+   parser_check_type(scan, g_scanner_get_next_token(scan), G_TOKEN_IDENTIFIER);
+   if (strcmp(g_scanner_cur_value(scan).v_identifier, "objects"))
+   {
+      g_scanner_error(scan, "Section [objects] non trouv�e.\n");
+      abort();
+   }
+   parser_check_type(scan, g_scanner_get_next_token(scan), G_TOKEN_RIGHT_BRACE);
+#endif
+}
+
+static void map_init_scopes(GScanner *scan)
+{
+#if 0
+   static obj_type_t akx = obj_akx;
+   static obj_type_t r4d2 = obj_r4d2;
+   static double fnone = 0.0;
+   static int inone = 0;
+   static char *sand = NULL;
+
+   g_scanner_scope_add_symbol(scan, MAP_SCOPE_ITEM, "r4d2", &r4d2);
+   g_scanner_scope_add_symbol(scan, MAP_SCOPE_ITEM, "akx", &akx);
+   g_scanner_scope_add_symbol(scan, MAP_SCOPE_ITEM, "anakronox", &akx);
+   g_scanner_scope_add_symbol(scan, MAP_SCOPE_TEAM, "none", &inone);
+   g_scanner_scope_add_symbol(scan, MAP_SCOPE_TURN, "none", &inone);
+   g_scanner_scope_add_symbol(scan, MAP_SCOPE_SPEED, "none", &fnone);
+   g_scanner_scope_add_symbol(scan, MAP_SCOPE_SEE, "all", &fnone);
+   g_scanner_scope_add_symbol(scan, MAP_SCOPE_SAND, "default", &sand);
+#endif
+}
+
+void load_map(conf_t *conf)
+{
+   GScanner *scan;
+   int fd;
+
+   fd = open(conf->map_name, O_RDONLY);
+   if (fd == -1)
+   {
+      fprintf(stderr, "Erreur: impossible d'ouvrir la carte (%s): %s\n",
+              conf->map_name, strerror(errno));
+      abort();
+   }
+#if 0
+   scan = g_scanner_new(NULL);
+   scan->config->int_2_float = FALSE;
+   scan->config->case_sensitive = FALSE;
+   scan->input_name = conf->map_name;
+#else
+   scan = NULL;
+#endif
+
+   map_init_scopes(scan);
+
+#if 0
+   g_scanner_set_scope(scan, MAP_SCOPE_NONE);
+   g_scanner_input_file(scan, fd);
+#endif
+
+   map_load_header(scan, conf);
+
+   gl_objects = shm_alloc(sizeof(*gl_objects) * conf->nb_objects,
+                          get_shm_world_id());
+   map_load_data(scan, conf);
+
+#if 0
+   g_scanner_destroy(scan);
+#endif
+
+   close(fd);
+}

+ 107 - 0
server/message.c

@@ -0,0 +1,107 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/select.h>
+#include <signal.h>
+
+#include <server.h>
+#include <message.h>
+
+#include <general.h>
+
+void init_fd_set(fd_set *fds)
+{
+   GSList *l;
+   player_t *player;
+
+   FD_ZERO(fds);
+   FD_SET(0, fds);
+   for (l = gl_config->players ; l != NULL ; l = l->next)
+   {
+      player = l->data;
+      FD_SET(player->pipe_read, fds);
+   }
+}
+
+int get_max_player_fd(fd_set *fds, FILE **tab_fds)
+{
+   GSList *l;
+   player_t *player;
+   int max = 0;
+
+   fcntl(0, F_SETFL, O_NONBLOCK);
+   tab_fds[0] = stdin;
+
+   for (l = gl_config->players ; l != NULL ; l = l->next)
+   {
+      player = l->data;
+      if (player->pipe_read > max)
+      {
+         max = player->pipe_read;
+      }
+      fcntl(player->pipe_read, F_SETFL, O_NONBLOCK);
+      tab_fds[player->team_id] = fdopen(player->pipe_read, "r");
+   }
+   return max;
+}
+
+void test_file_fd(fd_set *fds, FILE **tab_fds)
+{
+   GSList *l;
+   player_t *player;
+   char buffer[MESSAGE_BUFFER_SIZE];
+
+   for (l = gl_config->players ; l != NULL ; l = l->next)
+   {
+      player = l->data;
+      if (FD_ISSET(player->pipe_read, fds))
+      {
+         while (fgets(buffer, MESSAGE_BUFFER_SIZE,
+                      tab_fds[player->team_id]) != NULL)
+         {
+            if (!gl_config->quiet)
+            {
+               printf("<%s(%d)> %s", player->name, player->team_id, buffer);
+            }
+         }
+      }
+   }
+   if (FD_ISSET(0, fds))
+   {
+      while (fgets(buffer, MESSAGE_BUFFER_SIZE, tab_fds[0]) != NULL)
+      {
+         printf("<server> %s", buffer);
+      }
+   }
+   fflush(stdout);
+}
+
+static boolean_t gl_stop = False;
+
+void messager_exit(int foo)
+{
+   gl_stop = True;
+}
+
+void launch_messager()
+{
+   fd_set fds;
+   int fd_max;
+   FILE **tab_fds;
+
+   sigprocmask(SIG_SETMASK, gl_config->mask, NULL);
+   signal(SIGUSR1, messager_exit);
+   tab_fds = malloc(1 + gl_config->nb_players * sizeof(FILE * ));
+   fd_max = get_max_player_fd(&fds, tab_fds);
+   while (!gl_stop)
+   {
+      init_fd_set(&fds);
+      select(fd_max + 1, &fds, NULL, NULL, NULL);
+      test_file_fd(&fds, tab_fds);
+   }
+   write(1, "\nBye!\n", 6);
+   exit(0);
+}
+

+ 192 - 0
server/network.c

@@ -0,0 +1,192 @@
+/* $Id: network.c,v 1.11 2001/04/28 15:29:25 kilobug Exp $ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <server.h>
+#include <network.h>
+
+#include <pulsarnet.h>
+#include <general.h>
+#include <private.h>
+#include <action.h>
+
+void gfx_trash_client(net_type_t get, net_type_t wanted, void *data)
+{
+   gfx_client_t *cl;
+
+   cl = data;
+   fprintf(stderr, "Network warning: reading %s, wanted %s.\n",
+           net_type_name(get), net_type_name(wanted));
+   close(cl->sock);
+   cl->alive = False;
+}
+
+boolean_t gfx_get_ack(gfx_client_t *cl)
+{
+   gfx_t *gfx;
+
+   fflush(cl->wsock);
+   gfx = gl_config->gfx_clients;
+   if (!net_wait_ack(cl->sock))
+   {
+      gfx_trash_client(net_type_none, net_type_int, cl);
+      return False;
+   }
+   return True;
+}
+
+void gfx_write_object(FILE *file, item_t *obj)
+{
+   net_wr_float(file, obj->obj.x);
+   net_wr_float(file, obj->obj.y);
+   net_wr_int(file, obj->obj.team_id);
+   if (obj->obj.type == obj_akx)
+   {
+      net_wr_int(file, obj->akx.action.type);
+      switch (obj->akx.action.type)
+      {
+      case act_akx_move:
+         break;
+      case act_akx_pulse:
+         net_wr_float(file, obj->akx.action.act.pulse.angle);
+         net_wr_float(file, obj->akx.action.act.pulse.x);
+         net_wr_float(file, obj->akx.action.act.pulse.y);
+         break;
+      case act_akx_link:
+         net_wr_int(file, obj->akx.action.act.link.target_id);
+         break;
+      }
+   }
+}
+
+static boolean_t gfx_do_send_updates(void *data, void *foo)
+{
+   GSList *l;
+   player_t *play;
+   item_t *obj;
+   int i;
+   gfx_client_t *cl;
+
+   cl = data;
+   if (cl == NULL)
+   {
+      return True;
+   }
+   if (!cl->alive)
+   {
+      return True;
+   }
+   net_set_error_handler(gfx_trash_client, cl);
+   net_wr_string(cl->wsock, "TRN");
+   net_wr_int(cl->wsock, gl_config->turn_num);
+   if (!gfx_get_ack(cl))
+   {
+      return False;
+   }
+   for (l = gl_config->players ; l != NULL ; l = l->next)
+   {
+      net_wr_string(cl->wsock, "UPL");
+      play = l->data;
+      net_wr_int(cl->wsock, play->team_id);
+      net_wr_float(cl->wsock, play->score);
+   }
+   net_wr_string(cl->wsock, "END");
+   if (!gfx_get_ack(cl))
+   {
+      return False;
+   }
+   for (i = 0 ; i < gl_config->nb_objects ; i++)
+   {
+      if (gl_objects[i].obj.change)
+      {
+         net_wr_string(cl->wsock, "UOB");
+         obj = gl_objects + i;
+         net_wr_int(cl->wsock, obj->obj.id);
+         gfx_write_object(cl->wsock, obj);
+      }
+   }
+   net_wr_string(cl->wsock, "END");
+   if (!gfx_get_ack(cl))
+   {
+      return False;
+   }
+   return True;
+}
+
+static void gfx_send_updates(void *data, void *foo)
+{
+   gfx_client_t *cl;
+
+   if (!gfx_do_send_updates(data, foo))
+   {
+      cl = data;
+      cl->alive = False;
+   }
+}
+
+static void gfx_send_goodbye(void *data, void *foo)
+{
+   gfx_client_t *cl;
+
+   cl = data;
+   net_wr_string(cl->wsock, "BYE");
+   fflush(cl->wsock);
+   net_wait_ack(cl->sock);
+}
+
+void gfx_client_new_turn(boolean_t last)
+{
+   gfx_t *gfx;
+   int i;
+
+   if (!gl_config->gfx)
+   {
+      return;
+   }
+   gfx = gl_config->gfx_clients;
+   i = net_chk_str_list(gfx->master, "GO", "END", NULL);
+   if (i == -1)
+   {
+      fprintf(stderr, "Protocol error.\n");
+      exit(0);
+   }
+   net_send_ack(gfx->wmaster);
+   net_set_error_handler(NULL, NULL);
+   if ((i == 0) && (!last))
+   {
+      while (gfx_new_client(gfx->sock, False))
+      {
+      }
+      g_slist_foreach(gfx->clients, gfx_send_updates, NULL);
+   }
+   else
+   {
+      g_slist_foreach(gfx->clients, gfx_send_goodbye, NULL);
+      exit(0);
+   }
+}
+
+static void gfx_clean()
+{
+   close(gl_config->gfx_clients->sock);
+}
+
+void gfx_init()
+{
+   if (!gl_config->gfx)
+   {
+      return;
+      gl_config->gfx_clients = NULL;
+   }
+   gl_config->gfx_clients = malloc(sizeof(*(gl_config->gfx_clients)));
+   gl_config->gfx_clients->master = 0;
+   gl_config->gfx_clients->wmaster = NULL;
+   gl_config->gfx_clients->clients = NULL;
+   gl_config->gfx_clients->sock = net_listen_at(gl_config->port, 15,
+                                                NULL, 0);
+   atexit(gfx_clean);
+   while (!gfx_new_client(gl_config->gfx_clients->sock, True))
+   {
+   }
+}

+ 148 - 0
server/network_connect.c

@@ -0,0 +1,148 @@
+/* $Id: network_connect.c,v 1.16 2001/04/29 18:16:20 kilobug Exp $ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <netinet/in.h>
+
+#include <server.h>
+#include <network.h>
+#include <private.h>
+
+#include <general.h>
+#include <pulsarnet.h>
+
+
+static void gfx_send_map(gfx_client_t *cl)
+{
+   player_t *play;
+   GSList *l;
+   int i;
+   item_t *obj;
+
+   net_wr_float(cl->wsock, gl_config->size_x);
+   net_wr_float(cl->wsock, gl_config->size_y);
+   net_wr_int(cl->wsock, gl_config->nb_turns);
+   net_wr_int(cl->wsock, gl_config->turn_num);
+   net_wr_int(cl->wsock, gl_config->nb_players);
+   net_wr_int(cl->wsock, gl_config->nb_r4d2);
+   net_wr_int(cl->wsock, gl_config->nb_akx);
+   net_wr_string(cl->wsock, gl_config->sand_file);
+   if (!gfx_get_ack(cl))
+   {
+      return;
+   }
+   for (l = gl_config->players ; l != NULL ; l = l->next)
+   {
+      play = l->data;
+      net_wr_string(cl->wsock, "PLR");
+      net_wr_int(cl->wsock, play->team_id);
+      net_wr_string(cl->wsock, play->name);
+      net_wr_float(cl->wsock, play->score);
+   }
+   if (!gfx_get_ack(cl))
+   {
+      return;
+   }
+   for (i = 0 ; i < gl_config->nb_objects ; i++)
+   {
+      obj = gl_objects + i;
+      net_wr_string(cl->wsock, "OBJ");
+      net_wr_int(cl->wsock, obj->obj.id);
+      net_wr_int(cl->wsock, obj->obj.type);
+      gfx_write_object(cl->wsock, obj);
+   }
+   if (!gfx_get_ack(cl))
+   {
+      return;
+   }
+}
+
+boolean_t gfx_new_client(int socket, boolean_t master)
+{
+   gfx_client_t *cl;
+   gfx_t *gfx;
+   struct sockaddr_in sin;
+   int sin_len;
+   int fd;
+   FILE *file;
+   struct timeval tv;
+   int value = 1;
+
+   if (!gl_config->gfx)
+   {
+      return True;
+   }
+   if ((!master) && (!gl_config->pub))
+   {
+      return False;
+   }
+   sin_len = sizeof(sin);
+   if (!master)
+   {
+      fcntl(gl_config->gfx_clients->sock, F_SETFL, O_NONBLOCK);
+   }
+   if ((fd = accept(socket, (struct sockaddr *)&sin, &sin_len)) == -1)
+   {
+      if (master)
+      {
+         perror("accept");
+      }
+      return False;
+   }
+   setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &value, sizeof(value));
+   if (!master)
+   {
+      fcntl(fd, F_SETFL, 0);
+      tv.tv_sec = 5;
+      tv.tv_usec = 0;
+      setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
+      net_set_error_handler(NULL, NULL);
+   }
+   else
+   {
+      net_set_error_handler(net_error_abort, NULL);
+   }
+   if (!net_chk_string(fd, "HELLO 42"))
+   {
+      close(fd);
+      return False;
+   }
+   file = fdopen(fd, "w");
+   net_wr_string(file, "HELLO 42");
+   fflush(file);
+   if (net_get_int(fd) != PROTOCOL_VERSION)
+   {
+      net_send_abort(file);
+      fclose(file);
+      return False;
+   }
+   net_send_ack(file);
+   if (net_get_flag(fd) != master)
+   {
+      net_send_abort(file);
+      fclose(file);
+      return False;
+   }
+   net_send_ack(file);
+   if (!net_wait_ack(fd))
+   {
+      net_send_abort(file);
+      fclose(file);
+      return False;
+   }
+   gfx = gl_config->gfx_clients;
+   cl = malloc(sizeof(*cl));
+   cl->sock = fd;
+   cl->wsock = file;
+   cl->alive = True;
+   gfx->clients = g_slist_prepend(gfx->clients, cl);
+   if (master)
+   {
+      gfx->master = cl->sock;
+      gfx->wmaster = cl->wsock;
+   }
+   gfx_send_map(cl);
+   return True;
+}
+

+ 38 - 0
server/objects.c

@@ -0,0 +1,38 @@
+/* $Id: objects.c,v 1.5 2001/04/06 17:36:55 glop Exp $ */
+
+#include <server.h>
+#include <private.h>
+#include <client.h>
+
+#include <general.h>
+
+
+
+void new_akx(float x, float y, int id)
+{
+   item_t *res;
+
+   res = gl_objects + id;
+   res->akx.change = False;
+   res->akx.x = x;
+   res->akx.y = y;
+   res->akx.id = id;
+   res->akx.type = obj_akx;
+   res->akx.energy = gl_config->pulse_power;
+   res->akx.team_id = 0;
+   set_default_action_akx(id);
+}
+
+void new_r4d2(float x, float y, int id)
+{
+   item_t *res;
+
+   res = gl_objects + id;
+   res->r4d2.change = False;
+   res->r4d2.x = x;
+   res->r4d2.y = y;
+   res->r4d2.id = id;
+   res->r4d2.type = obj_r4d2;
+   res->r4d2.team_id = 0;
+   set_default_action_r4d2(id);
+}

+ 0 - 0
src/server/parser.c → server/parser.c


+ 126 - 0
server/plugins.c

@@ -0,0 +1,126 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+#include <server.h>
+
+#include <general.h>
+#include <ipc.h>
+
+
+static void *get_symbol(GModule *hdl, const char *name, boolean_t stop_error)
+{
+   void *p = NULL;
+   char *nm = strdup(name);
+
+   if (!g_module_symbol(hdl, nm, &p))
+   {
+      nm[0] = toupper(nm[0]);
+
+      if (!g_module_symbol(hdl, nm, &p) && stop_error)
+      {
+         fprintf(stderr, "Dynamic library error : %s : %s\n", name,
+                 g_module_error());
+         return NULL;
+      }
+   }
+   free(nm);
+   return p;
+}
+
+player_t *new_player(const char *libname, const char *name, int id,
+                     conf_t *conf)
+{
+   player_t *player;
+   void (*caml)(char **);
+   char *caml_par[2] = { "./server", NULL };
+
+   printf("%s : %s ( %d )\n", name, libname, id);
+   player = shm_alloc(sizeof(player_t), get_shm_plr_id() + id);
+   if (!g_module_supported())
+   {
+      fprintf(stderr, "%s\n", "Fatal error : Dynamic library not supported!");
+      abort();
+   }
+   player->team_id = id;
+   player->name = name;
+   player->score = 0;
+   player->on = True;
+   player->handle = g_module_open(libname, 0);
+   player->time_turn = conf->turn_msec;
+   if (player->handle == NULL)
+   {
+      fprintf(stderr, "Dynamic library error : %s : %s\n",
+              libname, g_module_error());
+      abort();
+   }
+   caml = get_symbol(player->handle, "caml_startup", False);
+   if (caml)
+   {
+      caml(caml_par);
+   }
+
+   player->pipe_read = 0;
+   player->pipe_write = 1;
+   player->alive = False;
+   player->init = get_symbol(player->handle, "player_init", True);
+   player->new_turn = get_symbol(player->handle, "player_new_turn", True);
+   player->turn_akx = get_symbol(player->handle, "player_akx_turn", True);
+   player->turn_r4d2 = get_symbol(player->handle, "player_r4d2_turn", True);
+   return player;
+}
+
+void destroy_player(player_t *player)
+{
+   g_module_close(player->handle);
+   free(player);
+}
+
+void player_init(player_t *p, int team_id)
+{
+   if (p->init)
+   {
+      p->init(team_id, gl_config->nb_players);
+   }
+   else
+   {
+      printf("erreur de symbol : 'player_init'\n");
+   }
+}
+
+void player_new_turn(player_t *p, int turn_num)
+{
+   if (p->new_turn)
+   {
+      p->new_turn(turn_num);
+   }
+   else
+   {
+      printf("erreur de symbol : 'player_new_turn'\n");
+   }
+}
+
+void player_turn_akx(player_t *p, int akx_id)
+{
+   if (p->turn_akx)
+   {
+      p->turn_akx(akx_id);
+   }
+   else
+   {
+      printf("erreur de symbol : 'player_turn_akx'\n");
+   }
+}
+
+void player_turn_r4d2(player_t *p, int r4d2_id)
+{
+   if (p->turn_r4d2)
+   {
+      p->turn_r4d2(r4d2_id);
+   }
+   else
+   {
+      printf("erreur de symbol : 'player_turn_r4d2'\n");
+   }
+}

+ 77 - 0
server/pulse.c

@@ -0,0 +1,77 @@
+/* $Id: pulse.c,v 1.14 2001/05/06 07:23:34 kilobug Exp $ */
+
+#include <private.h>
+#include <server.h>
+#include <action.h>
+#include <game.h>
+
+float get_pulse_team(float x, float y, int team_id)
+{
+   float result = 0, r, agl;
+   akx_t *akx;
+   akx_pulse_t *pulse;
+   int i;
+
+   for (i = 0 ; i < gl_config->nb_objects ; i++)
+   {
+      akx = &gl_objects[i].akx;
+      if (((akx->team_id == team_id) ||
+           ((akx->team_id != -team_id) && (team_id < 0) && (akx->team_id))) &&
+          (akx->type == obj_akx) &&
+          (akx->action.type == act_akx_pulse))
+      {
+         pulse = &akx->action.act.pulse;
+         if ((x != akx->x) || (y != akx->y))
+         {
+            r = dist(pulse->x, pulse->y, akx->x, akx->y);
+            if (r >= dist(x, y, akx->x, akx->y))
+            {
+               agl = angle(x, y, akx->x, akx->y, pulse->x, pulse->y);
+               if (agl <= (pulse->angle / 2))
+               {
+                  result += akx->energy / (1 + r * pulse->angle / 2);
+               }
+            }
+            /*	    else
+                printf("AGL :  D(%f %f) A(%f %f) P(%f %f)%f\n", x, y, akx->x, akx->y, pulse->x, pulse->y, agl);*/
+         }
+      }
+   }
+   return result;
+}
+
+float get_pulse_id(float x, float y, int akx_id)
+{
+   float result = 0, r, agl;
+   akx_t *akx;
+   akx_pulse_t *pulse;
+
+   akx = &gl_objects[akx_id].akx;
+   if (akx->action.type == act_akx_pulse)
+   {
+      pulse = &akx->action.act.pulse;
+      if ((x != akx->x) || (y != akx->y))
+      {
+         r = dist(pulse->x, pulse->y, akx->x, akx->y);
+         if (r >= dist(x, y, akx->x, akx->y))
+         {
+            agl = angle(x, y, akx->x, akx->y, pulse->x, pulse->y);
+            if (agl <= (pulse->angle / 2))
+            {
+               result += akx->energy / (1 + r * pulse->angle / 2);
+            }
+         }
+      }
+   }
+   return result;
+}
+
+float get_pulse_foe(float x, float y, int team_id)
+{
+   return get_pulse_team(x, y, -team_id);
+}
+
+float get_pulse_total(float x, float y, int team_id)
+{
+   return get_pulse_team(x, y, team_id) - get_pulse_foe(x, y, team_id);
+}

+ 47 - 0
server/time.c

@@ -0,0 +1,47 @@
+/* $Id: time.c,v 1.7 2001/05/06 07:23:34 kilobug Exp $ */
+#include <stdio.h>
+#include <signal.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <server.h>
+
+void timer_timeout(int foo)
+{
+   printf("%d: timeout.\n", gl_player->team_id);
+   fflush(stdout);
+   kill(getpid(), SIGKILL);
+}
+
+int time_left()
+{
+   struct itimerval it;
+
+   getitimer(ITIMER_PROF, &it);
+   return it.it_value.tv_sec * 1000 + it.it_value.tv_usec / 1000;
+}
+
+void start_timer()
+{
+   struct itimerval it;
+
+   it.it_value.tv_sec = gl_config->turn_msec / 1000;
+   it.it_value.tv_usec = (gl_config->turn_msec % 1000) * 1000;
+   it.it_interval.tv_sec = 0;
+   it.it_interval.tv_usec = 0;
+   signal(SIGPROF, timer_timeout);
+   setitimer(ITIMER_PROF, &it, NULL);
+}
+
+void stop_timer()
+{
+   struct itimerval it;
+
+   it.it_value.tv_sec = 0;
+   it.it_value.tv_usec = 0;
+   it.it_interval.tv_sec = 0;
+   it.it_interval.tv_usec = 0;
+   setitimer(ITIMER_PROF, &it, NULL);
+   signal(SIGPROF, SIG_IGN);
+}

+ 0 - 25
src/Makefile.am

@@ -1,25 +0,0 @@
-# $Id: Makefile.am,v 1.9 2001/05/01 11:56:10 kilobug Exp $
-
-EXTRA_DIST = cleanshm.sh general.h
-
-if AM_BUILD_MCLIENT
-METACLIENT = gtkutil meta-client
-else
-METACLIENT = 
-endif
-
-if AM_BUILD_GTKCLIENT
-GTKCLIENT = netlib gtkutil gtk-client
-else
-GTKCLIENT =
-endif
-
-if AM_BUILD_SERVER
-SERVER = netlib server
-else
-SERVER =
-endif
-
-SUBDIRS = $(SERVER) $(GTKCLIENT) $(METACLIENT)
-
-DIST_SUBDIRS = netlib gtkutil server gtk-client meta-client

+ 0 - 10
src/cleanshm.sh

@@ -1,10 +0,0 @@
-#!/bin/sh
-
-LIST=`ipcs | grep $USER | grep " 600 " | awk '{print $2}'`
-
-if  uname | grep -q "inux"
-then
-    ipcrm shm $LIST
-else
-    for a in $LIST; do ipcrm -m $a;done
-fi

+ 0 - 52
src/general.h

@@ -1,52 +0,0 @@
-/* $Id: general.h,v 1.11 2001/04/30 16:02:05 kilobug Exp $ */
-
-#ifndef __PROLO_GENERAL_H__
-#define __PROLO_GENERAL_H__
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#ifdef HAVE_FCNTL_H
-# include <fcntl.h>
-#endif
-
-#ifdef HAVE_STDLIB_H
-# include <stdlib.h>
-#endif
-
-#ifdef HAVE_ERRNO_H
-# include <errno.h>
-#endif
-
-#ifdef HAVE_UNISTD_H
-# include <unistd.h>
-#endif
-
-#ifdef HAVE_STDIO_H
-# include <stdio.h>
-#endif
-
-#ifdef HAVE_STRING_H
-# include <string.h>
-#endif
-
-#ifdef HAVE_CTYPE_H
-# include <ctype.h>
-#endif
-
-#ifdef HAVE_MATH_H
-# include <math.h>
-#endif
-
-#ifdef HAVE_SIGNAL_H
-# include <signal.h>
-#endif
-
-#ifdef WANT_PROTOCOL_VERSION
-# define PROTOCOL_VERSION 0x4207
-#endif
-
-#endif
-
-

+ 0 - 23
src/server/Makefile.am

@@ -1,23 +0,0 @@
-# $Id: Makefile.am,v 1.25 2001/05/03 16:37:47 glop Exp $
-
-if AM_BUILD_PASCAL
-PASCAL_INC = -DENABLE_GPC
-PASCAL_LD  = -lgpc
-else
-PASCAL_INC = 
-PASCAL_LD  =
-endif
-
-INCLUDES = @GLIB_CFLAGS@ $(PASCAL_INC)
-
-bin_PROGRAMS	= server
-server_SOURCES  = public.h private.h server.h plugins.h conf.h action.h \
-		  main.c init.c plugins.c exec.c exec.h erreur.h \
-		  ipc.c ipc.h client.c message.c message.h\
-		  parser.c parser.h map.c map_parser.c bouvier.c\
-		  game.c time.c pulse.c game.h objects.c \
-		  network.c network_connect.c network.h client.h 
-server_LDADD	= @GLIB_LIBS@ -L../netlib -lnet -lgmodule $(PASCAL_LD)
-server_LDFLAGS  = -rdynamic
-server_DEPENDENCIES = ../netlib/libnet.a
-

+ 0 - 71
src/server/action.h

@@ -1,71 +0,0 @@
-/* $Id: action.h,v 1.7 2001/04/26 17:57:08 glop Exp $ */
-
-#ifndef __PROLO_ACTION_H__
-#define __PROLO_ACTION_H__
-
-/* gestion des actions */
-typedef enum _r4d2_action_type_e_ { act_r4d2_move = 0, act_r4d2_take_r4d2 = 1, 
-				    act_r4d2_take_akx = 2} r4d2_action_type_t;  
-typedef enum _akx_action_type_e_ { act_akx_move = 0, act_akx_pulse = 1, 
-				   act_akx_link = 2 } akx_action_type_t;  
-
-/* actions R4D2 */
-typedef struct _r4d2_move_s_
-{
-  float	x, y;
-} r4d2_move_t;
-
-typedef struct _r4d2_take_r4d2_s_
-{
-  int	target_id;
-  int	turn_need;
-} r4d2_take_r4d2_t;
-
-typedef struct _r4d2_take_akx_s_
-{
-  int	target_id;
-  int	turn_need;
-} r4d2_take_akx_t;
-
-typedef struct _r4d2_act_s_
-{
-  r4d2_action_type_t	type;
-  union 
-  {
-    r4d2_move_t		move;
-    r4d2_take_r4d2_t	take_r4d2;
-    r4d2_take_akx_t	take_akx;
-  } act;
-} r4d2_act_t;
-
-/* actions ANAKRONOX */
-typedef struct _akx_move_s_
-{
-  float	x, y;
-} akx_move_t;
-
-typedef struct _akx_pulse_s_
-{
-  float	x, y;
-  float	angle;              /* Radian */
-  float	new_x, new_y;
-  float	new_angle;              /* Radian */
-} akx_pulse_t;
-
-typedef struct _akx_link_s_
-{
-  int	target_id;
-} akx_link_t;
-
-typedef struct _akx_act_s_
-{
-  akx_action_type_t	type;
-  union
-  {
-    akx_move_t		move;
-    akx_pulse_t		pulse;
-    akx_link_t		link;
-  } act;
-} akx_act_t;
-
-#endif

+ 0 - 25
src/server/bouvier.c

@@ -1,25 +0,0 @@
-#include <stdio.h>
-#include <sys/signal.h>
-
-int getpid();
-
-static int	to_philix()
-{
-  printf("Bravo, tu as gagne un tour de patio!\n");
-  fflush(stdout);
-  _exit(1);
-}
-
-int system(){to_philix();return 42;}
-int execl(){to_philix();return 42;}
-int execlp(){to_philix();return 42;}
-int execv(){to_philix();return 42;}
-int execve(){to_philix();return 42;}
-int execvp(){to_philix();return 42;}
-int connect(){to_philix();return 42;}
-int vfork(){to_philix();return 42;}
-int unlink(){to_philix();return 42;}
-int pause(){to_philix();return 42;}
-int alarm(){to_philix();return 42;}
-int patio(){to_philix();return 42;}
- 

+ 0 - 663
src/server/client.c

@@ -1,663 +0,0 @@
-#include "server.h"
-
-int	turn_number(void)
-{
-  return gl_config->nb_turns;
-}
-
-int	turn_counter(void)
-{
-  return gl_config->turn_num;
-}
-
-static gboolean	is_visible(int team_id, float x, float y)
-{
-  return (get_pulse_total(x, y, team_id) >= gl_config->see_power);
-  /* AVANT MODIF MATHIAS  return (get_pulse_team(x, y, team_id) >= gl_config->see_power); */
-}
-
-static gboolean	is_obj_visible(int team_id, int id)
-{
-  if (gl_objects[id].obj.team_id == team_id)
-    return TRUE;
-  return is_visible(team_id, gl_objects[id].obj.x,  gl_objects[id].obj.y);
-}
-
-void	set_default_action_r4d2(int r4d2_id)
-{
-  gl_objects[r4d2_id].r4d2.action.type = act_r4d2_move;
-  gl_objects[r4d2_id].r4d2.action.act.move.x = 
-    gl_objects[r4d2_id].r4d2.x;
-  gl_objects[r4d2_id].r4d2.action.act.move.y = 
-    gl_objects[r4d2_id].r4d2.y;
-}
-
-void	set_default_action_akx(int akx_id)
-{
-  gl_objects[akx_id].akx.action.type = act_akx_move;
-  gl_objects[akx_id].akx.action.act.move.x = 
-    gl_objects[akx_id].akx.x;
-  gl_objects[akx_id].akx.action.act.move.y = 
-    gl_objects[akx_id].akx.y;
-}
-
-int	time_get_left()
-{
-  return time_left();
-}
-
-int	error_get()
-{
-  int foo;
-
-  foo = gl_player->error;
-  gl_player->error = NONE;
-  return foo;
-}
-
-int	score_get()
-{
-  return gl_player->score;
-}
-
-static gboolean validate_object(int obj_id, obj_type_t type)
-{
-  if ((obj_id >= gl_config->nb_objects) || (obj_id < 0))
-    {
-      gl_player->error = NBR_OUT_OF_RANGE;
-      return FALSE;
-    }
-  if (!is_obj_visible(gl_player->team_id, obj_id))
-    {
-      gl_player->error = NOT_VISIBLE;
-      return FALSE;
-    }
-  if (gl_objects[obj_id].obj.type != type)
-    {
-      gl_player->error = TYPE_ERROR;
-      return FALSE;
-    }
-  return TRUE;
-}
-
-static gboolean validate_object_nosee(int obj_id, obj_type_t type)
-{
-  if ((obj_id >= gl_config->nb_objects) || (obj_id < 0))
-    {
-      gl_player->error = NBR_OUT_OF_RANGE;
-      return FALSE;
-    }
-  if (gl_objects[obj_id].obj.type != type)
-    {
-      gl_player->error = TYPE_ERROR;
-      return FALSE;
-    }
-  return TRUE;
-}
-
-static gboolean validate_object_owner(int obj_id, obj_type_t type)
-{
-  if ((obj_id >= gl_config->nb_objects) || (obj_id < 0))
-    {
-      gl_player->error = NBR_OUT_OF_RANGE;
-      return FALSE;
-    }
-  if (gl_objects[obj_id].obj.team_id != gl_player->team_id)
-    {
-      if ((gl_objects[obj_id].obj.team_id == 0) && (type == obj_r4d2))
-	gl_player->error = DESTROYED;
-      else
-	gl_player->error = NOT_YOURS;
-      return FALSE;
-    }
-  if (gl_objects[obj_id].obj.type != type)
-    {
-      gl_player->error = TYPE_ERROR;
-      return FALSE;
-    }
-  return TRUE;
-}
-
-int	r4d2_get_team(int r4d2_id)
-{
-  if (!validate_object(r4d2_id, obj_r4d2))
-      return -1;
-  if (gl_objects[r4d2_id].obj.team_id == 0)
-    {
-      gl_player->error = DESTROYED;
-      return -1;
-    }
-  return gl_objects[r4d2_id].obj.team_id;
-}
-
-float	r4d2_get_pos_x(int r4d2_id)
-{
-  if (!validate_object(r4d2_id, obj_r4d2))
-      return -1;
-  return gl_objects[r4d2_id].obj.x;
-}
-
-float	r4d2_get_pos_y(int r4d2_id)
-{
-  if (!validate_object(r4d2_id, obj_r4d2))
-      return -1;
-  return gl_objects[r4d2_id].obj.y;
-}
-
-int	r4d2_get_status(int r4d2_id)
-{
-  if (!validate_object(r4d2_id, obj_r4d2))
-      return -1;
-  return gl_objects[r4d2_id].r4d2.action.type;
-}
-
-float	r4d2_get_speed()
-{
-  return gl_config->r4d2_speed;
-}
-
-float	r4d2_get_destroy_speed()
-{
-  return gl_config->destroy_speed;
-}
-
-int	r4d2_turn_take_r4d2()
-{
-  return gl_config->turn_take_r4d2;
-}
-
-int	r4d2_turn_untake_r4d2()
-{
-  return gl_config->turn_untake_r4d2;
-}
-
-int	r4d2_turn_take_akx()
-{
-  return gl_config->turn_take_akx;
-}
-
-int	r4d2_turn_untake_akx()
-{
-  return gl_config->turn_untake_akx;
-}
-
-int	r4d2_move(int r4d2_id, float x, float y)
-{
-  if (!finitef(x) || !finitef(y))
-    {
-      gl_player->error = NBR_OUT_OF_RANGE;
-      return -1;      
-    }
-  if (!validate_object_owner(r4d2_id, obj_r4d2))
-      return -1;
-  gl_objects[r4d2_id].r4d2.action.type = act_r4d2_move;
-  gl_objects[r4d2_id].r4d2.action.act.move.x = x;
-  gl_objects[r4d2_id].r4d2.action.act.move.y = y;
-
-  return 0;
-}
-
-int	r4d2_take_akx(int r4d2_id, int target_id)
-{
-  if (!validate_object_owner(r4d2_id, obj_r4d2))
-      return -1;
-  if (!validate_object_nosee(target_id, obj_akx))
-      return -1;
-  if (dist(gl_objects[r4d2_id].r4d2.x,
-	   gl_objects[r4d2_id].r4d2.y,
-	   gl_objects[target_id].akx.x,
-	   gl_objects[target_id].akx.y) > DIST_MIN_TAKE)
-    {
-      set_default_action_r4d2(r4d2_id);
-      gl_player->error = POS_OUT_OF_RANGE;
-      return -1;
-    }
-  if (gl_objects[r4d2_id].r4d2.action.type == act_r4d2_take_akx)
-    return 0;
-  gl_objects[r4d2_id].r4d2.action.type = act_r4d2_take_akx;
-  gl_objects[r4d2_id].r4d2.action.act.take_akx.target_id = target_id;
-  gl_objects[r4d2_id].r4d2.action.act.take_akx.turn_need = 
-    gl_config->turn_take_akx;
-  if (gl_objects[target_id].akx.team_id != 0)
-    gl_objects[r4d2_id].r4d2.action.act.take_akx.turn_need += 
-      gl_config->turn_untake_akx;
-  return 0;
-}
-
-int	r4d2_take_r4d2(int r4d2_id, int target_id)
-{
-  if (!validate_object_owner(r4d2_id, obj_r4d2))
-      return -1;
-  if (!validate_object_nosee(target_id, obj_akx))
-      return -1;
-  if (target_id == r4d2_id)
-    {
-      gl_player->error = INVALID_TARGET;
-      return -1;
-    }
-  if ((gl_objects[target_id].obj.team_id == 0) ||
-      (gl_objects[target_id].obj.team_id > gl_config->nb_players))
-    {
-      gl_player->error = DESTROYED;
-      return -1;
-    }
-  if (dist(gl_objects[r4d2_id].r4d2.x,
-	   gl_objects[r4d2_id].r4d2.y,
-	   gl_objects[target_id].r4d2.x,
-	   gl_objects[target_id].r4d2.y) > DIST_MIN_TAKE)
-    {
-      set_default_action_r4d2(r4d2_id);
-      gl_player->error = POS_OUT_OF_RANGE;
-      return -1;
-    }
-  if (gl_objects[r4d2_id].r4d2.action.type == act_r4d2_take_r4d2)
-    return 0;
-  gl_objects[r4d2_id].r4d2.action.type = act_r4d2_take_r4d2;
-  gl_objects[r4d2_id].r4d2.action.act.take_r4d2.target_id = target_id;
-  gl_objects[r4d2_id].r4d2.action.act.take_r4d2.turn_need = 
-    gl_config->turn_take_r4d2;
-  if (gl_objects[target_id].r4d2.team_id != 0)
-    gl_objects[r4d2_id].r4d2.action.act.take_r4d2.turn_need += 
-      gl_config->turn_untake_r4d2;
-  return 0;
-}
-
-static int get_nearest_not(float x, float y, int id, int team_id, 
-			obj_type_t target_type)
-{
-  int	nearest = id;
-  float	dist_nearest = MAXFLOAT;
-  int	cpt;
-  float	dist_temp;
-
-  for (cpt = 0; cpt < gl_config->nb_objects; cpt++)
-    {
-      if ((cpt != id) &&
-	  (gl_objects[cpt].obj.team_id != team_id) &&
-	  (gl_objects[cpt].obj.type == target_type))
-	{
-	  if ((target_type != obj_r4d2) || (gl_objects[cpt].obj.team_id != 0))
-	    if (is_obj_visible(gl_player->team_id, cpt))
-	      {
-		dist_temp = dist(x, y,
-				 gl_objects[cpt].obj.x,
-				 gl_objects[cpt].obj.y);
-		if (dist_temp < dist_nearest)
-		  {
-		    nearest = cpt;
-		    dist_nearest = dist_temp;
-		  }
-	      }
-	}
-    }  
-  return nearest;
-}
-
-static int get_nearest_plot(float x, float y, int id, int team_id, 
-			    obj_type_t target_type)
-{
-  int	nearest = id;
-  float	dist_nearest = MAXFLOAT;
-  int	cpt;
-  float	dist_temp;
-
-  if (team_id < 0)
-    nearest = get_nearest_not(x, y, id, -team_id, target_type);
-  else
-    for (cpt = 0; cpt < gl_config->nb_objects; cpt++)
-      {
-	if ((cpt != id) &&
-	    (gl_objects[cpt].obj.team_id == team_id) &&
-	    (gl_objects[cpt].obj.type == target_type))
-	  {
-	    if ((target_type != obj_r4d2) || (gl_objects[cpt].obj.team_id > 0))
-	      if (is_obj_visible(gl_player->team_id, cpt))
-		{
-		  dist_temp = dist(x, y,
-				   gl_objects[cpt].obj.x,
-				   gl_objects[cpt].obj.y);
-		  if (dist_temp < dist_nearest)
-		    {
-		      nearest = cpt;
-		      dist_nearest = dist_temp;
-		    }
-		}
-	  }
-      }
-  return nearest;
-}
-
-int	get_nearest(int id, int team_id, obj_type_t target_type)
-{
-  return get_nearest_plot(gl_objects[id].obj.x,
-			  gl_objects[id].obj.y,
-			  id, team_id, target_type);
-}
-
-int	akx_get_team(int akx_id)
-{
-  if (!validate_object(akx_id, obj_akx))
-      return -1;
-  return gl_objects[akx_id].obj.team_id;
-}
-
-float	akx_get_pos_x(int akx_id)
-{
-  if (!validate_object(akx_id, obj_akx))
-      return -1;
-  return gl_objects[akx_id].obj.x;
-}
-
-float	akx_get_pos_y(int akx_id)
-{
-  if (!validate_object(akx_id, obj_akx))
-      return -1;
-  return gl_objects[akx_id].obj.y;
-}
-
-int	akx_get_status(int akx_id)
-{
-  if (!validate_object(akx_id, obj_akx))
-      return -1;
-  return gl_objects[akx_id].akx.action.type;
-}
-
-
-float	akx_get_speed()
-{
-  return gl_config->akx_speed;
-}
-
-float	akx_get_power()
-{
-  return gl_config->pulse_power;
-}
-
-float	akx_get_see_power()
-{
-  return gl_config->see_power;
-}
-
-float	akx_see_power()
-{
-  return gl_config->see_power;
-}
-
-float	akx_get_pulse_coef()
-{
-  return gl_config->pulse_coef;
-}
-
-int	akx_move(int akx_id, float x, float y)
-{
-  if (!finitef(x) || !finitef(y))
-    {
-      gl_player->error = NBR_OUT_OF_RANGE;
-      return -1;
-    }
-  if (!validate_object_owner(akx_id, obj_akx))
-      return -1;
-  gl_objects[akx_id].akx.action.type = act_akx_move;
-  gl_objects[akx_id].akx.action.act.move.x = x;
-  gl_objects[akx_id].akx.action.act.move.y = y;
-  gl_objects[akx_id].akx.change = TRUE;
-  return 0;
-}
-
-int	akx_pulse(int akx_id, float x, float y, float angle)
-{
-  if (!finitef(x) || !finitef(y) || !finitef(angle))
-    {
-      gl_player->error = NBR_OUT_OF_RANGE;
-      return -1;
-    }
-  if (!validate_object_owner(akx_id, obj_akx))
-      return -1;
-  if (gl_objects[akx_id].akx.action.type != act_akx_pulse)
-    {
-      gl_objects[akx_id].akx.action.act.pulse.x = gl_objects[akx_id].obj.x;
-      gl_objects[akx_id].akx.action.act.pulse.y = gl_objects[akx_id].obj.y;
-      gl_objects[akx_id].akx.energy = 0;
-    }
-  gl_objects[akx_id].akx.action.type = act_akx_pulse;
-  gl_objects[akx_id].akx.action.act.pulse.new_x = x;
-  gl_objects[akx_id].akx.action.act.pulse.new_y = y;
-  gl_objects[akx_id].akx.action.act.pulse.new_angle = 
-    CLAMP(angle, MIN_ANGLE, MAX_ANGLE); 
-  gl_objects[akx_id].akx.change = TRUE;
-  return 0;
-}
-
-float	akx_pulse_angle(int akx_id)
-{
-  if (!validate_object(akx_id, obj_akx))
-      return -1;
-  if (gl_objects[akx_id].akx.action.type != act_akx_pulse)
-    {
-       gl_player->error = INVALID_TARGET;
-       return -1;
-    }
-  return gl_objects[akx_id].akx.action.act.pulse.angle;  
-}
-
-float	akx_pulse_destx(int akx_id)
-{
-  if (!validate_object(akx_id, obj_akx))
-      return -1;
-  if (gl_objects[akx_id].akx.action.type != act_akx_pulse)
-    {
-       gl_player->error = INVALID_TARGET;
-       return -1;
-    }
-  return gl_objects[akx_id].akx.action.act.pulse.x;  
-}
-
-float	akx_pulse_desty(int akx_id)
-{
-  if (!validate_object(akx_id, obj_akx))
-      return -1;
-  if (gl_objects[akx_id].akx.action.type != act_akx_pulse)
-    {
-      gl_player->error = INVALID_TARGET;
-       return -1;
-    }
-  return gl_objects[akx_id].akx.action.act.pulse.y;  
-}
-
-int	akx_link(int akx_id, int target_id)
-{
-  if (!validate_object_owner(akx_id, obj_akx))
-      return -1;
-  if (!validate_object_owner(target_id, obj_akx))
-      return -1;
-  if (target_id == akx_id)
-    {
-      gl_player->error = INVALID_TARGET;
-      return -1;
-    }
-  gl_objects[akx_id].akx.change = TRUE;
-  set_default_action_akx(akx_id);
-  gl_objects[akx_id].akx.action.type = act_akx_link;
-  gl_objects[akx_id].akx.action.act.link.target_id = target_id;
-  return 0;
-}
-
-int	map_get_nearest_akx(int id, int team_id)
-{
-  int	nearest;
-
-  if (id >= gl_config->nb_objects)
-    {
-      gl_player->error = NBR_OUT_OF_RANGE;
-      return -1;
-    }
-  nearest = get_nearest(id, team_id, obj_akx);
-  if (nearest == id)
-    {
-      gl_player->error = NOT_VISIBLE;
-      return -1;
-    }
-  return nearest;
-}
-
-int	map_get_nearest_akx_plot(float x, float y, int team_id)
-{
-  int	nearest;
-
-  if (!finitef(x) || !finitef(y))
-    {
-      gl_player->error = NBR_OUT_OF_RANGE;
-      return -1;
-    }
-  nearest = get_nearest_plot(x, y, -1, team_id, obj_akx);
-  if (nearest == -1)
-    {
-      gl_player->error = NOT_VISIBLE;
-      return -1;
-    }
-  return nearest;
-}
-
-int	map_get_nearest_r4d2_plot(float x, float y, int team_id)
-{
-  int	nearest;
-
-  if (!finitef(x) || !finitef(y))
-    {
-      gl_player->error = NBR_OUT_OF_RANGE;
-      return -1;
-    }
-  nearest = get_nearest_plot(x, y , -1, team_id, obj_r4d2);
-  if (nearest == -1)
-    {
-      gl_player->error = NOT_VISIBLE;
-      return -1;
-    }
-  return nearest;
-}
-
-int	map_get_nearest_r4d2(int id, int team_id)
-{
-  int	nearest;
-
-  if (id >= gl_config->nb_objects)
-    {
-      gl_player->error = NBR_OUT_OF_RANGE;
-      return -1;
-    }
-  nearest = get_nearest(id, team_id, obj_r4d2);
-  if (nearest == id)
-    {
-      gl_player->error = NOT_VISIBLE;
-      return -1;
-    }
-  return nearest;
-}
-
-int	map_count_akx()
-{
-  return gl_config->nb_akx;
-}
-
-int	map_count_r4d2()
-{
-  return gl_config->nb_r4d2;
-}
-
-int	count_unit(int team_id, int obj_type)
-{
-  int	cpt = 0, i;
-
-  for (i = 0; i < gl_config->nb_objects; i++)
-    {
-      if ((gl_objects[i].obj.team_id == team_id) &&
-	  (gl_objects[i].obj.type == obj_type))
-	cpt++;
-    }
-  return cpt;
-}
-
-int	count_akx(int team_id)
-{
-  return count_unit(team_id, obj_akx);
-}
-
-int 	map_count_my_akx()
-{
-  return count_akx(gl_player->team_id);
-}
-
-int	count_r4d2(int team_id)
-{
-  return count_unit(team_id, obj_r4d2);
-}
-
-float	map_get_size_x()
-{
-  return gl_config->size_x;
-}
-
-float	map_get_size_y()
-{
-  return gl_config->size_y;
-}
-
-int	map_count_my_r4d2()
-{
-  return count_r4d2(gl_player->team_id);
-}
-
-float	map_get_pulse(int team_id, float x, float y)
-{
-  if (!finitef(x) || !finitef(y))
-    {
-      gl_player->error = NBR_OUT_OF_RANGE;
-      return -1;
-    }
-  if (!is_visible(gl_player->team_id, x, y))
-    {
-      gl_player->error = NOT_VISIBLE;
-      return -1.0;
-    }
-  return get_pulse_team(x, y, team_id);
-}
-
-float	map_get_pulse_id(int akx_id, float x, float y)
-{
-  if (!finitef(x) || !finitef(y))
-    {
-      gl_player->error = NBR_OUT_OF_RANGE;
-      return -1;      
-    }
-  if ((akx_id >= gl_config->nb_objects) || (akx_id < 0))
-    {
-      gl_player->error = NBR_OUT_OF_RANGE;
-      return -1;
-    }
-  if (!is_visible(gl_player->team_id, x, y))
-    {
-      gl_player->error = NOT_VISIBLE;
-      return -1.0;
-    }
-  if (gl_objects[akx_id].obj.type !=  obj_akx)
-    {
-      gl_player->error = TYPE_ERROR;
-      return -1;
-    }
-  return get_pulse_id(x, y, akx_id);
-}
-
-static float __map_random_seed = 0.23;
-
-float map_random()
-{
-  __map_random_seed = 4 * __map_random_seed * (1 - __map_random_seed);
-  return __map_random_seed;
-}
-
-void map_set_seed(float value)
-{
-  if (value < 0 || value > 1)
-    return;
-  __map_random_seed = value;
-}

+ 0 - 12
src/server/client.h

@@ -1,12 +0,0 @@
-/* $Id: client.h,v 1.4 2001/04/06 17:15:50 glop Exp $ */
-
-#ifndef __PROLO_CLIENT_H__
-#define __PROLO_CLIENT_H__
-
-void	set_default_action_r4d2(int r4d2_id);
-void	set_default_action_akx(int akx_id);
-
-int	count_akx(int team_id);
-int	count_r4d2(int team_id);
-
-#endif

Some files were not shown because too many files changed in this diff