[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[palito-dev] server sketch
From: |
barrett |
Subject: |
[palito-dev] server sketch |
Date: |
18 Jan 2003 01:36:10 -0000 |
//---------------------------------------------------------------------------
int main(int argc, char *argv[])
{
print_welcome();
network_init();
while() {
tv = wait_period;
do {
fd_set(rin, fileno(stdin));
foreach fd_set(rin, player[i]->fd);
start_select = get_ticks;
if(select rin, tv) {
foreach player
if fd_isset(pl[i]->fd)
process_command(i);
if fd_isset(rin 0)
process_command(0);
}
spent_on_select = get_ticks - start_select;
tv -= spent_on_select;
} while (tv>0);
start_gameloop = get_ticks;
game_tick();
spent_on_gameloop = get_ticks - start_gameloop;
wait_period = frame_period - spent_on_gameloop;
}
return 0;
}
//---------------------------------------------------------------------------
void process_command(Client *client, char *cmd)
{
char *tok = *cmd;
switch(tok) {
map;
server settings;
join {
if(id = next_token)
join as player id;
else
return new_player->id;
}
status {
playerlist
maplist
orderlist [player] [unit]
}
client != NULL && command {
unit = next_token(&tok);
if(append|prepend|insert|delete) {
if(insert|delete)
order_idx = next_token;
order_type = next_token(&tok);
if(move|build|attack)
target = next_token;
else if(kill)
kill();
}
else if(group) {
group_id = next_token;
group_op = next_token;
units = next_tokens;
}
}
}
}
//---------------------------------------------------------------------------
void game_tick()
{
// allocate unit slots with orders
foreach player
foreach unit
use_slots = 0
// decide what to do
foreach order // inherit group?
req_slots = 0
"move"
if too_far
req_slots |= 1<<MOVE
else
accomplished = 1
"attack"
if target dead
accomplished = 1
break
foreach weapon
if used_slot & 1<<weapon_slot_id
if (target_fly && weapon->is_air)
|| (!target_fly && !weapon->is_air)
req_slots |= 1<<weapon
range = weapon_range
//FIXME move even if one
// weapon already reaching?
"build"
if target_built
accomplished =1
req_slots |= 1<<NANO
range = nano_range
"follow"
"guard"
...
if dist_to_target > range
req_slots |= 1<<MOVE
if accomplished
pop_order
continue
if req_slots & use_slots
continue
use_slots |= req_slots;
foreach slot
MOVE
unit->slot[MOVE]
target = order->target - range
path//finding
WEAPON1
WEAPON2
WEAPON3
WEAPON4
unit->slot[1<<weapon]
target = order->target
//allocate resources
NANO
unit->slot[MOVE]
target = order->target - range
path//finding
//allocate resources
end //foreach order
// alocate unused slots on automatic tasks
foreach slot
MOVE
wander around
WEAPON1
WEAPON2
WEAPON3
WEAPON4
//shoot someone!
//plane, trains and automobiles
//allocate resources
NANO
//nanolate something!
//patrol! get wreckage!
//do something utile of your life!
//FIXME make nano like a specialized weapon
// nano shoots friends and building stuff
//allocate resources
end //foreach slot
if once_in_a_while
//check communication with commander
if once_in_a_while
//add visual area on visualization map
//FIXME visualization map is like
//the commander communication check
//(but to the enemy commander?)
end //foreach unit
end //foreach player
foreach player
foreach unit
// finally do the physics and other shit
foreach slot
MOVE
//change angle/speed
WEAPON
//spend energy/metal
//aim
//spawn shot
if in_communication_with_commander
send player unit
foreach other_player
if in visualization_map
send other_player unit
//FIXME visualization map is like
//the commander communication check
//(but to the enemy commander?)
end //foreach unit
end //foreach player
}
//---------------------------------------------------------------------------
- [palito-dev] server sketch,
barrett <=