summaryrefslogtreecommitdiff
path: root/src/item.c
diff options
context:
space:
mode:
authororoborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e>2008-03-23 21:38:56 +0000
committeroroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e>2008-03-23 21:38:56 +0000
commitaec5ba5ca31f3d7c895beb658a93c353b2b8d5c1 (patch)
tree068d2a3ad5e5bf290acf2d73b87e170bc9962069 /src/item.c
parent20ecf36f401adad01cc5ff67e411c596a8b523d5 (diff)
- zobratie zbrani/bonusov prebieha na server, a server tuto informaciu posiela clientom
- server checkuje, ci ma client spravnu verziu - clientovy, ktory sa neprihlasil do hry prikazom hello, neposiela stavy aku su end, alebo deltux - oprava malej chyby v textfiled - posladna aktivita serveru/clienta zistuje druha strana na zaklade kazdeho prijateho packetu, nie iba podla packetu ping - server posile clientovy pakcety "error <code>" ) nespravny pikaz, veriza, timeout git-svn-id: http://opensvn.csie.org/tuxanci_ng@33 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e
Diffstat (limited to 'src/item.c')
-rw-r--r--src/item.c153
1 files changed, 104 insertions, 49 deletions
diff --git a/src/item.c b/src/item.c
index 658e66e..3305d7c 100644
--- a/src/item.c
+++ b/src/item.c
@@ -59,6 +59,7 @@ void initItem()
item_t* newItem(int x, int y, int type, tux_t *author)
{
+ static unsigned int last_id = 0;
item_t *new;
new = malloc( sizeof(item_t) );
@@ -66,6 +67,7 @@ item_t* newItem(int x, int y, int type, tux_t *author)
new->type = type;
+ new->id = last_id++;
new->x = x;
new->y = y;
new->frame = 0;
@@ -121,6 +123,27 @@ item_t* newItem(int x, int y, int type, tux_t *author)
return new;
}
+item_t* getItemID(list_t *listItem, int id)
+{
+ 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( thisItem->id == id )
+ {
+ return thisItem;
+ }
+ }
+
+ return NULL;
+}
+
void addNewItem(list_t *listItem, tux_t *author)
{
#ifndef BUBLIC_SERVER
@@ -175,6 +198,7 @@ void addNewItem(list_t *listItem, tux_t *author)
#ifndef BUBLIC_SERVER
}while( isSettingItem(type) == FALSE );
#endif
+
item = newItem(new_x, new_y, type, author);
addList(listItem, item);
@@ -302,6 +326,23 @@ int isConflictWithListItem(list_t *listItem, int x, int y, int w, int h)
return 0;
}
+void mineExplosion(list_t *listItem, item_t *item)
+{
+ int x, y;
+ int index;
+
+ index = searchListItem(listItem, item);
+
+ assert( index != -1 );
+
+ 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) );
+
+ delListItem(listItem, index, destroyItem);
+}
+
+
void eventConflictShotWithItem(list_t *listItem, list_t *listShot)
{
shot_t *thisShot;
@@ -326,16 +367,13 @@ void eventConflictShotWithItem(list_t *listItem, list_t *listShot)
switch( thisItem->type )
{
case ITEM_MINE :
- if( conflictSpace(thisShot->x, thisShot->y, thisShot->w, thisShot->h,
+
+ if( getNetTypeGame() != NET_GAME_TYPE_CLIENT &&
+ conflictSpace(thisShot->x, thisShot->y, thisShot->w, thisShot->h,
thisItem->x, thisItem->y, thisItem->w, thisItem->h) )
{
- int x, y;
-
- x = ( thisItem->x + thisItem->w/2 ) - ITEM_BIG_EXPLOSION_WIDTH/2;
- y = ( thisItem->y + thisItem->h/2 ) - ITEM_BIG_EXPLOSION_HEIGHT/2;
- addList(listItem, newItem(x, y, ITEM_BIG_EXPLOSION, thisItem->author) );
-
- delListItem(listItem, j, destroyItem);
+ proto_send_item_server(PROTO_SEND_ALL, NULL, NULL, thisItem);
+ mineExplosion(listItem, thisItem);
j--;
}
break;
@@ -422,12 +460,65 @@ static void tuxGiveGun(tux_t *tux, item_t *item)
}
-void eventGiveTuxItem(tux_t *tux, list_t *listItem)
+int eventGiveTuxItem(tux_t *tux, list_t *listItem, item_t *item)
+{
+ int index;
+
+ index = searchListItem(listItem, item);
+
+ assert( index != -1 );
+
+ switch( item->type )
+ {
+ case GUN_TOMMY :
+ case GUN_DUAL_SIMPLE :
+ case GUN_SCATTER :
+ case GUN_LASSER :
+ case GUN_MINE :
+ tuxGiveGun(tux, item);
+ delListItem(listItem, index, destroyItem);
+ return index;
+ break;
+
+ case ITEM_MINE :
+ if( tux->bonus != BONUS_GHOST )
+ {
+ mineExplosion(listItem, item);
+ return index;
+ }
+ break;
+
+ case ITEM_EXPLOSION :
+ case ITEM_BIG_EXPLOSION :
+ eventTuxIsDeadWithItem(tux, item);
+ break;
+
+ case BONUS_SPEED :
+ case BONUS_SHOT :
+ case BONUS_TELEPORT :
+ case BONUS_GHOST :
+ case BONUS_4X :
+ case BONUS_HIDDEN :
+ tuxGiveBonus(tux, item);
+ delListItem(listItem, index, destroyItem);
+ return index;
+ break;
+ }
+
+ return -1;
+}
+
+void eventGiveTuxListItem(tux_t *tux, list_t *listItem)
{
item_t *thisItem;
int x, y, w, h;
int i;
+ if( getNetTypeGame() == NET_GAME_TYPE_CLIENT )
+ {
+ return;
+ }
+
assert( listItem != NULL );
assert( tux != NULL );
@@ -445,49 +536,13 @@ void eventGiveTuxItem(tux_t *tux, list_t *listItem)
if( conflictSpace(x, y, w, h, thisItem->x, thisItem->y, thisItem->w, thisItem->h) )
{
- switch( thisItem->type )
- {
- case GUN_TOMMY :
- case GUN_DUAL_SIMPLE :
- case GUN_SCATTER :
- case GUN_LASSER :
- case GUN_MINE :
- tuxGiveGun(tux, thisItem);
- delListItem(listItem, i, destroyItem);
- i--;
- break;
-
- case ITEM_MINE :
- if( tux->bonus != BONUS_GHOST )
- {
- //eventTuxIsDeadWithItem(tux, thisItem);
- addList(listItem, newItem(x, y,
- ITEM_EXPLOSION, thisItem->author) );
-
- delListItem(listItem, i, destroyItem);
- i--;
- }
- break;
-
- case ITEM_EXPLOSION :
- case ITEM_BIG_EXPLOSION :
- eventTuxIsDeadWithItem(tux, thisItem);
- break;
-
- case BONUS_SPEED :
- case BONUS_SHOT :
- case BONUS_TELEPORT :
- case BONUS_GHOST :
- case BONUS_4X :
- case BONUS_HIDDEN :
- tuxGiveBonus(tux, thisItem);
- delListItem(listItem, i, destroyItem);
- i--;
- break;
+ proto_send_item_server(PROTO_SEND_ALL, NULL, tux, thisItem);
+ if( eventGiveTuxItem(tux, listItem, thisItem) >= 0 )
+ {
+ i--;
}
}
-
}
}