Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sends planet info to bots #16

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions config.c
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ void help(void)
printf(" extrapoints selects the extrapoint mode (one out of: off, random, oldest, best\n) (default: best)");
printf(" numdebris number of debris particles on kill (default 10)\n");
printf(" speeddebris speed of debris particles (default 3.0)\n");
printf(" sendplanets send planet positions to bots (0 / 1) (default 0)\n");
printf("\n");
printf(" fullscreen fullscreen enabled (default: 1)\n");
printf(" ratio aspect ratio of battlefield (1.33, 4:3 and 4/3 are valid formats) (default: 16:9)\n");
Expand Down Expand Up @@ -67,6 +68,7 @@ void config(int* argc, char** argv)

conf.numDebrisParticles = 10;
conf.debrisSpeed = 3.0;
conf.sendPlanets = 0;

//debug
conf.debug = 0;
Expand Down Expand Up @@ -213,6 +215,15 @@ void config(int* argc, char** argv)
conf.message = c;
}
}
else if (strcmp(b, "sendplanets") == 0)
{
conf.sendPlanets = atoi(c);
if (conf.sendPlanets < 0 || conf.sendPlanets > 1)
{
printf("sendplanets needs to be 0 or 1\n");
exit(0);
}
}
else if (strcmp(b, "debug") == 0)
{
conf.debug = atoi(c);
Expand Down
1 change: 1 addition & 0 deletions config.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ typedef struct
int extrapoints;
int numDebrisParticles;
double debrisSpeed;
char sendPlanets;
/* debug options */
int fastmode;
int throttle;
Expand Down
26 changes: 26 additions & 0 deletions network.c
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,31 @@ void sendPlayerPos(int i, int p)
snd_l(i, 4, binsend);
}

void sendPlanets(int i)
{
if (conf.sendPlanets == 0)
{
return;
}
if (connection[i].socket && connection[i].bot)
{
int planet_size = sizeof(SimPlanet) / sizeof(uint32_t);
binsend[0] = MSG_PLANETPOS;
binsend[1] = conf.numPlanets;
binsend[2] = sizeof(SimPlanet);
int buf_index = 3;
for (int planet_index = 0; planet_index < conf.numPlanets; planet_index++, buf_index += planet_size)
{
SimPlanet *temp = getPlanet(planet_index);
memcpy(&binsend[buf_index], &temp->position.x, planet_size);
memcpy(&binsend[buf_index+2], &temp->position.y, planet_size);
memcpy(&binsend[buf_index+4], &temp->radius, planet_size);
memcpy(&binsend[buf_index+6], &temp->mass, planet_size);
}
snd_l(connection[i].socket, buf_index, binsend);
}
}

void sendShotFinished(int i, SimShot* s)
{
binsend[0] = MSG_SHOTFINISHED;
Expand Down Expand Up @@ -743,6 +768,7 @@ void stepNetwork(void)
sendGameMode(i, pi);
}
sendOwnId(i, pi);
sendPlanets(pi);
for(pi2 = 0; pi2 < conf.maxPlayers; ++pi2)
{
if(connection[pi2].socket)
Expand Down
2 changes: 2 additions & 0 deletions network.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define MSG_SHOTFIN 6 /* replaces msg 4 */
#define MSG_GAMEMODE 7 /* not sent for bot protocol > 8 */
#define MSG_OWN_ENERGY 8
#define MSG_PLANETPOS 9

#define MODE_REALTIME 3

Expand All @@ -18,6 +19,7 @@
void initNetwork(void);
void stepNetwork(void);

void sendPlanets(int i);
void allSendPlayerPos(int p);
void allSendKillMessage(int p, int p2);
void allSendShotFinished(SimShot* s);
Expand Down
1 change: 1 addition & 0 deletions simulation.c
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,7 @@ void reinitialize(void)
{
initPlayer(pl, 1);
allSendPlayerPos(pl);
sendPlanets(pl);
}
}
mode = MODE_PLAYING;
Expand Down