/************************************************ Fill tx and ty with pixels coordinate of scpecified tile tx and/or ty may be nullptr tx and ty are not modified on error return RET_NOK on error ************************************************/ ret_code_t map_get_tile_coord(const char * map, int layer, int x, int y, int * tx, int * ty) { layer_t * default_layer; if (map == nullptr) { return RET_NOK; } if ((default_layer = map_layer_new(map, DEFAULT_LAYER, nullptr)) == nullptr) { return RET_NOK; } if (tx) { *tx = map_t2p_x(x, y, default_layer); } if (ty) { *ty = map_t2p_y(x, y, default_layer); } map_layer_delete(default_layer); return RET_OK; }
/********************************** Draw the "set" keyword of a layer **********************************/ static void compose_map_set(context_t * ctx, int layer_index) { int i = 0; int x = 0; int y = 0; anim_t * anim; item_t * item; char ** tile_set = NULL; char layer_name[SMALL_BUF]; layer_t * layer; sprintf(layer_name,"%s%d",MAP_KEY_LAYER,layer_index); if(entry_read_list(MAP_TABLE, ctx->map, &tile_set,layer_name,MAP_KEY_SET,NULL) == RET_NOK ) { return; } layer = map_layer_new(ctx->map,layer_index,default_layer); while(tile_set[i] != NULL ) { /* Skip empty tile */ if( tile_set[i][0] != 0 ) { item = item_list_add(&item_list); anim = imageDB_get_anim(ctx,tile_set[i]); item_set_pos(item,map_t2p_x(x,y,layer),map_t2p_y(x,y,layer)); item_set_anim(item,anim,0); } x++; if(x>=layer->map_w) { x=0; y++; } i++; } deep_free(tile_set); map_layer_delete(layer); }
/********************************** Compose the character select screen **********************************/ item_t * scr_play_compose(context_t * ctx) { int bg_red = 0; int bg_blue = 0; int bg_green = 0; char * map_filename; int layer_index = 0; char * old_sfx = NULL; option = option_get(); if(item_list) { item_list_free(item_list); item_list = NULL; } if(ctx->map == NULL ) { if(context_update_from_file(ctx) == RET_NOK) { return NULL; } } if(init) { /* Register this character to receive server notifications */ network_request_start(ctx,ctx->id); ui_play_init(); init = false; } sdl_free_keycb(); sdl_free_mousecb(); sdl_add_mousecb(MOUSE_WHEEL_UP,cb_zoom); sdl_add_mousecb(MOUSE_WHEEL_DOWN,cb_unzoom); change_map = ctx->change_map; if( change_map == true ) { map_filename = strconcat( MAP_TABLE,"/",ctx->map,NULL); network_send_req_file(ctx,map_filename); free(map_filename); if(default_layer) { map_layer_delete(default_layer); } default_layer = map_layer_new(ctx->map,DEFAULT_LAYER,NULL); } if( default_layer && default_layer->active ) { // Make sure map data are available for(layer_index = 0; layer_index < MAX_LAYER; layer_index++) { compose_map_set(ctx,layer_index); compose_map_scenery(ctx,layer_index); compose_item(ctx,layer_index); compose_sprite(ctx,layer_index); compose_type(ctx,layer_index); } compose_map_button(ctx); compose_select(ctx); ui_play_compose(ctx,item_list); // force virtual coordinate on map change if( change_map == true ) { sdl_force_virtual_x(map_t2p_x(ctx->pos_tx,ctx->pos_ty,default_layer) + default_layer->col_width[ctx->pos_tx%default_layer->col_num]/2 + default_layer->row_width[ctx->pos_ty%default_layer->row_num]/2 ); sdl_force_virtual_y(map_t2p_y(ctx->pos_tx,ctx->pos_ty,default_layer) + default_layer->col_height[ctx->pos_tx%default_layer->col_num]/2 + default_layer->row_height[ctx->pos_ty%default_layer->row_num]/2 ); } // set virtual coordinate on the same map else { sdl_set_virtual_x(map_t2p_x(ctx->pos_tx,ctx->pos_ty,default_layer) + default_layer->col_width[ctx->pos_tx%default_layer->col_num]/2 + default_layer->row_width[ctx->pos_ty%default_layer->row_num]/2 ); sdl_set_virtual_y(map_t2p_y(ctx->pos_tx,ctx->pos_ty,default_layer) + default_layer->col_height[ctx->pos_tx%default_layer->col_num]/2 + default_layer->row_height[ctx->pos_ty%default_layer->row_num]/2 ); } } entry_read_int(MAP_TABLE,ctx->map,&bg_red,MAP_KEY_BG_RED,NULL); entry_read_int(MAP_TABLE,ctx->map,&bg_blue,MAP_KEY_BG_BLUE,NULL); entry_read_int(MAP_TABLE,ctx->map,&bg_green,MAP_KEY_BG_GREEN,NULL); SDL_SetRenderDrawColor(ctx->render, bg_red, bg_blue, bg_green, 255); old_sfx = sfx; sfx = NULL; entry_read_string(MAP_TABLE,ctx->map,&sfx,MAP_SFX,NULL); if(old_sfx) { if( sfx ) { if( strcmp(old_sfx,sfx) ) { sfx_stop(ctx,old_sfx); } } else { // sfx == NULL sfx_stop(ctx,old_sfx); } free(old_sfx); } if( sfx && sfx[0]!=0 ) { sfx_play(ctx,sfx,NO_RESTART); } return item_list; }