int main() { int i; struct s_player *p[NTIMES]; s_entities_init(); s_players_init(); s_vmaps_init(); s_commands_init(); s_tilemaps_init(); struct s_vmap *m = s_vmap_find(0); for (i = 0; i < NTIMES; i++) { char buf[100]; sprintf(buf, "dodo%d\n", i); p[i] = s_player_create(i+2, i, buf); s_player_register(p[i]); } for (i = 0; i < NTIMES; i++) { int x = random()%20; int y = random()%20; s_command_join_map_create(&p[i]->entity, m, x, y); } for (i = 0; i <NTIMES; i++) { char buf[] = "local chat"; s_command_local_chat_create(&p[i]->entity, buf); } for (i = 0; i < NTIMES; i++) s_command_quit_map_create(&p[i]->entity); s_command_dispatch(NTIMES*4); for (i = 0; i < NTIMES; i++) { s_player_unregister(p[i]); s_player_destroy(p[i]); } s_tilemaps_exit(); return 0; }
struct command *bgame_join_map_create(struct dictionary *dict) { int x; int y; struct s_vmap *map; JsonNode *tmp; struct command_join_map *join; /* get map ID */ tmp = json_find_member(dict->json, "map_id"); if (!tmp || tmp->tag != JSON_NUMBER) return NULL; map = s_vmap_find((uint32_t)tmp->number_); if (!map) return NULL; json_delete(tmp); /* get x */ tmp = json_find_member(dict->json, "x"); if (!tmp || tmp->tag != JSON_NUMBER) return NULL; x = (int)tmp->number_; json_delete(tmp); /* get y */ tmp = json_find_member(dict->json, "y"); if (!tmp || tmp->tag != JSON_NUMBER) return NULL; y = (int)tmp->number_; json_delete(tmp); join = malloc(sizeof(struct command_join_map)); if (!join) return NULL; join->vmap = map; join->x = x; join->y = y; join->command.handle = command_join_map_handle; return &join->command; }