Magic number, and (tiny) preparation for multiplayer

Discussions about the internal structures of the game. You can also post here if you'd like to know how things really work (and don't know how to read C code).
Post Reply
GeoVah
Posts: 50
Joined: Sat Dec 18, 2004 10:38 am
Location: Sophia Antipolis - France

Magic number, and (tiny) preparation for multiplayer

Post by GeoVah »

I think you should avoid use magic number, use #define instead.
For example, it's the number of player in team :
you have "players_in_team()== 20" and many other place where you use 20.
I think you should use :
#define MAX_PLAYERS 20 in enums.h
and players_in_team()==MAX_PLAYERS (and replace 20 by MAX_PLAYERS in all place).

If a day you need to increase max players, it's much easy..

More over, if you know all place, add a
#define COMPUTER_PLAYERS_COUNT 20
and use where you have to use it.


More over, maybe start to change player_in_team(void) to player_in_team(int teamID) :
so it can help for some algo who need to know how many, player there is in team, instead
of using a

Code: Select all

void someAlgoForOneTeam(gint team) {
...
 players=(team==myteam)?player_team():COMPUTER_PLAYERS_COUNT
...
}
It can helps when you go to multiplayer (just need to modify player_in_team ..)

:-)
Geovah - geovah@jabber.sk- (yes i'm french...)
gyboth
Site Admin
Posts: 1421
Joined: Sat Dec 18, 2004 8:42 am
Location: Passau, Germany
Contact:

Re: Magic number, and (tiny) preparation for multiplayer

Post by gyboth »

GeoVah wrote:I think you should avoid use magic number, use #define instead.
yes, you're right. there are a lot of hard-coded constants in the Bygfoot code because i learned how to use 'define's and enums etc. gradually while writing and improving the game.

but there won't be any in 1.9, i promise ;-).
More over, maybe start to change player_in_team(void) to player_in_team(int teamID)
this won't be necessary in 1.9, because the players will be in GArrays, and those have a component called 'len'. so if you'd like to know how many players are in a team, you just write

Code: Select all

team.players->len
gyözö
Press any key to continue or any other key to quit.
Post Reply