summaryrefslogtreecommitdiff
path: root/src/base/shot.c
diff options
context:
space:
mode:
authorxHire <xhire@tuxportal.cz>2008-10-25 14:11:06 +0200
committerxHire <xhire@tuxportal.cz>2008-10-25 14:11:06 +0200
commitc8a9209d77a896bf49227e5aeccd54e91ccf29cc (patch)
tree6b7367406ebbc6ce3ea5e0c8668c75f6fb3f6ae9 /src/base/shot.c
parentcb9deba915dd7b114eeb76601eb1c8b07c1ba90f (diff)
Changed style of the code to the K&R standard
Diffstat (limited to 'src/base/shot.c')
-rw-r--r--src/base/shot.c454
1 files changed, 218 insertions, 236 deletions
diff --git a/src/base/shot.c b/src/base/shot.c
index 2fe1490..a233712 100644
--- a/src/base/shot.c
+++ b/src/base/shot.c
@@ -12,13 +12,13 @@
#include "serverSendMsg.h"
#ifndef PUBLIC_SERVER
-#include "image.h"
-#include "layer.h"
-#include "screen_world.h"
+# include "image.h"
+# include "layer.h"
+# include "screen_world.h"
#endif
#ifdef PUBLIC_SERVER
-#include "publicServer.h"
+# include "publicServer.h"
#endif
#ifndef PUBLIC_SERVER
@@ -32,350 +32,332 @@ static image_t *g_shot_bombball;
static bool_t isShotInit = FALSE;
-bool_t
-isShotInicialized()
+bool_t isShotInicialized()
{
- return isShotInit;
+ return isShotInit;
}
-void
-initShot()
+void initShot()
{
#ifndef PUBLIC_SERVER
- assert(isImageInicialized() == TRUE);
+ assert(isImageInicialized() == TRUE);
#endif
#ifndef PUBLIC_SERVER
- g_shot_simple =
- addImageData("shot.png", IMAGE_ALPHA, "shot", IMAGE_GROUP_BASE);
- g_shot_lasserX =
- addImageData("lasserX.png", IMAGE_NO_ALPHA, "lasserX",
- IMAGE_GROUP_BASE);
- g_shot_lasserY =
- addImageData("lasserY.png", IMAGE_NO_ALPHA, "lasserY",
- IMAGE_GROUP_BASE);
- g_shot_bombball =
- addImageData("bombball.png", IMAGE_ALPHA, "bombball",
- IMAGE_GROUP_BASE);
+ g_shot_simple =
+ addImageData("shot.png", IMAGE_ALPHA, "shot", IMAGE_GROUP_BASE);
+ g_shot_lasserX =
+ addImageData("lasserX.png", IMAGE_NO_ALPHA, "lasserX",
+ IMAGE_GROUP_BASE);
+ g_shot_lasserY =
+ addImageData("lasserY.png", IMAGE_NO_ALPHA, "lasserY",
+ IMAGE_GROUP_BASE);
+ g_shot_bombball =
+ addImageData("bombball.png", IMAGE_ALPHA, "bombball",
+ IMAGE_GROUP_BASE);
#endif
- isShotInit = TRUE;
+ isShotInit = TRUE;
}
-shot_t *
-newShot(int x, int y, int px, int py, int gun, int author_id)
+shot_t *newShot(int x, int y, int px, int py, int gun, int author_id)
{
- shot_t *new;
- tux_t *author;
+ shot_t *new;
+ tux_t *author;
- new = malloc(sizeof(shot_t));
- memset(new, 0, sizeof(shot_t));
+ new = malloc(sizeof(shot_t));
+ memset(new, 0, sizeof(shot_t));
- new->id = getNewID();
- new->x = x;
- new->y = y;
- new->px = px;
- new->py = py;
- new->gun = gun;
- new->author_id = author_id;
+ new->id = getNewID();
+ new->x = x;
+ new->y = y;
+ new->px = px;
+ new->py = py;
+ new->gun = gun;
+ new->author_id = author_id;
- new->position = POSITION_UNKNOWN;
+ new->position = POSITION_UNKNOWN;
- author = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, author_id);
+ author = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, author_id);
- if (author != NULL) {
- new->position = author->position;
- }
+ if (author != NULL) {
+ new->position = author->position;
+ }
- new->isCanKillAuthor = FALSE;
- new->del = FALSE;
+ new->isCanKillAuthor = FALSE;
+ new->del = FALSE;
- switch (gun) {
- case GUN_SIMPLE:
- new->w = GUN_SHOT_WIDTH;
- new->h = GUN_SHOT_HEIGHT;
+ switch (gun) {
+ case GUN_SIMPLE:
+ new->w = GUN_SHOT_WIDTH;
+ new->h = GUN_SHOT_HEIGHT;
#ifndef PUBLIC_SERVER
- new->img = g_shot_simple;
+ new->img = g_shot_simple;
#endif
- break;
-
- case GUN_LASSER:
- switch (author->position) {
- case TUX_RIGHT:
- case TUX_LEFT:
- new->w = GUN_LASSER_HORIZONTAL;
- new->h = GUN_SHOT_VERTICAL;
+ break;
+
+ case GUN_LASSER:
+ switch (author->position) {
+ case TUX_RIGHT:
+ case TUX_LEFT:
+ new->w = GUN_LASSER_HORIZONTAL;
+ new->h = GUN_SHOT_VERTICAL;
#ifndef PUBLIC_SERVER
- new->img = g_shot_lasserX;
+ new->img = g_shot_lasserX;
#endif
- break;
- case TUX_UP:
- case TUX_DOWN:
- new->w = GUN_SHOT_VERTICAL;
- new->h = GUN_LASSER_HORIZONTAL;
+ break;
+ case TUX_UP:
+ case TUX_DOWN:
+ new->w = GUN_SHOT_VERTICAL;
+ new->h = GUN_LASSER_HORIZONTAL;
#ifndef PUBLIC_SERVER
- new->img = g_shot_lasserY;
+ new->img = g_shot_lasserY;
#endif
- break;
- }
- break;
+ break;
+ }
+ break;
- case GUN_BOMBBALL:
- new->w = GUN_BOMBBALL_WIDTH;
- new->h = GUN_BOMBBALL_HEIGHT;
+ case GUN_BOMBBALL:
+ new->w = GUN_BOMBBALL_WIDTH;
+ new->h = GUN_BOMBBALL_HEIGHT;
#ifndef PUBLIC_SERVER
- new->img = g_shot_bombball;
+ new->img = g_shot_bombball;
#endif
- break;
+ break;
- default:
- assert(!_("Type variable has a really wierd value!"));
- break;
- }
+ default:
+ assert(!_("Type variable has a really wierd value!"));
+ break;
+ }
- return new;
+ return new;
}
-void
-replaceShotID(shot_t * shot, int id)
+void replaceShotID(shot_t * shot, int id)
{
- replaceID(shot->id, id);
- shot->id = id;
+ replaceID(shot->id, id);
+ shot->id = id;
}
-void
-getStatusShot(void *p, int *id, int *x, int *y, int *w, int *h)
+void getStatusShot(void *p, int *id, int *x, int *y, int *w, int *h)
{
- shot_t *shot;
-
- shot = p;
- *id = shot->id;
- *x = shot->x;
- *y = shot->y;
- *w = shot->w;
- *h = shot->h;
+ shot_t *shot;
+
+ shot = p;
+ *id = shot->id;
+ *x = shot->x;
+ *y = shot->y;
+ *w = shot->w;
+ *h = shot->h;
}
-void
-setStatusShot(void *p, int x, int y, int w, int h)
+void setStatusShot(void *p, int x, int y, int w, int h)
{
- shot_t *shot;
+ shot_t *shot;
- shot = p;
- shot->x = x;
- shot->y = y;
- shot->w = w;
- shot->h = h;
+ shot = p;
+ shot->x = x;
+ shot->y = y;
+ shot->w = w;
+ shot->h = h;
}
#ifndef PUBLIC_SERVER
-void
-drawShot(shot_t * p)
+void drawShot(shot_t * p)
{
- assert(p != NULL);
- addLayer(p->img, p->x, p->y, 0, 0, p->img->w, p->img->h, TUX_LAYER);
+ assert(p != NULL);
+ addLayer(p->img, p->x, p->y, 0, 0, p->img->w, p->img->h, TUX_LAYER);
}
-void
-drawListShot(list_t * listShot)
+void drawListShot(list_t * listShot)
{
- shot_t *thisShot;
- int i;
+ shot_t *thisShot;
+ int i;
- assert(listShot != NULL);
+ assert(listShot != NULL);
- for (i = 0; i < listShot->count; i++) {
- thisShot = (shot_t *) listShot->list[i];
- assert(thisShot != NULL);
- drawShot(thisShot);
- }
+ for (i = 0; i < listShot->count; i++) {
+ thisShot = (shot_t *) listShot->list[i];
+ assert(thisShot != NULL);
+ drawShot(thisShot);
+ }
}
#endif
-static int
-getRandomCourse(int x, int y)
+static int getRandomCourse(int x, int y)
{
- int ret = -1; // no warnning
-
- do {
- switch (random() % 3) {
- case 0:
- ret = y;
- break;
- case 1:
- ret = -y;
- break;
- case 2:
- ret = 0;
- break;
- }
- } while (ret == x);
-
- return ret;
+ int ret = -1; // no warnning
+
+ do {
+ switch (random() % 3) {
+ case 0:
+ ret = y;
+ break;
+ case 1:
+ ret = -y;
+ break;
+ case 2:
+ ret = 0;
+ break;
+ }
+ } while (ret == x);
+
+ return ret;
}
-void
-boundBombBall(shot_t * shot)
+void boundBombBall(shot_t * shot)
{
- if (shot->gun != GUN_BOMBBALL) {
- return;
- }
+ if (shot->gun != GUN_BOMBBALL) {
+ return;
+ }
- shot->px = getRandomCourse(shot->px, +10);
- shot->py = getRandomCourse(shot->py, +10);
- shot->isCanKillAuthor = 1;
+ shot->px = getRandomCourse(shot->px, +10);
+ shot->py = getRandomCourse(shot->py, +10);
+ shot->isCanKillAuthor = 1;
- if (getNetTypeGame() == NET_GAME_TYPE_SERVER) {
- proto_send_shot_server(PROTO_SEND_ALL, NULL, shot);
- }
+ if (getNetTypeGame() == NET_GAME_TYPE_SERVER) {
+ proto_send_shot_server(PROTO_SEND_ALL, NULL, shot);
+ }
}
-void
-transformOnlyLasser(shot_t * shot)
+void transformOnlyLasser(shot_t * shot)
{
- space_t *space;
- int mustRefesh = 0;
+ space_t *space;
+ int mustRefesh = 0;
- space = getCurrentArena()->spaceShot;
+ space = getCurrentArena()->spaceShot;
- if (getObjectFromSpaceWithID(space, shot->id) != NULL) {
- mustRefesh = 1;
- }
+ if (getObjectFromSpaceWithID(space, shot->id) != NULL) {
+ mustRefesh = 1;
+ }
- if (mustRefesh) {
- delObjectFromSpace(space, shot);
- }
+ if (mustRefesh) {
+ delObjectFromSpace(space, shot);
+ }
- switch (shot->position) {
- case TUX_RIGHT:
- case TUX_LEFT:
- shot->w = GUN_LASSER_HORIZONTAL;
- shot->h = GUN_SHOT_VERTICAL;
+ switch (shot->position) {
+ case TUX_RIGHT:
+ case TUX_LEFT:
+ shot->w = GUN_LASSER_HORIZONTAL;
+ shot->h = GUN_SHOT_VERTICAL;
#ifndef PUBLIC_SERVER
- shot->img = g_shot_lasserX;
+ shot->img = g_shot_lasserX;
#endif
- break;
- case TUX_UP:
- case TUX_DOWN:
- shot->w = GUN_SHOT_VERTICAL;
- shot->h = GUN_LASSER_HORIZONTAL;
+ break;
+ case TUX_UP:
+ case TUX_DOWN:
+ shot->w = GUN_SHOT_VERTICAL;
+ shot->h = GUN_LASSER_HORIZONTAL;
#ifndef PUBLIC_SERVER
- shot->img = g_shot_lasserY;
+ shot->img = g_shot_lasserY;
#endif
- break;
- }
+ break;
+ }
- if (mustRefesh) {
- addObjectToSpace(space, shot);
- }
+ if (mustRefesh) {
+ addObjectToSpace(space, shot);
+ }
}
-static void
-action_moveShot(space_t * space, shot_t * shot, void *p)
+static void action_moveShot(space_t * space, shot_t * shot, void *p)
{
- int new_x, new_y;
- arena_t *arena;
+ int new_x, new_y;
+ arena_t *arena;
- arena = getCurrentArena();
+ arena = getCurrentArena();
- new_x = shot->x + shot->px;
- new_y = shot->y + shot->py;
+ new_x = shot->x + shot->px;
+ new_y = shot->y + shot->py;
- moveObjectInSpace(space, shot, new_x, new_y);
+ moveObjectInSpace(space, shot, new_x, new_y);
- if (shot->x + shot->w < 0 || shot->x > arena->w ||
- shot->y + shot->h < 0 || shot->y > arena->h) {
- delObjectFromSpaceWithObject(space, shot, destroyShot);
- }
+ if (shot->x + shot->w < 0 || shot->x > arena->w ||
+ shot->y + shot->h < 0 || shot->y > arena->h) {
+ delObjectFromSpaceWithObject(space, shot, destroyShot);
+ }
}
-void
-eventMoveListShot(arena_t * arena)
+void eventMoveListShot(arena_t * arena)
{
- actionSpace(arena->spaceShot, action_moveShot, NULL);
+ actionSpace(arena->spaceShot, action_moveShot, NULL);
}
-static int
-isValueInList(list_t * list, int x)
+static int isValueInList(list_t * list, int x)
{
- int i;
+ int i;
- for (i = 0; i < list->count; i++) {
- if (x == (*(int *) list->list[i])) {
- return 1;
- }
- }
+ for (i = 0; i < list->count; i++) {
+ if (x == (*(int *) list->list[i])) {
+ return 1;
+ }
+ }
- return 0;
+ return 0;
}
-static void
-action_check(space_t * space, shot_t * shot, client_t * client)
+static void action_check(space_t * space, shot_t * shot, client_t * client)
{
- if (isValueInList(client->listSeesShot, shot->id) == 0) {
- addList(client->listSeesShot, newInt(shot->id));
- proto_send_shot_server(PROTO_SEND_ONE, client, shot);
- }
+ if (isValueInList(client->listSeesShot, shot->id) == 0) {
+ addList(client->listSeesShot, newInt(shot->id));
+ proto_send_shot_server(PROTO_SEND_ONE, client, shot);
+ }
}
-void
-checkShotIsInTuxScreen(arena_t * arena)
+void checkShotIsInTuxScreen(arena_t * arena)
{
- int screen_x, screen_y;
- tux_t *thisTux;
- client_t *thisClient;
- list_t *listClient;
- int i;
+ int screen_x, screen_y;
+ tux_t *thisTux;
+ client_t *thisClient;
+ list_t *listClient;
+ int i;
- if (getNetTypeGame() != NET_GAME_TYPE_SERVER) {
- return;
- }
+ if (getNetTypeGame() != NET_GAME_TYPE_SERVER) {
+ return;
+ }
- listClient = getListServerClient();
+ listClient = getListServerClient();
- for (i = 0; i < listClient->count; i++) {
- thisClient = (client_t *) listClient->list[i];
- thisTux = (tux_t *) thisClient->tux;
- int del = 0;
+ for (i = 0; i < listClient->count; i++) {
+ thisClient = (client_t *) listClient->list[i];
+ thisTux = (tux_t *) thisClient->tux;
+ int del = 0;
- if (thisTux == NULL || thisTux->control != TUX_CONTROL_NET) {
- continue;
- }
+ if (thisTux == NULL || thisTux->control != TUX_CONTROL_NET) {
+ continue;
+ }
- getCenterScreen(&screen_x, &screen_y, thisTux->x, thisTux->y,
- WINDOW_SIZE_X, WINDOW_SIZE_Y);
+ getCenterScreen(&screen_x, &screen_y, thisTux->x, thisTux->y,
+ WINDOW_SIZE_X, WINDOW_SIZE_Y);
- actionSpaceFromLocation(arena->spaceShot, action_check,
- thisClient, screen_x, screen_y, WINDOW_SIZE_X,
- WINDOW_SIZE_Y);
+ actionSpaceFromLocation(arena->spaceShot, action_check,
+ thisClient, screen_x, screen_y, WINDOW_SIZE_X,
+ WINDOW_SIZE_Y);
- while (thisClient->listSeesShot->count > 100) {
- delListItem(thisClient->listSeesShot, 0, free);
- del++;
- }
+ while (thisClient->listSeesShot->count > 100) {
+ delListItem(thisClient->listSeesShot, 0, free);
+ del++;
+ }
- //if( del > 0 )printf("del = %d\n", del);
- }
+ //if( del > 0 )printf("del = %d\n", del);
+ }
}
-void
-destroyShot(shot_t * p)
+void destroyShot(shot_t * p)
{
- assert(p != NULL);
+ assert(p != NULL);
- delID(p->id);
+ delID(p->id);
- free(p);
+ free(p);
}
-void
-quitShot()
+void quitShot()
{
- isShotInit = FALSE;
+ isShotInit = FALSE;
}