summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile1
-rw-r--r--config.h2
-rw-r--r--include/modules.h6
-rw-r--r--include/proto.h8
-rw-r--r--include/screen_setting.h1
-rw-r--r--include/tux.h2
-rw-r--r--include/widget_select.h26
-rwxr-xr-xmodules/Makefile4
-rwxr-xr-xmodules/modAI.c256
-rwxr-xr-xsrc/Makefile5
-rw-r--r--src/client.c5
-rw-r--r--src/item.c140
-rwxr-xr-xsrc/modules.c3
-rw-r--r--src/proto.c192
-rw-r--r--src/screen_setting.c56
-rw-r--r--src/screen_world.c9
-rw-r--r--src/server.c2
-rw-r--r--src/tux.c23
-rw-r--r--src/widget_select.c99
19 files changed, 555 insertions, 285 deletions
diff --git a/Makefile b/Makefile
index 62237a1..1397e3c 100644
--- a/Makefile
+++ b/Makefile
@@ -54,6 +54,7 @@ mod:
make -C ./modules -f Makefile modTeleport
make -C ./modules -f Makefile modPipe
make -C ./modules -f Makefile modWall
+ make -C ./modules -f Makefile modAI
servermod:
make -C ./modules -f Makefile-publicserver modTeleport
diff --git a/config.h b/config.h
index 0c383a1..1572911 100644
--- a/config.h
+++ b/config.h
@@ -6,7 +6,7 @@
#define DEBUG_CLIENT_RECV
*/
-#define TUXANCI_NG_VERSION "svn67"
+#define TUXANCI_NG_VERSION "svn68"
#define DESTDIR "/usr/local/"
#define SUPPORT_NET_SDL_UDP
diff --git a/include/modules.h b/include/modules.h
index 085e476..0b31292 100644
--- a/include/modules.h
+++ b/include/modules.h
@@ -7,6 +7,7 @@
#include "shot.h"
#include "arena.h"
#include "proto.h"
+#include "myTimer.h"
#ifndef PUBLIC_SERVER
#include "image.h"
@@ -29,7 +30,8 @@ typedef struct export_fce_s
void (*fce_getTuxProportion)(tux_t *tux, int *x,int *y, int *w, int *h);
void (*fce_setTuxProportion)(tux_t *tux, int x, int y);
tux_t* (*fce_getTuxID)(list_t *listTux, int id);
-
+ void (*fce_actionTux)(tux_t *tux, int action);
+
arena_t* (*fce_getCurrentArena)();
int (*fce_conflictSpace)(int x1,int y1,int w1,int h1,int x2,int y2,int w2,int h2);
int (*fce_isFreeSpace)(arena_t *arena, int x, int y, int w, int h);
@@ -37,6 +39,8 @@ typedef struct export_fce_s
void (*fce_proto_send_newtux_server)(int type, client_t *client, tux_t *tux);
void (*fce_proto_send_shot_server)(int type, client_t *client, shot_t *p);
+ my_time_t (*fce_getMyTime)();
+
void (*fce_destroyShot)(shot_t *p);
void (*fce_boundBombBall)(shot_t *shot);
void (*fce_transformOnlyLasser)(shot_t *shot);
diff --git a/include/proto.h b/include/proto.h
index 569339e..178b387 100644
--- a/include/proto.h
+++ b/include/proto.h
@@ -70,15 +70,11 @@ extern void proto_send_kill_server(int type, client_t *client, tux_t *tux);
extern void proto_recv_kill_client(char *msg);
extern void proto_send_score_server(int type, client_t *client, tux_t *tux);
extern void proto_recv_score_client(char *msg);
-extern void proto_send_deltux_server(int type, client_t *client, client_t *client2);
-extern void proto_recv_deltux_client(char *msg);
+extern void proto_send_del_server(int type, client_t *client, int id);
+extern void proto_recv_del_client(char *msg);
extern void proto_send_additem_server(int type, client_t *client, item_t *p);
extern void proto_recv_additem_client(char *msg);
-extern void proto_send_item_server(int type, client_t *client, tux_t *tux, item_t *item);
-extern void proto_recv_item_client(char *msg);
extern void proto_send_shot_server(int type, client_t *client, shot_t *p);
-extern void proto_send_delshot_server(int type, client_t *client, shot_t *p);
-extern void proto_recv_delshot_client(char *msg);
extern void proto_recv_shot_client(char *msg);
extern void proto_send_ping_client();
extern void proto_recv_ping_server(client_t *client, char *msg);
diff --git a/include/screen_setting.h b/include/screen_setting.h
index 88f2289..1684c0d 100644
--- a/include/screen_setting.h
+++ b/include/screen_setting.h
@@ -9,6 +9,7 @@ extern void eventScreenSetting();
extern void getSettingNameRight(char *s);
extern void getSettingNameLeft(char *s);
extern void getSettingCountRound(int *n);
+extern char* getSettingAI();
extern bool_t isSettingAnyItem();
extern bool_t isSettingItem(int item);
extern void quitScreenSetting();
diff --git a/include/tux.h b/include/tux.h
index f247f02..25299a2 100644
--- a/include/tux.h
+++ b/include/tux.h
@@ -30,7 +30,7 @@
#define TUX_CONTROL_KEYBOARD_LEFT 1
#define TUX_CONTROL_KEYBOARD_RIGHT 2
#define TUX_CONTROL_NET 3
-#define TUX_CONTROL_ROBOT 4
+#define TUX_CONTROL_AI 4
#define TUX_WIDTH 30
#define TUX_HEIGHT 30
diff --git a/include/widget_select.h b/include/widget_select.h
new file mode 100644
index 0000000..81255a9
--- /dev/null
+++ b/include/widget_select.h
@@ -0,0 +1,26 @@
+
+#ifndef WIDGET_SELECT_H
+
+#define WIDGET_SELECT_H
+
+#include "main.h"
+#include "list.h"
+
+
+typedef struct widget_select
+{
+ int x, y;
+ int w, h;
+ list_t *list;
+ int select;
+ void (*fce_event)(void *);
+} widget_select_t;
+
+extern widget_select_t* newWidgetSelect(int x, int y, void (*fce_event)(void *));
+extern void addToWidgetSelect(widget_select_t *p, char *s);
+extern void drawWidgetSelect(widget_select_t *p);
+extern void eventWidgetSelect(widget_select_t *p);
+extern void destroyWidgetSelect(widget_select_t *p);
+
+#endif
+
diff --git a/modules/Makefile b/modules/Makefile
index dcdd234..e9546c8 100755
--- a/modules/Makefile
+++ b/modules/Makefile
@@ -19,6 +19,10 @@ modWall:
gcc $(CFLAGS) -fPIC -I../include `sdl-config --cflags` -c modWall.c -o modWall.o
gcc $(CFLAGS) -I../include -shared -fPIC -o modWall.so modWall.o list.o space.o
+modAI:
+ gcc $(CFLAGS) -fPIC -I../include `sdl-config --cflags` -c modAI.c -o modAI.o
+ gcc $(CFLAGS) -I../include -shared -fPIC -o modAI.so modAI.o
+
clean:
rm -rf *.o
rm -rf *.so
diff --git a/modules/modAI.c b/modules/modAI.c
new file mode 100755
index 0000000..53f689e
--- /dev/null
+++ b/modules/modAI.c
@@ -0,0 +1,256 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#include "main.h"
+#include "modules.h"
+#include "tux.h"
+#include "shot.h"
+#include "list.h"
+#include "gun.h"
+#include "space.h"
+
+#ifndef PUBLIC_SERVER
+#include "interface.h"
+#include "image.h"
+#endif
+
+#ifdef PUBLIC_SERVER
+#include "publicServer.h"
+#endif
+
+static export_fce_t *export_fce;
+
+static void cmd_ai(char *line)
+{
+}
+
+int init(export_fce_t *p)
+{
+ export_fce = p;
+
+ return 0;
+}
+
+#ifndef PUBLIC_SERVER
+
+int draw(int x, int y, int w, int h)
+{
+ return 0;
+}
+#endif
+
+/////////////////
+
+int colisionAll(tux_t *tux, int px, int py)
+{
+ arena_t *arena;
+ int x, y, w, h;
+
+ arena = export_fce->fce_getCurrentArena();
+
+ export_fce->fce_getTuxProportion(tux, &x, &y, &w, &h);
+ x += px;
+ y += py;
+
+ return export_fce->fce_isFreeSpace(arena, x, y, w, h);
+}
+
+void gotoTux(tux_t *tux, int x, int y, int w, int h)
+{
+ int px = 0,py = 0;
+ int smer = TUX_DOWN;
+
+ if(tux->x > x+w ) px = -TUX_STEP;
+ if(tux->x < x ) px = +TUX_STEP;
+ if(tux->y > y+h ) py = -TUX_STEP;
+ if(tux->y < y ) py = +TUX_STEP;
+
+ if( px != 0 && py !=0 ) px = 0;
+
+ while( colisionAll(tux, px, 0 ) )
+ {
+ px=0;
+ if(py==0) py = +TUX_STEP;
+ goto sem;
+ }
+
+ while( colisionAll(tux, 0, py ) )
+ {
+ py = 0;
+ if( px == 0 ) px = +TUX_STEP;
+ }
+
+ sem:
+ if( px != 0 && py != 0 ) px = 0;
+
+ if( py== -TUX_STEP )smer = TUX_UP;
+ if( px== +TUX_STEP )smer = TUX_RIGHT;
+ if( px== -TUX_STEP )smer = TUX_LEFT;
+ if( py== +TUX_STEP )smer = TUX_DOWN;
+
+ //printf("smer=%d\n",smer);
+ export_fce->fce_actionTux(tux, smer);
+}
+
+void gotoTuxShot(tux_t *tux, int x, int y, int w, int h)
+{
+ if( tux->x > x && tux->x < x+w )
+ {
+ if( tux->y > y+h )tux->position = TUX_UP;
+ if( tux->y < y )tux->position = TUX_DOWN;
+
+ if( colisionAll(tux, 0, 0) == 0 )
+ {
+ if( tux->shot[GUN_SIMPLE] > 0 )tux->gun = GUN_SIMPLE;
+ if( tux->shot[GUN_DUAL_SIMPLE] > 0 )tux->gun = GUN_DUAL_SIMPLE;
+ if( tux->shot[GUN_SCATTER] > 0 )tux->gun = GUN_SCATTER;
+ if( tux->shot[GUN_TOMMY] > 0 )tux->gun = GUN_TOMMY;
+ if( tux->shot[GUN_LASSER] > 0 )tux->gun = GUN_LASSER;
+ if( tux->shot[GUN_BOMBBALL] > 0 )tux->gun = GUN_BOMBBALL;
+
+ export_fce->fce_actionTux(tux, TUX_SHOT);
+ }
+ }
+
+ if( tux->y > y && tux->y < y+h )
+ {
+ if( tux->x > x+w )tux->position=TUX_LEFT;
+ if( tux->x < x )tux->position=TUX_RIGHT;
+
+ if( colisionAll(tux, 0 , 0) == 0 )
+ {
+ if( tux->shot[GUN_SIMPLE] > 0 )tux->gun = GUN_SIMPLE;
+ if( tux->shot[GUN_DUAL_SIMPLE] > 0 )tux->gun = GUN_DUAL_SIMPLE;
+ if( tux->shot[GUN_SCATTER] > 0 )tux->gun = GUN_SCATTER;
+ if( tux->shot[GUN_TOMMY] > 0 )tux->gun = GUN_TOMMY;
+ if( tux->shot[GUN_LASSER] > 0 )tux->gun = GUN_LASSER;
+ if( tux->shot[GUN_BOMBBALL] > 0 )tux->gun = GUN_BOMBBALL;
+
+ export_fce->fce_actionTux(tux, TUX_SHOT);
+ }
+ }
+}
+
+void killTux(tux_t *tux, int active)
+{
+ arena_t *arena;
+ int i;
+
+ arena = export_fce->fce_getCurrentArena();
+
+ for( i = 0 ; i < arena->spaceTux->list->count ; i++ )
+ {
+ tux_t *thisTux;
+
+ thisTux = arena->spaceTux->list->list[i];
+
+ if( thisTux->control != TUX_CONTROL_KEYBOARD_LEFT &&
+ thisTux->status == TUX_STATUS_ALIVE )
+ {
+ gotoTuxShot(tux, thisTux->x, thisTux->y,
+ TUX_WIDTH, TUX_HEIGHT);
+
+ if( active )
+ {
+ gotoTux(tux, thisTux->x, thisTux->y,
+ TUX_WIDTH, TUX_HEIGHT);
+
+ gotoTuxShot(tux, thisTux->x, thisTux->y,
+ TUX_WIDTH, TUX_HEIGHT);
+
+ break;
+ }
+ }
+ }
+}
+
+/////////////////
+
+static void eventTux(tux_t *tux)
+{
+ arena_t *arena;
+ item_t *item;
+
+ arena = export_fce->fce_getCurrentArena();
+
+ killTux(tux, 0);
+
+ item = NULL;
+
+ if( arena->spaceItem->list->count > 0 )
+ {
+ item = (item_t *) arena->spaceItem->list->list[0];
+ }
+
+ if( item != NULL &&
+ item->type != GUN_MINE )
+ {
+ gotoTux(tux, item->x, item->y,
+ item->w, item->h);
+ }
+ else
+ {
+ killTux(tux, 1);
+ }
+}
+
+int event()
+{
+ static my_time_t lastEvent = 0;
+ my_time_t curentTime;
+ arena_t *arena;
+ int countTuxAI;
+ int i;
+
+ if( lastEvent == 0 )
+ {
+ lastEvent = export_fce->fce_getMyTime();
+ }
+
+ curentTime = export_fce->fce_getMyTime();
+
+ if( curentTime - lastEvent < 25 )
+ {
+ return 0;
+ }
+
+ lastEvent = export_fce->fce_getMyTime();
+ //printf("event AI\n");
+
+ arena = export_fce->fce_getCurrentArena();
+ countTuxAI = 0;
+
+ for( i = 0 ; i < arena->spaceTux->list->count ; i++ )
+ {
+ tux_t *thisTux;
+
+ thisTux = arena->spaceTux->list->list[i];
+
+ if( thisTux->control == TUX_CONTROL_AI &&
+ thisTux->status == TUX_STATUS_ALIVE )
+ {
+ eventTux(thisTux);
+ countTuxAI = 0;
+ }
+ }
+
+ return 0;
+}
+
+int isConflict(int x, int y, int w, int h)
+{
+ return 0;
+}
+
+void cmd(char *line)
+{
+ if( strncmp(line, "ai", 2) == 0 )cmd_ai(line);
+}
+
+int destroy()
+{
+ return 0;
+}
diff --git a/src/Makefile b/src/Makefile
index d730826..29273cb 100755
--- a/src/Makefile
+++ b/src/Makefile
@@ -14,7 +14,7 @@ FILES = interface.o space.o idManager.o storage.o font.o list.o modules.o\
screen.o screen_world.o shot.o myTimer.o panel.o net_multiplayer.o \
buffer.o arena.o arenaFile.o textFile.o audio.o sound.o music.o gun.o \
item.o widget_label.o screen_mainMenu.o widget_button.o screen_analyze.o widget_textfield.o \
- widget_check.o widget_image.o screen_setting.o screen_gameType.o screen_choiceArena.o \
+ widget_check.o widget_image.o widget_select.o screen_setting.o screen_gameType.o screen_choiceArena.o \
widget_buttonimage.o screen_credits.o homeDirector.o screen_table.o \
sdl_udp.o proto.o server.o client.o term.o keytable.o language.o game.o
@@ -171,6 +171,9 @@ widget_check.o: widget_check.c ../include/widget_check.h
widget_image.o: widget_image.c ../include/widget_image.h
$(CC) $(CFLAGS) -o $(BUILD_DIR)/widget_image.o -c widget_image.c
+widget_select.o: widget_select.c ../include/widget_select.h
+ $(CC) $(CFLAGS) -o $(BUILD_DIR)/widget_select.o -c widget_select.c
+
#teleport.o: teleport.c ../include/teleport.h
# $(CC) $(CFLAGS) -o $(BUILD_DIR)/teleport.o -c teleport.c
diff --git a/src/client.c b/src/client.c
index 0009909..2210a3a 100644
--- a/src/client.c
+++ b/src/client.c
@@ -156,13 +156,10 @@ void eventServerBuffer()
if( strncmp(line, "init", 4) == 0 )proto_recv_init_client(line);
if( strncmp(line, "event", 5) == 0 )proto_recv_event_client(line);
if( strncmp(line, "newtux", 6) == 0 )proto_recv_newtux_client(line);
- if( strncmp(line, "deltux", 6) == 0 )proto_recv_deltux_client(line);
+ if( strncmp(line, "del", 3) == 0 )proto_recv_del_client(line);
if( strncmp(line, "additem", 7) == 0 )proto_recv_additem_client(line);
- if( strncmp(line, "item", 4) == 0 )proto_recv_item_client(line);
if( strncmp(line, "shot", 4) == 0 )proto_recv_shot_client(line);
- if( strncmp(line, "delshot", 7) == 0 )proto_recv_delshot_client(line);
if( strncmp(line, "kill", 4) == 0 )proto_recv_kill_client(line);
- if( strncmp(line, "score", 5) == 0 )proto_recv_score_client(line);
if( strncmp(line, "ping", 4) == 0 )proto_recv_ping_client(line);
if( strncmp(line, "end", 3) == 0 )proto_recv_end_client(line);
diff --git a/src/item.c b/src/item.c
index 171ac76..7100e5c 100644
--- a/src/item.c
+++ b/src/item.c
@@ -348,38 +348,8 @@ void eventListItem(space_t *spaceItem)
}
}
-/*
-int isConflictWithListItem(list_t *listItem, int x, int y, int w, int h)
-{
- item_t *thisItem;
- int i;
-
- assert( listItem != NULL );
-
- for( i = 0 ; i < listItem->count ; i++ )
- {
- thisItem = (item_t *)listItem->list[i];
- assert( thisItem != NULL );
-
- if( conflictSpace(x, y, w, h,
- thisItem->x, thisItem->y, thisItem->w, thisItem->h) )
- {
- return 1;
- }
- }
-
- return 0;
-}
-*/
-
void mineExplosion(space_t *spaceItem, item_t *item)
{
-/*
- x = ( item->x + item->w/2 ) - ITEM_BIG_EXPLOSION_WIDTH/2;
- y = ( item->y + item->h/2 ) - ITEM_BIG_EXPLOSION_HEIGHT/2;
- addList(listItem, newItem(x, y, ITEM_BIG_EXPLOSION, item->author_id) );
-*/
-
if( getNetTypeGame() != NET_GAME_TYPE_CLIENT )
{
int x, y;
@@ -398,78 +368,13 @@ void mineExplosion(space_t *spaceItem, item_t *item)
addObjectToSpace(spaceItem, item_explosion );
}
- delObjectFromSpaceWithObject(spaceItem, item, destroyItem);
-}
-
-/*
-void eventConflictShotWithItem(list_t *listItem, list_t *listShot)
-{
- shot_t *thisShot;
- item_t *thisItem;
- int i, j;
-
- if( getNetTypeGame() == NET_GAME_TYPE_CLIENT )
+ if( getNetTypeGame() == NET_GAME_TYPE_SERVER )
{
- return;
+ proto_send_del_server(PROTO_SEND_ALL, NULL, item->id);
}
- assert( listItem != NULL );
- assert( listShot != NULL );
-
- for( i = 0 ; i < listShot->count ; i++ )
- {
- bool_t isDelShot;
-
- isDelShot = FALSE;
- thisShot = (shot_t *)listShot->list[i];
- assert( thisShot != NULL );
-
- for( j = 0 ; j < listItem->count ; j++ )
- {
- thisItem = (item_t *)listItem->list[j];
- assert( thisItem != NULL );
-
- if( conflictSpace(thisShot->x, thisShot->y, thisShot->w, thisShot->h,
- thisItem->x, thisItem->y, thisItem->w, thisItem->h) )
- {
- switch( thisItem->type )
- {
- case ITEM_MINE :
-
- if( getNetTypeGame() != NET_GAME_TYPE_CLIENT )
- {
- if( getNetTypeGame() == NET_GAME_TYPE_SERVER )
- {
- proto_send_item_server(PROTO_SEND_ALL, NULL, NULL, thisItem);
- }
-
- mineExplosion(listItem, thisItem);
- j--;
- }
- break;
-
- case ITEM_EXPLOSION :
- case ITEM_BIG_EXPLOSION :
- isDelShot = TRUE;
-
- break;
- }
- }
- }
-
- if( isDelShot )
- {
- if( getNetTypeGame() == NET_GAME_TYPE_SERVER )
- {
- proto_send_delshot_server(PROTO_SEND_ALL, NULL, thisShot);
- }
-
- delListItem(listShot, i, destroyShot);
- i--;
- }
- }
+ delObjectFromSpaceWithObject(spaceItem, item, destroyItem);
}
-*/
void eventConflictShotWithItem(arena_t *arena)
{
@@ -503,11 +408,6 @@ void eventConflictShotWithItem(arena_t *arena)
case ITEM_MINE :
if( getNetTypeGame() != NET_GAME_TYPE_CLIENT )
{
- if( getNetTypeGame() == NET_GAME_TYPE_SERVER )
- {
- proto_send_item_server(PROTO_SEND_ALL, NULL, NULL, thisItem);
- }
-
mineExplosion(arena->spaceItem, thisItem);
}
break;
@@ -523,10 +423,10 @@ void eventConflictShotWithItem(arena_t *arena)
{
if( getNetTypeGame() == NET_GAME_TYPE_SERVER )
{
- proto_send_delshot_server(PROTO_SEND_ALL, NULL, thisShot);
+ proto_send_del_server(PROTO_SEND_ALL, NULL, thisShot->id);
}
- delObjectFromSpaceWithObject(arena->spaceShot, thisItem, destroyShot);
+ delObjectFromSpaceWithObject(arena->spaceShot, thisShot, destroyShot);
i--;
}
}
@@ -557,7 +457,7 @@ static void eventTuxIsDeadWithItem(tux_t *tux, item_t *item)
if( getNetTypeGame() == NET_GAME_TYPE_SERVER )
{
- proto_send_score_server(PROTO_SEND_ALL, NULL, author);
+ proto_send_newtux_server(PROTO_SEND_ALL, NULL, author);
}
}
}
@@ -579,6 +479,11 @@ static void tuxGiveBonus(tux_t *tux, item_t *item)
sprintf(msg, "tux with id %d bonus enabled\n", tux->id);
appendTextInTerm(msg);
#endif
+
+ if( getNetTypeGame() == NET_GAME_TYPE_SERVER )
+ {
+ proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux);
+ }
}
static void tuxGiveGun(tux_t *tux, item_t *item)
@@ -597,6 +502,10 @@ static void tuxGiveGun(tux_t *tux, item_t *item)
appendTextInTerm(msg);
#endif
+ if( getNetTypeGame() == NET_GAME_TYPE_SERVER )
+ {
+ proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux);
+ }
}
void eventGiveTuxItem(tux_t *tux, item_t *item, space_t *spaceItem)
@@ -610,6 +519,12 @@ void eventGiveTuxItem(tux_t *tux, item_t *item, space_t *spaceItem)
case GUN_MINE :
case GUN_BOMBBALL :
tuxGiveGun(tux, item);
+
+ if( getNetTypeGame() == NET_GAME_TYPE_SERVER )
+ {
+ proto_send_del_server(PROTO_SEND_ALL, NULL, item->id);
+ }
+
delObjectFromSpaceWithObject(spaceItem, item, destroyItem);
break;
@@ -632,6 +547,12 @@ void eventGiveTuxItem(tux_t *tux, item_t *item, space_t *spaceItem)
case BONUS_4X :
case BONUS_HIDDEN :
tuxGiveBonus(tux, item);
+
+ if( getNetTypeGame() == NET_GAME_TYPE_SERVER )
+ {
+ proto_send_del_server(PROTO_SEND_ALL, NULL, item->id);
+ }
+
delObjectFromSpaceWithObject(spaceItem, item, destroyItem);
break;
}
@@ -666,12 +587,13 @@ void eventGiveTuxListItem(tux_t *tux, space_t *spaceItem)
thisItem = (item_t *)listHelp->list[i];
assert( thisItem != NULL );
+ eventGiveTuxItem(tux, thisItem, spaceItem);
+
if( getNetTypeGame() == NET_GAME_TYPE_SERVER )
{
- proto_send_item_server(PROTO_SEND_ALL, NULL, tux, thisItem);
+ //proto_send_item_server(PROTO_SEND_ALL, NULL, tux, thisItem);
+ proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux);
}
-
- eventGiveTuxItem(tux, thisItem, spaceItem);
}
}
diff --git a/src/modules.c b/src/modules.c
index bf7eec6..34224a4 100755
--- a/src/modules.c
+++ b/src/modules.c
@@ -39,6 +39,9 @@ static export_fce_t export_fce =
.fce_getTuxProportion = getTuxProportion,
.fce_setTuxProportion = setTuxProportion,
//.fce_getTuxID = getTuxID,
+ .fce_actionTux = actionTux,
+
+ .fce_getMyTime = getMyTime,
.fce_getCurrentArena = getCurrentArena,
.fce_conflictSpace = conflictSpace,
diff --git a/src/proto.c b/src/proto.c
index 72e8f16..f33f74f 100644
--- a/src/proto.c
+++ b/src/proto.c
@@ -341,8 +341,6 @@ void proto_send_event_server(int type, client_t *client, tux_t *tux, int action)
{
char msg[STR_PROTO_SIZE];
- assert( tux != NULL );
-
sprintf(msg, "event %d %d\n", tux->id, action);
proto_send(type, client, msg);
@@ -524,80 +522,66 @@ void proto_recv_kill_client(char *msg)
#endif
-void proto_send_score_server(int type, client_t *client, tux_t *tux)
+void proto_send_del_server(int type, client_t *client, int id)
{
char msg[STR_PROTO_SIZE];
-
- assert( tux != NULL );
+ int check_id;
- sprintf(msg, "score %d %d\n", tux->id, tux->score);
-
- proto_send(type, client, msg);
+ check_id = getNewID();
+
+ sprintf(msg, "del %d %d\n",
+ id, check_id);
+
+ proto_check(type, client, msg, check_id);
}
#ifndef PUBLIC_SERVER
-void proto_recv_score_client(char *msg)
+void proto_recv_del_client(char *msg)
{
char cmd[STR_PROTO_SIZE];
- int id, score;
+ int id, check_id;
tux_t *tux;
+ shot_t *shot;
+ item_t *item;
assert( msg != NULL );
- sscanf(msg, "%s %d %d", cmd, &id, &score);
+ sscanf(msg, "%s %d %d",
+ cmd, &id, &check_id);
+
+ proto_send_check_client(check_id);
tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id);
if( tux != NULL )
{
char term_msg[STR_SIZE];
- sprintf(term_msg, "tux with id %d set score to %d\n", tux->id, score);
+
+ //printf("delete tux..\n");
+ sprintf(term_msg, "tux with id %d is disconnect\n", tux->id);
appendTextInTerm(term_msg);
- tux->score = score;
+ delObjectFromSpaceWithObject(getCurrentArena()->spaceTux, tux, destroyTux);
+ return;
}
- countRoundInc();
-}
-
-#endif
-
-void proto_send_deltux_server(int type, client_t *client, client_t *client2)
-{
- char msg[STR_PROTO_SIZE];
-
- assert( client2 != NULL );
-
- sprintf(msg, "deltux %d\n", client2->tux->id);
-
- proto_send(type, client, msg);
-}
-
-#ifndef PUBLIC_SERVER
-
-void proto_recv_deltux_client(char *msg)
-{
- char cmd[STR_PROTO_SIZE];
- int id;
- tux_t *tux;
-
- assert( msg != NULL );
+ shot = getObjectFromSpaceWithID(getCurrentArena()->spaceShot, id);
- sscanf(msg, "%s %d", cmd, &id);
+ if( shot != NULL )
+ {
+ //printf("delete shot..\n");
+ delObjectFromSpaceWithObject(getCurrentArena()->spaceShot, shot, destroyShot);
+ return;
+ }
- tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id);
+ item = getObjectFromSpaceWithID(getCurrentArena()->spaceItem, id);
- if( tux != NULL )
+ if( item != NULL )
{
- char term_msg[STR_SIZE];
- //int index;
-
- sprintf(term_msg, "tux with id %d is disconnect\n", tux->id);
- appendTextInTerm(term_msg);
-
- //index = searchListItem(getCurrentArena()->listTux, tux);
- delObjectFromSpaceWithObject(getCurrentArena()->spaceTux, tux, destroyTux);
+ //printf("delete item..\n");
+ delObjectFromSpaceWithObject(getCurrentArena()->spaceItem, item, destroyItem);
+ return;
}
}
@@ -645,13 +629,7 @@ void proto_recv_additem_client(char *msg)
}
item = newItem(x, y, type, author_id);
-/*
- if( isConflictWithListItem(getCurrentArena()->listItem, item->x, item->y, item->w, item->h) )
- {
- destroyItem(item);
- return;
- }
-*/
+
replaceItemID(item, id);
item->count = count;
item->frame = frame;
@@ -661,68 +639,6 @@ void proto_recv_additem_client(char *msg)
#endif
-void proto_send_item_server(int type, client_t *client, tux_t *tux, item_t *item)
-{
- char msg[STR_PROTO_SIZE];
- int tux_id = -1;
- int check_id;
-
- assert( item != NULL );
-
- if( tux != NULL )
- {
- tux_id = tux->id;
- }
-
- check_id = getNewID();
-
- sprintf(msg, "item %d %d %d\n",
- tux_id, item->id, check_id);
-
- //proto_send(type, client, msg);
- proto_check(type, client, msg, check_id);
-}
-
-#ifndef PUBLIC_SERVER
-
-void proto_recv_item_client(char *msg)
-{
- char cmd[STR_PROTO_SIZE];
- int tux_id, item_id, check_id;
- arena_t *arena;
-
- item_t *item;
- tux_t *tux;
-
- assert( msg != NULL );
-
- sscanf(msg, "%s %d %d %d",
- cmd, &tux_id, &item_id, &check_id);
-
- proto_send_check_client(check_id);
-
- arena = getCurrentArena();
-
- item = getObjectFromSpaceWithID(arena->spaceItem, item_id);
- tux = getObjectFromSpaceWithID(arena->spaceTux, tux_id);
-
- if( item == NULL)
- {
- return;
- }
-
- if( tux != NULL )
- {
- eventGiveTuxItem(tux, item, arena->spaceItem);
- }
- else
- {
- mineExplosion(arena->spaceItem, item);
- }
-}
-
-#endif
-
void proto_send_shot_server(int type, client_t *client, shot_t *p)
{
char msg[STR_PROTO_SIZE];
@@ -776,46 +692,6 @@ void proto_recv_shot_client(char *msg)
#endif
-void proto_send_delshot_server(int type, client_t *client, shot_t *shot)
-{
- char msg[STR_PROTO_SIZE];
- int check_id;
-
- assert( shot != NULL );
-
- check_id = getNewID();
-
- sprintf(msg, "delshot %d %d\n",
- shot->id, check_id);
-
- proto_check(type, client, msg, check_id);
-}
-
-#ifndef PUBLIC_SERVER
-
-void proto_recv_delshot_client(char *msg)
-{
- char cmd[STR_PROTO_SIZE];
- shot_t *shot;
- int id, check_id;
-
- assert( msg != NULL );
-
- sscanf(msg, "%s %d %d",
- cmd, &id, &check_id);
-
- proto_send_check_client(check_id);
-
- shot = getObjectFromSpaceWithID(getCurrentArena()->spaceShot, id);
-
- if( shot != NULL )
- {
- delObjectFromSpaceWithObject(getCurrentArena()->spaceShot, shot, destroyShot);
- }
-}
-
-#endif
-
#ifndef PUBLIC_SERVER
void proto_send_ping_client()
diff --git a/src/screen_setting.c b/src/screen_setting.c
index 92e88e0..5a42135 100644
--- a/src/screen_setting.c
+++ b/src/screen_setting.c
@@ -19,12 +19,14 @@
#include "tux.h"
#include "textFile.h"
#include "configFile.h"
+#include "director.h"
#include "widget_label.h"
#include "widget_button.h"
#include "widget_image.h"
#include "widget_textfield.h"
#include "widget_check.h"
+#include "widget_select.h"
static widget_image_t *image_backgorund;
@@ -33,6 +35,7 @@ static widget_button_t *button_back;
static widget_label_t *label_count_round;
static widget_label_t *label_name_player1;
static widget_label_t *label_name_player2;
+static widget_label_t *label_ai;
#ifndef NO_SOUND
static widget_label_t *label_music;
@@ -63,6 +66,8 @@ static widget_textfield_t *textfield_count_cound;
static widget_textfield_t *textfield_name_player1;
static widget_textfield_t *textfield_name_player2;
+static widget_select_t *select_ai;
+
static textFile_t *configFile;
void startScreenSetting()
@@ -79,6 +84,8 @@ void drawScreenSetting()
drawWidgetLabel(label_count_round);
drawWidgetLabel(label_name_player1);
drawWidgetLabel(label_name_player2);
+ drawWidgetLabel(label_ai);
+
#ifndef NO_SOUND
drawWidgetLabel(label_music);
drawWidgetLabel(label_sound);
@@ -117,13 +124,24 @@ void drawScreenSetting()
drawWidgetCheck(check[i]);
}
+ drawWidgetSelect(select_ai);
+
drawWidgetButton(button_back);
}
void eventScreenSetting()
{
int i;
+/*
+ int x, y;
+
+ getMousePosition(&x, &y);
+ if( isMouseClicked() )
+ {
+ printf("x = %d y = %d\n", x, y);
+ }
+*/
eventWidgetTextfield(textfield_count_cound);
eventWidgetTextfield(textfield_name_player1);
eventWidgetTextfield(textfield_name_player2);
@@ -143,6 +161,8 @@ void eventScreenSetting()
eventWidgetCheck(check[i]);
}
+ eventWidgetSelect(select_ai);
+
eventWidgetButton(button_back);
}
@@ -279,6 +299,29 @@ static void saveAndDestroyConfigFile()
destroyTextFile(configFile);
}
+static void findModulesAI()
+{
+ director_t *listModules;
+ int i;
+
+ listModules = loadDirector(PATH_MODULES);
+
+ for( i = 0 ; i < listModules->list->count ; i++)
+ {
+ char *line;
+
+ line = (char *)listModules->list->list[i];
+
+ if( strstr(line,"AI") != NULL &&
+ strstr(line,".so") != NULL )
+ {
+ addToWidgetSelect(select_ai, line);
+ }
+ }
+
+ destroyDirector(listModules);
+}
+
void initScreenSetting()
{
SDL_Surface *image;
@@ -292,6 +335,7 @@ void initScreenSetting()
label_count_round = newWidgetLabel(getMyText("COUNT_ROUND"), 100, WINDOW_SIZE_Y-200, WIDGET_LABEL_LEFT);
label_name_player1 = newWidgetLabel(getMyText("NAME_PLAYER1"), 100, WINDOW_SIZE_Y-160, WIDGET_LABEL_LEFT);
label_name_player2 = newWidgetLabel(getMyText("NAME_PLAYER2"), 100, WINDOW_SIZE_Y-120, WIDGET_LABEL_LEFT);
+ label_ai = newWidgetLabel("AI :", 430, 400, WIDGET_LABEL_LEFT);
textfield_count_cound = newWidgetTextfield(getParamElse("--count", "15"), 110+label_count_round->w, WINDOW_SIZE_Y-200);
@@ -367,6 +411,10 @@ void initScreenSetting()
initSettingFile();
+ select_ai = newWidgetSelect(label_ai->x, label_ai->y+40, eventWidget);
+ addToWidgetSelect(select_ai, "none");
+ findModulesAI();
+
#ifndef NO_SOUND
eventWidget(check_music);
eventWidget(check_sound);
@@ -388,6 +436,11 @@ void getSettingCountRound(int *n)
*n = atoi( textfield_count_cound->text );
}
+char* getSettingAI()
+{
+ return (char *) select_ai->list->list[ select_ai->select ];
+}
+
bool_t isSettingAnyItem()
{
int i;
@@ -427,6 +480,7 @@ void quitScreenSetting()
destroyWidgetLabel(label_count_round);
destroyWidgetLabel(label_name_player1);
destroyWidgetLabel(label_name_player2);
+ destroyWidgetLabel(label_ai);
#ifndef NO_SOUND
destroyWidgetLabel(label_music);
@@ -466,6 +520,8 @@ void quitScreenSetting()
destroyWidgetCheck(check[i]);
}
+ destroyWidgetSelect(select_ai);
+
destroyWidgetButton(button_back);
}
diff --git a/src/screen_world.c b/src/screen_world.c
index 077153f..a5fdc1c 100644
--- a/src/screen_world.c
+++ b/src/screen_world.c
@@ -103,6 +103,7 @@ void countRoundInc()
}
count++;
+ printf("count %d/%d\n", count, max_count);
if( count >= max_count )
{
@@ -116,6 +117,8 @@ void prepareArena()
{
tux_t *tux;
+ //printf("getSettingAI = %s\n", getSettingAI());
+
switch( getNetTypeGame() )
{
case NET_GAME_TYPE_NONE :
@@ -134,6 +137,12 @@ void prepareArena()
tuxWithControlLeftKeyboard = tux;
getSettingNameLeft(tux->name);
addObjectToSpace(arena->spaceTux, tux);
+
+ if( strcmp(getSettingAI(), "none") != 0 )
+ {
+ loadModule( getSettingAI() );
+ tux->control = TUX_CONTROL_AI;
+ }
break;
case NET_GAME_TYPE_SERVER :
diff --git a/src/server.c b/src/server.c
index 3b06a3f..bda983a 100644
--- a/src/server.c
+++ b/src/server.c
@@ -77,7 +77,7 @@ static void delZombieCLient(void *p_nothink)
{
if( thisClient->tux != NULL )
{
- proto_send_deltux_server(PROTO_SEND_ALL, NULL, thisClient);
+ proto_send_del_server(PROTO_SEND_ALL, NULL, thisClient->tux->id);
}
delListItem(listClient, i, destroyClient);
diff --git a/src/tux.c b/src/tux.c
index 710b253..c9d5ff2 100644
--- a/src/tux.c
+++ b/src/tux.c
@@ -356,7 +356,7 @@ static void eventTuxIsDeadWIthShot(tux_t *tux, shot_t *shot)
if( getNetTypeGame() == NET_GAME_TYPE_SERVER )
{
- proto_send_score_server(PROTO_SEND_ALL, NULL, author);
+ proto_send_newtux_server(PROTO_SEND_ALL, NULL, author);
}
}
@@ -407,7 +407,7 @@ static void bombBallExplosion(shot_t *shot)
if( getNetTypeGame() == NET_GAME_TYPE_SERVER )
{
- proto_send_delshot_server(PROTO_SEND_ALL, NULL, shot);
+ proto_send_del_server(PROTO_SEND_ALL, NULL, shot->id);
proto_send_additem_server(PROTO_SEND_ALL, NULL, item);
}
}
@@ -470,6 +470,22 @@ void eventConflictTuxWithShot(arena_t *arena)
}
}
+static void interval()
+{
+ static my_time_t lastEvent = 0;
+ my_time_t curentTime;
+
+ if( lastEvent == 0 )
+ {
+ lastEvent = getMyTime();
+ }
+
+ curentTime = getMyTime();
+
+ printf("time = %d\n", curentTime - lastEvent);
+
+ lastEvent = getMyTime();
+}
void moveTux(tux_t *tux, int n)
{
@@ -482,6 +498,7 @@ void moveTux(tux_t *tux, int n)
assert( tux != NULL );
arena = getCurrentArena();
+ //interval();
if( tux->position != n )
{
@@ -623,7 +640,7 @@ void actionTux(tux_t *tux, int action)
{
return;
}
-
+
switch( action )
{
case TUX_UP :
diff --git a/src/widget_select.c b/src/widget_select.c
new file mode 100644
index 0000000..dbd6fa9
--- /dev/null
+++ b/src/widget_select.c
@@ -0,0 +1,99 @@
+
+#include <stdlib.h>
+
+#include "main.h"
+#include "interface.h"
+#include "font.h"
+#include "widget_select.h"
+#include "image.h"
+
+/*
+typedef struct widget_select
+{
+ int x, y;
+ int w, h;
+ list_t *list;
+ void (*fce_event)(void *);
+} widget_select_t;
+*/
+
+widget_select_t* newWidgetSelect(int x, int y, void (*fce_event)(void *))
+{
+ widget_select_t *new;
+
+ new = malloc( sizeof(widget_select_t) );
+ new->x = x;
+ new->y = y;
+ new->select = 0;
+ new->fce_event = fce_event;
+ new->list = newList();
+
+ return new;
+}
+
+void addToWidgetSelect(widget_select_t *p, char *s)
+{
+ addList(p->list, strdup(s) );
+}
+
+void drawWidgetSelect(widget_select_t *p)
+{
+ int x, y, w, h;
+ int i;
+
+ getMousePosition(&x, &y);
+
+ for( i = 0 ; i < p->list->count ; i++ )
+ {
+ char *line;
+
+ line = (char *)p->list->list[i];
+
+ getTextSize(line, &w, &h);
+
+ if( x > p->x && y > p->y + i*20 && x < p->x+w && y < p->y + i*20 + h )
+ {
+ drawFont(line, p->x, p->y + i*20, COLOR_YELLOW);
+ }
+ else
+ {
+ if( p->select == i )
+ {
+ drawFont(line, p->x, p->y + i*20, COLOR_RED);
+ }
+ else
+ {
+ drawFont(line, p->x, p->y + i*20, COLOR_WHITE);
+ }
+ }
+ }
+}
+
+void eventWidgetSelect(widget_select_t *p)
+{
+ int x, y, w, h;
+ int i;
+
+ getMousePosition(&x, &y);
+
+ for( i = 0 ; i < p->list->count ; i++ )
+ {
+ char *line;
+
+ line = (char *)p->list->list[i];
+
+ getTextSize(line, &w, &h);
+
+ if( x > p->x && y > p->y + i*20 && x < p->x+w && y < p->y + i*20 + h && isMouseClicked() )
+ {
+ p->select = i;
+ p->fce_event(p);
+ }
+ }
+}
+
+void destroyWidgetSelect(widget_select_t *p)
+{
+ destroyListItem(p->list, free);
+ free(p);
+}