void load_exploration_map () { FILE *fp = NULL; char exploration_map_filename[256]; if(!minimap_texture) return; my_strcp (exploration_map_filename, map_file_name); exploration_map_filename[strlen(exploration_map_filename)-4] = 0; strcat (exploration_map_filename, ".xm"); safe_strncpy (current_exploration_map_filename, exploration_map_filename, sizeof (current_exploration_map_filename)); fp = open_file_config (exploration_map_filename, "rb"); if(fp) { if (fread(exploration_map, sizeof(GLubyte), 256 * 256, fp) != 256 * 256) { memset(exploration_map, 0, 256 * 256 * sizeof(GLubyte)); LOG_ERROR("%s() read failed for file [%s]\n", __FUNCTION__, exploration_map_filename); } fclose(fp); } else { memset(exploration_map, 0, 256 * 256 * sizeof(GLubyte)); } if(poor_man) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); } else if(use_mipmaps) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE); } else { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); } if(have_extension(arb_texture_compression)) { if(have_extension(ext_texture_compression_s3tc)) glTexImage2D(GL_TEXTURE_2D,0,GL_COMPRESSED_RGB_S3TC_DXT1_EXT, minimap_size, minimap_size,0,GL_LUMINANCE,GL_UNSIGNED_BYTE,&exploration_map); else glTexImage2D(GL_TEXTURE_2D,0,GL_COMPRESSED_LUMINANCE, minimap_size, minimap_size,0,GL_ALPHA,GL_UNSIGNED_BYTE,&exploration_map); } else glTexImage2D(GL_TEXTURE_2D,0,GL_LUMINANCE, minimap_size, minimap_size,0,GL_LUMINANCE,GL_UNSIGNED_BYTE,&exploration_map); CHECK_GL_ERRORS(); }
void unwear_item_from_actor(int actor_id,Uint8 which_part) { int i; for(i=0;i<max_actors;i++) { if(actors_list[i]) if(actors_list[i]->actor_id==actor_id) { if(which_part==KIND_OF_WEAPON) { if(actors_list[i]->cur_weapon == GLOVE_FUR || actors_list[i]->cur_weapon == GLOVE_LEATHER){ my_strcp(actors_list[i]->body_parts->hands_tex, actors_list[i]->body_parts->hands_tex_save); glDeleteTextures(1,&actors_list[i]->texture_id); actors_list[i]->texture_id=load_bmp8_enhanced_actor(actors_list[i]->body_parts, 255); } actors_list[i]->body_parts->weapon=0; actors_list[i]->body_parts->weapon_fn[0]=0; actors_list[i]->body_parts->weapon_tex[0]=0; return; } if(which_part==KIND_OF_SHIELD) { actors_list[i]->body_parts->shield=0; actors_list[i]->body_parts->shield_fn[0]=0; actors_list[i]->body_parts->shield_tex[0]=0; return; } if(which_part==KIND_OF_CAPE) { actors_list[i]->body_parts->cape=0; actors_list[i]->body_parts->cape_fn[0]=0; actors_list[i]->body_parts->cape_tex[0]=0; return; } if(which_part==KIND_OF_HELMET) { actors_list[i]->body_parts->helmet=0; actors_list[i]->body_parts->helmet_fn[0]=0; actors_list[i]->body_parts->helmet_tex[0]=0; return; } return; } } }
void init_actor_defs () { const char *dirname = "actor_defs", *idxname = "actor_defs.xml"; char defdir[120]; int ok; // initialize the whole thing to zero memset (actors_defs, 0, sizeof (actors_defs)); #ifndef WINDOWS snprintf (defdir, sizeof (defdir), "%s/%s", datadir, dirname); #else my_strcp (defdir, dirname); #endif ok = read_actor_defs (defdir, idxname); }
//returns -1 if the name is already ignored, 1 on sucess, -2 if no more ignore slots int add_to_ignore_list(char *name, char save_name) { int i; // never ignore uobeyuok, the rule bot if(!strcasecmp(name, "uobeyuok")){ return(-1); } //see if this name is already on the list for(i=0;i<MAX_IGNORES;i++) { if(ignore_list[i].used) if(my_strcompare(ignore_list[i].name,name))return -1;//already in the list } //ok, find a free spot for(i=0;i<MAX_IGNORES;i++) { if(!ignore_list[i].used) { //excellent, a free spot my_strcp(ignore_list[i].name,name); //add to the global ignore file, if the case if(save_name) { FILE * f=open_file_config("local_ignores.txt", "a"); if (f == NULL){ LOG_ERROR("%s: %s \"local_ignores.txt\": %s\n", reg_error_str, cant_open_file, strerror(errno)); } else { fwrite(name, strlen(name), 1, f); fwrite("\n", 1, 1, f); fclose(f); } } ignore_list[i].used=1;//mark as used ignored_so_far++; return 1; } } return -2;//if we are here, it means the ignores list is full }
void process_message_from_server(unsigned char *in_data, int data_lenght) { //see what kind of data we got switch (in_data[PROTOCOL]) { case RAW_TEXT: { // do filtering and ignoring data_lenght=filter_or_ignore_text(&in_data[3],data_lenght-3)+3; if(data_lenght > 3) { //how to display it if(interface_mode!=interface_opening) put_text_in_buffer(&in_data[3],data_lenght-3,0); else put_text_in_buffer(&in_data[3],data_lenght-3,54); //lets log it write_to_log(&in_data[3],data_lenght-3); } } break; case SMALL_WINDOW_TEXT: { add_text_to_small_text_buffer(in_data+3, data_lenght-3); display_small_text_window(); } break; case ADD_NEW_ACTOR: { add_actor_from_server(&in_data[3]); } break; case ADD_NEW_ENHANCED_ACTOR: { add_enhanced_actor_from_server(&in_data[3]); } break; case ADD_ACTOR_COMMAND: { add_command_to_actor(*((short *)(in_data+3)),in_data[5]); } break; case REMOVE_ACTOR: { destroy_actor(*((short *)(in_data+3))); } break; case KILL_ALL_ACTORS: { destroy_all_actors(); } break; case NEW_MINUTE: { game_minute=*((short *)(in_data+3)); new_minute(); } break; case LOG_IN_OK: { interface_mode=interface_game; previously_logged_in=1; } break; case HERE_YOUR_STATS: { get_the_stats((Sint16 *)(in_data+3)); } break; case SEND_PARTIAL_STAT: { get_partial_stat(*((Uint8 *)(in_data+3)),*((Sint32 *)(in_data+4))); } break; case GET_KNOWLEDGE_LIST: { get_knowledge_list(*(Uint16 *)(in_data+1)-1, in_data+3); } break; case GET_NEW_KNOWLEDGE: { get_new_knowledge(*(Uint16 *)(in_data+3)); } break; case HERE_YOUR_INVENTORY: { get_your_items(in_data+3); } break; case GET_NEW_INVENTORY_ITEM: { get_new_inventory_item(in_data+3); } break; case REMOVE_ITEM_FROM_INVENTORY: { remove_item_from_inventory(*((Uint8 *)(in_data+3))); } break; case INVENTORY_ITEM_TEXT: { put_small_text_in_box(&in_data[3],data_lenght-3,6*51+100,items_string); if(!(get_show_window(items_win)||get_show_window(trade_win))) { put_text_in_buffer(&in_data[3],data_lenght-3,0); } } break; case GET_KNOWLEDGE_TEXT: { put_small_text_in_box(&in_data[3],data_lenght-3,6*51+150,knowledge_string); } break; case CHANGE_MAP: { current_sector=-1; if(map_file_name[0]!=0) save_map(map_file_name); object_under_mouse=-1;//to prevent a nasty crash, while looking for bags, when we change the map close_dialogue(); // close the dialogue window if open destroy_all_particles(); if(!load_map(&in_data[4])){ // creating map if it does not exist int size=(in_data[3]&0x1f)<<4; new_map(size,size); dungeon=(in_data[3]&0x20)?1:0; strcpy(map_file_name,&in_data[4]); save_map(map_file_name); } kill_local_sounds(); #ifndef NO_MUSIC playing_music=0; #endif //NO_MUSIC get_map_playlist(); have_a_map=1; //also, stop the rain seconds_till_rain_starts=-1; seconds_till_rain_stops=-1; is_raining=0; rain_sound=0;//kill local sounds also kills the rain sound weather_light_offset=0; rain_light_offset=0; } break; case GET_TELEPORTERS_LIST: { add_teleporters_from_list(&in_data[3]); } break; case PLAY_MUSIC: { if(!no_sound)play_music(*((short *)(in_data+3))); } break; case PLAY_SOUND: { if(!no_sound)add_sound_object(*((short *)(in_data+3)),*((short *)(in_data+5)),*((short *)(in_data+7)),*((char *)(in_data+9)),*((short *)(in_data+10))); } break; case TELEPORT_OUT: { add_particle_sys_at_tile("./particles/teleport_in.part",*((short *)(in_data+3)),*((short *)(in_data+5))); if(!no_sound)add_sound_object(snd_tele_out,*((short *)(in_data+3)),*((short *)(in_data+5)),1,0); } break; case TELEPORT_IN: { add_particle_sys_at_tile("./particles/teleport_in.part",*((short *)(in_data+3)),*((short *)(in_data+5))); if(!no_sound)add_sound_object(snd_tele_in,*((short *)(in_data+3)),*((short *)(in_data+5)),1,0); } break; case LOG_IN_NOT_OK: { sprintf(log_in_error_str,"%s: %s",reg_error_str,invalid_pass); } break; case REDEFINE_YOUR_COLORS: { strcpy(log_in_error_str,redefine_your_colours); } break; case YOU_DONT_EXIST: { sprintf(log_in_error_str,"%s: %s",reg_error_str,char_dont_exist); } break; case CREATE_CHAR_NOT_OK: { sprintf(create_char_error_str,"%s: %s",reg_error_str,char_name_in_use); return; } break; case CREATE_CHAR_OK: { login_from_new_char(); } break; case YOU_ARE: { yourself=*((short *)(in_data+3)); } break; case START_RAIN: { seconds_till_rain_starts=*((Uint8 *)(in_data+3)); seconds_till_rain_stops=-1; } break; case STOP_RAIN: { seconds_till_rain_stops=*((Uint8 *)(in_data+3)); seconds_till_rain_starts=-1; } break; case THUNDER: { add_thunder(rand()%5,*((Uint8 *)(in_data+3))); } break; case SYNC_CLOCK: { server_time_stamp=*((int *)(in_data+3)); client_time_stamp=SDL_GetTicks(); client_server_delta_time=server_time_stamp-client_time_stamp; } break; case PONG: { Uint8 str[160]; sprintf(str,"%s: %i MS",server_latency, SDL_GetTicks()-*((Uint32 *)(in_data+3))); log_to_console(c_green1,str); } break; case UPGRADE_NEW_VERSION: { log_to_console(c_red1,update_your_client); log_to_console(c_red1,(char*)web_update_address); } break; case UPGRADE_TOO_OLD: { log_to_console(c_red1,client_ver_not_supported); log_to_console(c_red1,(char*)web_update_address); this_version_is_invalid=1; } break; case GET_NEW_BAG: { put_bag_on_ground(*((Uint16 *)(in_data+3)),*((Uint16 *)(in_data+5)),*((Uint8 *)(in_data+7))); } break; case GET_BAGS_LIST: { add_bags_from_list(&in_data[3]); } break; case SPAWN_BAG_PARTICLES: { add_particle_sys_at_tile("./particles/bag_in.part",*((Uint16 *)(in_data+3)),*((Uint16 *)(in_data+5))); } break; case GET_NEW_GROUND_ITEM: { get_bag_item(in_data+3); } break; case HERE_YOUR_GROUND_ITEMS: { get_bags_items_list(&in_data[3]); } break; case CLOSE_BAG: { hide_window(ground_items_win); } break; case REMOVE_ITEM_FROM_GROUND: { remove_item_from_ground(in_data[3]); } break; case DESTROY_BAG: { remove_bag(in_data[3]); } break; case NPC_TEXT: { put_small_text_in_box(&in_data[3],data_lenght-3,dialogue_menu_x_len-70,dialogue_string); display_dialogue(); if(in_data[3]>=127 && in_data[4]>=127) { add_questlog(&in_data[4],data_lenght-4); } } break; case SEND_NPC_INFO: { my_strcp(npc_name,&in_data[3]); cur_portrait=in_data[23]; } break; case NPC_OPTIONS_LIST: { build_response_entries(&in_data[3],*((Uint16 *)(in_data+1))); } break; case GET_TRADE_ACCEPT: { if(!in_data[3])trade_you_accepted=1; else trade_other_accepted=1; } break; case GET_TRADE_REJECT: { if(!in_data[3])trade_you_accepted=0; else trade_other_accepted=0; } break; case GET_TRADE_EXIT: { hide_window(trade_win); } break; case GET_YOUR_TRADEOBJECTS: { get_your_trade_objects(in_data+3); } break; case GET_TRADE_OBJECT: { put_item_on_trade(in_data+3); } break; case REMOVE_TRADE_OBJECT: { remove_item_from_trade(in_data+3); } break; case GET_TRADE_PARTNER_NAME: { get_trade_partner_name(&in_data[3],*((Uint16 *)(in_data+1))-1); } break; case GET_ACTOR_DAMAGE: { get_actor_damage(*((Uint16 *)(in_data+3)),in_data[5]); } break; case GET_ACTOR_HEAL: { get_actor_heal(*((Uint16 *)(in_data+3)),in_data[5]); } break; case ACTOR_UNWEAR_ITEM: { unwear_item_from_actor(*((Uint16 *)(in_data+3)),in_data[5]); } break; case ACTOR_WEAR_ITEM: { actor_wear_item(*((Uint16 *)(in_data+3)),in_data[5],in_data[6]); } break; case NPC_SAY_OVERTEXT: { add_displayed_text_to_actor( get_actor_ptr_from_id( *((Uint16 *)(in_data+3)) ), in_data+5 ); } break; case BUDDY_EVENT: { if(in_data[3]==1) add_buddy(&in_data[5],in_data[4],data_lenght-5); else if(in_data[3]==0) del_buddy(&in_data[4],data_lenght-4); } break; // BARREN MOON NEW MESSAGES case THIS_IS_ACTIVE_SECTOR: active_sector=*((Uint16 *)(in_data+3)); break; case GET_TILE_DATA: get_tile_data(in_data+3); break; case GET_3D_OBJECTS: get_3d_objects(in_data+3); break; case GET_2D_OBJECTS: get_2d_objects(in_data+3); break; case GET_LIGHT_OBJECTS: get_light_objects(in_data+3); break; case GET_PARTICLE_OBJECTS: get_particle_objects(in_data+3); break; case GET_3D_OBJECTS_FULL_ROTATION: get_3d_objects_full_rotation(in_data+3); break; case GET_CHECKSUMS: { actor *actor=pf_get_our_actor(); get_checksums(in_data+3, sector_get(actor->x_pos,actor->y_pos)); break; } case ADD_3D_OBJECT: add_3d_object(in_data+3); break; case ADD_3D_OBJECT_FULL_ROTATION: add_3d_object_fullrotation(in_data+3); break; case DELETE_3D_OBJECT: delete_3d_object(in_data+3); break; case REPLACE_3D_OBJECT: replace_3d_object(in_data+3); break; case ADD_2D_OBJECT: add_2d_object(in_data+3); break; case DELETE_2D_OBJECT: delete_2d_object(in_data+3); break; case REPLACE_2D_OBJECT: replace_2d_object(in_data+3); break; case ADD_LIGHT: add_lights(in_data+3); break; case DELETE_LIGHT: delete_light(in_data+3); break; case ADD_PARTICLE: add_particle(in_data+3); break; case DELETE_PARTICLE: delete_particle(in_data+3); break; case REPLACE_PARTICLE: replace_particle(in_data+3); break; default: { /* Unknown data type?? */; } break; } }
int switch_to_game_map() { #ifdef NEW_TEXTURES char buffer[1024]; #else /* NEW_TEXTURES */ int len; texture_cache_struct tex; #endif /* NEW_TEXTURES */ short int cur_cont; static short int old_cont = -1; /* check we loaded the mapinfo data */ if (continent_maps == NULL || continent_maps[0].name == NULL) { LOG_TO_CONSOLE(c_yellow2,err_nomap_str); return 0; } #ifdef NEW_TEXTURES if (check_image_name(map_file_name, sizeof(buffer), buffer) == 1) { map_text = load_texture_cached(buffer, tt_image); } else { map_text = 0; } #else /* NEW_TEXTURES */ my_strcp(tex.file_name,map_file_name); len=strlen(tex.file_name); tex.file_name[len-3]='b'; tex.file_name[len-2]='m'; tex.file_name[len-1]='p'; tex.alpha = 128; if (!el_file_exists(tex.file_name)) map_text = 0; else map_text=load_bmp8_fixed_alpha(&tex, tex.alpha); #endif /* NEW_TEXTURES */ if(!map_text) { LOG_TO_CONSOLE(c_yellow2,err_nomap_str); return 0; } if (cur_map < 0) { cur_cont = -1; } else { cur_cont = continent_maps[cur_map].cont; } if (cur_cont != old_cont && cur_cont >= 0 && cur_cont < nr_continents) { #ifdef NEW_TEXTURES cont_text = load_texture_cached (cont_map_file_names[cur_cont], tt_image); #else /* NEW_TEXTURES */ cont_text = load_texture_cache (cont_map_file_names[cur_cont], 128); #endif /* NEW_TEXTURES */ old_cont = cur_cont; } #ifdef DEBUG_MAP_SOUND cur_tab_map = cur_map; #endif // DEBUG_MAP_SOUND if(current_cursor != CURSOR_ARROW) { change_cursor(CURSOR_ARROW); } return 1; }
void change_minimap(){ char minimap_file_name[256]; #ifndef NEW_TEXTURES texture_cache_struct tex; #endif /* NEW_TEXTURES */ if(minimap_win < 0) return; //save_exploration_map(); #ifdef NEW_TEXTURES //unload all textures if(exploration_texture) glDeleteTextures(1,&exploration_texture); //make filename if (check_image_name(map_file_name, sizeof(minimap_file_name), minimap_file_name) == 1) { minimap_texture = load_texture_cached(minimap_file_name, tt_image); } else { minimap_texture = 0; } compass_tex = load_texture_cached("./textures/compass", tt_gui); #else /* NEW_TEXTURES */ //unload all textures if(minimap_texture) glDeleteTextures(1,&minimap_texture); if(compass_tex) glDeleteTextures(1,&compass_tex); if(exploration_texture) glDeleteTextures(1,&exploration_texture); //make filename my_strcp(minimap_file_name,map_file_name); minimap_file_name[strlen(minimap_file_name)-4] = '\0'; strcat(minimap_file_name, ".bmp"); //load textures my_strcp(tex.file_name, minimap_file_name); if (!el_file_exists(minimap_file_name)) minimap_texture = 0; else minimap_texture = load_bmp8_fixed_alpha(&tex,128); my_strcp(tex.file_name, "./textures/compass.bmp"); compass_tex = load_bmp8_fixed_alpha_with_transparent_color(&tex,255,0,0,0); #endif /* NEW_TEXTURES */ glGenTextures(1, &exploration_texture); bind_texture_id(exploration_texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); //load_exploration_map(); #ifdef OPENGL_TRACE CHECK_GL_ERRORS(); #endif //OPENGL_TRACE }
int load_font_textures () { #ifndef NEW_TEXTURES int poor_man_save=poor_man; int use_mipmaps_save=use_mipmaps; #endif /* NEW_TEXTURES */ size_t i = 0; char *glob_pattern; #ifdef WINDOWS struct _finddata_t c_file; long hFile; #else //WINDOWS int ret; glob_t glob_res; size_t j; #endif //WINDOWS char file[60] = ""; char str[60] = ""; if (fonts[0] == NULL || fonts[1] == NULL || fonts[2] == NULL || fonts[3]==NULL ) { for (i = 0; i < FONTS_ARRAY_SIZE; i++) { if (fonts[i] != NULL) free (fonts[i]); fonts[i] = NULL; } if ( !init_fonts () ) return 0; } #ifndef NEW_TEXTURES poor_man=0; use_mipmaps=0; #endif /* NEW_TEXTURES */ #ifdef NEW_TEXTURES fonts[0]->texture_id = load_texture_cached("textures/font.dds", tt_font); #else /* NEW_TEXTURES */ fonts[0]->texture_id = load_texture_cache("./textures/font.bmp", 0); #endif /* NEW_TEXTURES */ i = 1; // Force the selection of the base font. add_multi_option("chat_font", "Type 1"); add_multi_option("name_font", "Type 1"); // Find what font's exist and load them glob_pattern = malloc(strlen(datadir)+sizeof(texture_dir)+10+1); //+10 = font*.bmp* #ifdef NEW_TEXTURES sprintf(glob_pattern, "%s%sfont*.dds", datadir, texture_dir); #else /* NEW_TEXTURES */ sprintf(glob_pattern, "%s%sfont*.bmp*", datadir, texture_dir); #endif /* NEW_TEXTURES */ #ifdef WINDOWS if( (hFile = _findfirst( glob_pattern, &c_file )) == -1L ){ free(glob_pattern); return 0; } do { int len; safe_strncpy(file, c_file.name, sizeof(file)); #else //!WINDOWS ret = glob(glob_pattern, 0, NULL, &glob_res); if(ret != 0) { LOG_ERROR("Unable to find any font textures\n"); free(glob_pattern); return 0; } j = 0; while (j < glob_res.gl_pathc && i < FONTS_ARRAY_SIZE) { int len; safe_strncpy(file, glob_res.gl_pathv[j]+sizeof(texture_dir)-1+strlen(datadir), sizeof(file)); #endif //WINDOWS len= strlen(file); #ifdef NEW_TEXTURES if (((len + sizeof(texture_dir) - 1) < sizeof(str)) && !strncasecmp(file, "font", 4) && has_suffix(file, len, ".dds", 4)) { safe_snprintf(str, sizeof(str), "./textures/%s", file); //Use a relative path here, load_texture_cache_deferred() is using the path wrappers. file[len - 4] = 0; fonts[i]->texture_id = load_texture_cached(str, tt_font); #else /* NEW_TEXTURES */ if (len+sizeof(texture_dir)-1 < sizeof(str) && !strncasecmp(file, "font", 4) && (has_suffix(file, len, ".bmp", 4) || has_suffix(file, len, ".bmp.gz", 7)) && (!has_suffix(file, len, "_alpha.bmp", 10)) && (!has_suffix(file, len, "_alpha.bmp.gz", 13))) { // Get the filename, remove the .bmp and add _alpha.bmp to a copy, then replace the .bmp safe_snprintf(str, sizeof(str), "./textures/%s", file); //Use a relative path here, load_texture_cache_deferred() is using the path wrappers. if(has_suffix(file, len, ".bmp.gz", 7)){ file[len - 7]= 0; } else { file[len - 4]= 0; } fonts[i]->texture_id = load_texture_cache_deferred(str, 0); #endif /* NEW_TEXTURES */ safe_snprintf(font_names[i], sizeof(font_names[i]), "Type %i - %s", i + 1, file); add_multi_option("chat_font", font_names[i]); add_multi_option("name_font", font_names[i]); i++; } #ifndef WINDOWS j++; #endif //WINDOWS } #ifdef WINDOWS while ( _findnext( hFile, &c_file ) == 0 ); _findclose( hFile ); #else //!WINDOWS globfree(&glob_res); #endif //WINDOWS free(glob_pattern); #ifndef NEW_TEXTURES poor_man=poor_man_save; use_mipmaps=use_mipmaps_save; #endif /* NEW_TEXTURES */ //set the default font cur_font_num = 0; font_text = fonts[0]->texture_id; return 1; } int set_font_parameters (int num) { int i; // error checking if(num < 0 || num >= FONTS_ARRAY_SIZE) { return -1; } // allocate space if needed if(fonts[num] == NULL) { fonts[num]=(font_info *)calloc(1, sizeof(font_info)); if(fonts[num] == NULL) { LOG_ERROR(cant_load_font); return -1; } } //watch the highest font if(num >= max_fonts) { max_fonts=num+1; } // set default font info my_strcp (fonts[num]->name, "default"); fonts[num]->spacing=0; // load font information // TODO: write this and remove the hack! if(num!=1||num!=2)for(i=0; i<FONTS_ARRAY_SIZE*FONT_CHARS_PER_LINE; i++) fonts[num]->widths[i]=12; if(num==1){ static int widths[]={ 4,2,7,11,8,12,12,2,7,7,9,10,3,8, 2,10,10,10,8,8,10,7,9,9,9,9,3,3, 10,10,10,9,12,12,9,10,10,9,9,10,9,8, 7,11,8,11,10,11,9,11,11,9,10,9,12,12, 12,12,10,6,10,6,10,12,3,11,9,9,9,9, 8,9,9,4,6,10,4,11,9,10,9,9,8,8, 8,9,10,12,10,10,9,8,2,8,10,8,12,12, 12,12,12,12,12,12,12,12,12,12,12,12,12,12, 12,12,12,12,12,12,12,12,12,12,12,12,12,12, 12,12,12,12,12,12,12,12,12,12,12,12,12,12, }; memcpy(fonts[num]->widths, widths, sizeof(widths)); fonts[num]->spacing=4; } if(num==2){ static int widths[]={ 8, 8, 8, 10, 8, 10, 10, 8, 8, 8, 8, 10, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 10, 10, 10, 8, 12, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 8, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 8, 8, 8, 8, 8, 8, 8, 10, 8, 8, 8, 8, 8, 8, 10, 8, 8, 8, 8, 8, 8, 8, 8, 8, 10, 8, 8, 8, 10, 8, 10, 10, 8, 10, 8, 8, 8, 10, 10, 10, 8, 10, 10, 8, 8, 8, 12, 12, 12, 10, 10, 12, 10, 12, 12, 12, }; memcpy(fonts[num]->widths, widths, sizeof(widths)); fonts[num]->spacing=2; } //and return return num; } int set_font(int num) { if(num >= 0 && num < max_fonts && fonts[num] && fonts[num]->texture_id >= 0) { cur_font_num=num; font_text=fonts[cur_font_num]->texture_id; } return cur_font_num; }
static int do_load_map(const char *file_name, update_func *update_function) { int i; int cur_tile, j; AABBOX bbox; map_header cur_map_header; char* file_mem; #ifdef CLUSTER_INSIDES char* occupied = 0; int have_clusters; #endif object3d_io* objs_3d; obj_2d_io* objs_2d; light_io* lights; particles_io* particles; #ifndef FASTER_MAP_LOAD float progress; #endif el_file_ptr file; file = el_open(file_name); if (!file) { return 0; } #ifdef EXTRA_DEBUG ERR(); #endif file_mem = el_get_pointer(file); my_strcp(map_file_name, file_name); LOG_DEBUG("Loading map '%s'.", file_name); main_bbox_tree_items = create_bbox_items(1024); memcpy(&cur_map_header, file_mem, sizeof(cur_map_header)); cur_map_header.tile_map_x_len = SDL_SwapLE32(cur_map_header.tile_map_x_len); cur_map_header.tile_map_y_len = SDL_SwapLE32(cur_map_header.tile_map_y_len); cur_map_header.tile_map_offset = SDL_SwapLE32(cur_map_header.tile_map_offset); cur_map_header.height_map_offset = SDL_SwapLE32(cur_map_header.height_map_offset); cur_map_header.obj_3d_struct_len = SDL_SwapLE32(cur_map_header.obj_3d_struct_len); cur_map_header.obj_3d_no = SDL_SwapLE32(cur_map_header.obj_3d_no); cur_map_header.obj_3d_offset = SDL_SwapLE32(cur_map_header.obj_3d_offset); cur_map_header.obj_2d_struct_len = SDL_SwapLE32(cur_map_header.obj_2d_struct_len); cur_map_header.obj_2d_no = SDL_SwapLE32(cur_map_header.obj_2d_no); cur_map_header.obj_2d_offset = SDL_SwapLE32(cur_map_header.obj_2d_offset); cur_map_header.lights_struct_len = SDL_SwapLE32(cur_map_header.lights_struct_len); cur_map_header.lights_no = SDL_SwapLE32(cur_map_header.lights_no); cur_map_header.lights_offset = SDL_SwapLE32(cur_map_header.lights_offset); cur_map_header.ambient_r = SwapLEFloat(cur_map_header.ambient_r); cur_map_header.ambient_g = SwapLEFloat(cur_map_header.ambient_g); cur_map_header.ambient_b = SwapLEFloat(cur_map_header.ambient_b); cur_map_header.particles_struct_len = SDL_SwapLE32(cur_map_header.particles_struct_len); cur_map_header.particles_no = SDL_SwapLE32(cur_map_header.particles_no); cur_map_header.particles_offset = SDL_SwapLE32(cur_map_header.particles_offset); #ifdef CLUSTER_INSIDES cur_map_header.clusters_offset = SDL_SwapLE32(cur_map_header.clusters_offset); #endif LOG_DEBUG("Checking map '%s' file signature.", file_name); //verify if we have a valid file if(cur_map_header.file_sig[0]!='e'|| cur_map_header.file_sig[1]!='l'|| cur_map_header.file_sig[2]!='m'|| cur_map_header.file_sig[3]!='f') { LOG_ERROR(invalid_map, map_file_name); exit_now = 1; // We might as well quit... el_close(file); return 0; } LOG_DEBUG("Checking map '%s' sizes.", file_name); // Check the sizes of structures. If they don't match, we have a // major problem, since these structures are supposed to be // written flat out to disk. if (cur_map_header.obj_3d_struct_len != sizeof (object3d_io) || cur_map_header.obj_2d_struct_len != sizeof (obj_2d_io) || cur_map_header.lights_struct_len != sizeof (light_io) || (cur_map_header.particles_struct_len != sizeof (particles_io) && cur_map_header.particles_no > 0) ) { LOG_ERROR ("Invalid object size on map %s", map_file_name); exit_now = 1; // We might as well quit... el_close(file); return 0; } update_function(load_map_str, 0); //get the map size tile_map_size_x = cur_map_header.tile_map_x_len; tile_map_size_y = cur_map_header.tile_map_y_len; LOG_DEBUG("Map '%s' size <%d, %d>.", file_name, tile_map_size_x, tile_map_size_y); // allocate the tile map (it was destroyed), and fill it tile_map = calloc (tile_map_size_x*tile_map_size_y, 1); memcpy(tile_map, file_mem + cur_map_header.tile_map_offset, tile_map_size_x*tile_map_size_y); begin_managing_memchunk(tile_map); // allocate the height map, and fill it height_map = calloc (tile_map_size_x*tile_map_size_y*6*6, 1); memcpy(height_map, file_mem + cur_map_header.height_map_offset, tile_map_size_x*tile_map_size_y*6*6); begin_managing_memchunk(height_map); #ifdef CLUSTER_INSIDES // check if we need to compute the clusters, or if they're stored // in the map have_clusters = (cur_map_header.clusters_offset > 0) && ((cur_map_header.clusters_offset + tile_map_size_x * tile_map_size_y * 6 * 6 * sizeof(short)) <= el_get_size(file)); LOG_DEBUG("Map '%s' has clusters: %d.", file_name, have_clusters); if (have_clusters) { // clusters are stored in the map, set them set_clusters (file_mem + cur_map_header.clusters_offset); } else { // We need to compute the clusters, allocate memory for // the occupation array, and initialize it with the // tile and height maps occupied = calloc (tile_map_size_x*tile_map_size_y*6*6, 1); update_occupied_with_tile_map (occupied, tile_map); update_occupied_with_height_map (occupied, height_map); } #endif LOG_DEBUG("Map '%s' is dungeon %d and ambient <%f, %f, %f>.", file_name, cur_map_header.dungeon, cur_map_header.ambient_r, cur_map_header.ambient_g, cur_map_header.ambient_b); //get the type of map, and the ambient light dungeon = cur_map_header.dungeon; ambient_r = cur_map_header.ambient_r; ambient_g = cur_map_header.ambient_g; ambient_b = cur_map_header.ambient_b; /* water_tiles_extension = (tile_map_size_x > tile_map_size_y ? */ /* tile_map_size_x : tile_map_size_y * 1.5); */ /* if (water_tiles_extension < 500.0) */ /* water_tiles_extension = 500.0 - water_tiles_extension; */ /* else */ /* water_tiles_extension = 0.0; */ LOG_DEBUG("Loading tiles"); //load the tiles in this map, if not already loaded load_map_tiles(); LOG_DEBUG("Initializing buffers"); init_buffers(); #ifndef CLUSTER_INSIDES for(i = 0; i < tile_map_size_y; i++) { bbox.bbmin[Y] = i*3.0f; bbox.bbmax[Y] = (i+1)*3.0f; if (i == 0) bbox.bbmin[Y] -= water_tiles_extension; else if (i == tile_map_size_y-1) bbox.bbmax[Y] += water_tiles_extension; for(j = 0; j < tile_map_size_x; j++) { cur_tile = tile_map[i*tile_map_size_x+j]; if (cur_tile != 255) { bbox.bbmin[X] = j*3.0f; bbox.bbmax[X] = (j+1)*3.0f; if (j == 0) bbox.bbmin[X] -= water_tiles_extension; else if (j == tile_map_size_x-1) bbox.bbmax[X] += water_tiles_extension; if (IS_WATER_TILE(cur_tile)) { bbox.bbmin[Z] = -0.25f; bbox.bbmax[Z] = -0.25f; if (IS_REFLECTING(cur_tile)) add_water_to_list(main_bbox_tree_items, get_terrain_id(j, i), bbox, cur_tile, 1); else add_water_to_list(main_bbox_tree_items, get_terrain_id(j, i), bbox, cur_tile, 0); } else { bbox.bbmin[Z] = 0.0f; bbox.bbmax[Z] = 0.0f; add_terrain_to_list(main_bbox_tree_items, get_terrain_id(j, i), bbox, cur_tile); } } } } #endif // CLUSTER_INSIDES #ifdef FASTER_MAP_LOAD update_function(load_3d_object_str, 20.0f); #else // FASTER_MAP_LOAD progress = (cur_map_header.obj_3d_no + 249) / 250; if (progress > 0.0f) { update_function(load_3d_object_str, 0.0f); progress = 20.0f / progress; } else { update_function(load_3d_object_str, 20.0f); progress = 0.0f; } #endif // FASTER_MAP_LOAD LOG_DEBUG("Loading %d 3d objects.", cur_map_header.obj_3d_no); //read the 3d objects #ifndef FASTER_MAP_LOAD clear_objects_list_placeholders(); #endif objs_3d = (object3d_io*) (file_mem + cur_map_header.obj_3d_offset); ENTER_DEBUG_MARK("load 3d objects"); for (i = 0; i < cur_map_header.obj_3d_no; i++) { object3d_io cur_3d_obj_io = objs_3d[i]; cur_3d_obj_io.x_pos = SwapLEFloat (cur_3d_obj_io.x_pos); cur_3d_obj_io.y_pos = SwapLEFloat (cur_3d_obj_io.y_pos); cur_3d_obj_io.z_pos = SwapLEFloat (cur_3d_obj_io.z_pos); cur_3d_obj_io.x_rot = SwapLEFloat (cur_3d_obj_io.x_rot); cur_3d_obj_io.y_rot = SwapLEFloat (cur_3d_obj_io.y_rot); cur_3d_obj_io.z_rot = SwapLEFloat (cur_3d_obj_io.z_rot); cur_3d_obj_io.r = SwapLEFloat (cur_3d_obj_io.r); cur_3d_obj_io.g = SwapLEFloat (cur_3d_obj_io.g); cur_3d_obj_io.b = SwapLEFloat (cur_3d_obj_io.b); LOG_DEBUG("Adding 3d object (%d) '%s' at <%d, %f, %f> with " "rotation <%f, %f, %f>, left lit %d, blended %d and " "color <%f, %f, %f>.", i, cur_3d_obj_io.file_name, cur_3d_obj_io.x_pos, cur_3d_obj_io.y_pos, cur_3d_obj_io.z_pos, cur_3d_obj_io.x_rot, cur_3d_obj_io.y_rot, cur_3d_obj_io.z_rot, cur_3d_obj_io.self_lit, cur_3d_obj_io.blended, cur_3d_obj_io.r, cur_3d_obj_io.g, cur_3d_obj_io.b); if (cur_3d_obj_io.blended != 20) { #ifdef CLUSTER_INSIDES int id; if (cur_3d_obj_io.blended != 1) cur_3d_obj_io.blended = 0; id = add_e3d (cur_3d_obj_io.file_name, cur_3d_obj_io.x_pos, cur_3d_obj_io.y_pos, cur_3d_obj_io.z_pos, cur_3d_obj_io.x_rot, cur_3d_obj_io.y_rot, cur_3d_obj_io.z_rot, cur_3d_obj_io.self_lit, cur_3d_obj_io.blended, cur_3d_obj_io.r, cur_3d_obj_io.g, cur_3d_obj_io.b, 0); if (!have_clusters) update_occupied_with_3d (occupied, id); #else if (cur_3d_obj_io.blended != 1) cur_3d_obj_io.blended = 0; add_e3d (cur_3d_obj_io.file_name, cur_3d_obj_io.x_pos, cur_3d_obj_io.y_pos, cur_3d_obj_io.z_pos, cur_3d_obj_io.x_rot, cur_3d_obj_io.y_rot, cur_3d_obj_io.z_rot, cur_3d_obj_io.self_lit, cur_3d_obj_io.blended, cur_3d_obj_io.r, cur_3d_obj_io.g, cur_3d_obj_io.b, 0); #endif } else { inc_objects_list_placeholders(); } #ifndef FASTER_MAP_LOAD if (i % 250 == 0) { update_function(load_3d_object_str, progress); } #endif } LEAVE_DEBUG_MARK("load 3d objects"); #ifdef FASTER_MAP_LOAD update_function(load_2d_object_str, 20.0f); #else // FASTER_MAP_LOAD progress = (cur_map_header.obj_2d_no + 249) / 250; if (progress > 0) { update_function(load_2d_object_str, 0.0f); progress = 20.0f / progress; } else { update_function(load_2d_object_str, 20.0f); progress = 0.0f; } #endif // FASTER_MAP_LOAD LOG_DEBUG("Loading %d 2d objects.", cur_map_header.obj_2d_no); //read the 2d objects objs_2d = (obj_2d_io*) (file_mem + cur_map_header.obj_2d_offset); ENTER_DEBUG_MARK("load 2d objects"); for (i = 0; i < cur_map_header.obj_2d_no; i++) { obj_2d_io cur_2d_obj_io = objs_2d[i]; #ifdef CLUSTER_INSIDES int id; #endif cur_2d_obj_io.x_pos = SwapLEFloat(cur_2d_obj_io.x_pos); cur_2d_obj_io.y_pos = SwapLEFloat(cur_2d_obj_io.y_pos); cur_2d_obj_io.z_pos = SwapLEFloat(cur_2d_obj_io.z_pos); cur_2d_obj_io.x_rot = SwapLEFloat(cur_2d_obj_io.x_rot); cur_2d_obj_io.y_rot = SwapLEFloat(cur_2d_obj_io.y_rot); cur_2d_obj_io.z_rot = SwapLEFloat(cur_2d_obj_io.z_rot); LOG_DEBUG("Adding 2d object (%d) '%s' at <%d, %f, %f> with " "rotation <%f, %f, %f>.", i, cur_2d_obj_io.file_name, cur_2d_obj_io.x_pos, cur_2d_obj_io.y_pos, cur_2d_obj_io.z_pos, cur_2d_obj_io.x_rot, cur_2d_obj_io.y_rot, cur_2d_obj_io.z_rot); #ifndef SHOW_FLICKERING // Add in low-order bits to prevent flicker. cur_2d_obj_io.z_pos += offset_2d; offset_2d += offset_2d_increment; if (offset_2d >= offset_2d_max) offset_2d = offset_2d_increment; #endif #ifdef FASTER_MAP_LOAD #ifdef CLUSTER_INSIDES id = add_2d_obj(i, cur_2d_obj_io.file_name, cur_2d_obj_io.x_pos, cur_2d_obj_io.y_pos, cur_2d_obj_io.z_pos, cur_2d_obj_io.x_rot, cur_2d_obj_io.y_rot, cur_2d_obj_io.z_rot, 0); if (!have_clusters) update_occupied_with_2d (occupied, id); #else // CLUSTER_INSIDES add_2d_obj(i, cur_2d_obj_io.file_name, cur_2d_obj_io.x_pos, cur_2d_obj_io.y_pos, cur_2d_obj_io.z_pos, cur_2d_obj_io.x_rot, cur_2d_obj_io.y_rot, cur_2d_obj_io.z_rot, 0); #endif // CLUSTER_INSIDES #else // FASTER_MAP_LOAD #ifdef CLUSTER_INSIDES id = add_2d_obj (cur_2d_obj_io.file_name, cur_2d_obj_io.x_pos, cur_2d_obj_io.y_pos, cur_2d_obj_io.z_pos, cur_2d_obj_io.x_rot, cur_2d_obj_io.y_rot, cur_2d_obj_io.z_rot, 0); if (!have_clusters) update_occupied_with_2d (occupied, id); #else // CLUSTER_INSIDES add_2d_obj(cur_2d_obj_io.file_name, cur_2d_obj_io.x_pos, cur_2d_obj_io.y_pos, cur_2d_obj_io.z_pos, cur_2d_obj_io.x_rot, cur_2d_obj_io.y_rot, cur_2d_obj_io.z_rot, 0); #endif // CLUSTER_INSIDES if (i % 250 == 0) { update_function(load_2d_object_str, progress); } #endif // FASTER_MAP_LOAD } LEAVE_DEBUG_MARK("load 2d objects"); #ifdef CLUSTER_INSIDES // If we need to compute the clusters, do it here, so that the // newly added lights and particle systems get the right cluster // number automagically. We don't update the occupation map with // lights or particle systems since I don't expect them to bridge // any clusters, and if they do happen to hang in the void, // they'll be shown anyway. if (!have_clusters) { compute_clusters (occupied); free (occupied); // Ok, we have the clusters, now assign new IDs to each // object that we added. for (i = 0; i < MAX_OBJ_3D; i++) { if (objects_list[i]) { int x = (int) (objects_list[i]->x_pos / 0.5f); int y = (int) (objects_list[i]->y_pos / 0.5f); objects_list[i]->cluster = get_cluster (x, y); } } for (i = 0; i < MAX_OBJ_2D; i++) { if (obj_2d_list[i]) { int x = (int) (obj_2d_list[i]->x_pos / 0.5f); int y = (int) (obj_2d_list[i]->y_pos / 0.5f); obj_2d_list[i]->cluster = get_cluster (x, y); } } } // we finally add the tiles to the abt for(i = 0; i < tile_map_size_y; i++) { bbox.bbmin[Y] = i*3.0f; bbox.bbmax[Y] = (i+1)*3.0f; if (i == 0) bbox.bbmin[Y] -= water_tiles_extension; else if (i == tile_map_size_y-1) bbox.bbmax[Y] += water_tiles_extension; for(j = 0; j < tile_map_size_x; j++) { current_cluster = get_cluster(j*6, i*6); cur_tile = tile_map[i*tile_map_size_x+j]; if (cur_tile != 255) { bbox.bbmin[X] = j*3.0f; bbox.bbmax[X] = (j+1)*3.0f; if (j == 0) bbox.bbmin[X] -= water_tiles_extension; else if (j == tile_map_size_x-1) bbox.bbmax[X] += water_tiles_extension; if (IS_WATER_TILE(cur_tile)) { bbox.bbmin[Z] = -0.25f; bbox.bbmax[Z] = -0.25f; if (IS_REFLECTING(cur_tile)) add_water_to_list(main_bbox_tree_items, get_terrain_id(j, i), bbox, cur_tile, 1); else add_water_to_list(main_bbox_tree_items, get_terrain_id(j, i), bbox, cur_tile, 0); } else { bbox.bbmin[Z] = 0.0f; bbox.bbmax[Z] = 0.0f; add_terrain_to_list(main_bbox_tree_items, get_terrain_id(j, i), bbox, cur_tile); } } } } #endif #ifdef FASTER_MAP_LOAD update_function(load_lights_str, 20.0f); #else // FASTER_MAP_LOAD progress = (cur_map_header.lights_no + 99) / 100; if (progress > 0) { update_function(load_lights_str, 0.0f); progress = 20.0f / progress; } else { update_function(load_lights_str, 20.0f); progress = 0.0f; } #endif // FASTER_MAP_LOAD LOG_DEBUG("Loading %d lights.", cur_map_header.lights_no); //read the lights lights = (light_io *) (file_mem + cur_map_header.lights_offset); ENTER_DEBUG_MARK("load lights"); for (i = 0; i < cur_map_header.lights_no; i++) { light_io cur_light_io = lights[i]; cur_light_io.pos_x = SwapLEFloat (cur_light_io.pos_x); cur_light_io.pos_y = SwapLEFloat (cur_light_io.pos_y); cur_light_io.pos_z = SwapLEFloat (cur_light_io.pos_z); cur_light_io.r = SwapLEFloat (cur_light_io.r); cur_light_io.g = SwapLEFloat (cur_light_io.g); cur_light_io.b = SwapLEFloat (cur_light_io.b); LOG_DEBUG("Adding light(%d) at <%d, %f, %f> with color " "<%f, %f, %f>.", i, cur_light_io.pos_x, cur_light_io.pos_y, cur_light_io.pos_z, cur_light_io.r, cur_light_io.g, cur_light_io.b); if (cur_light_io.pos_x < 0.0f || cur_light_io.pos_x > tile_map_size_x * 60 || cur_light_io.pos_y < 0.0f || cur_light_io.pos_y > tile_map_size_y * 60 || cur_light_io.pos_z < -1000.0f || cur_light_io.pos_z > 1000.0f || cur_light_io.r < -1.0f || cur_light_io.r > 1000.0f || cur_light_io.g < -1.0f || cur_light_io.g > 1000.0f || cur_light_io.b < -1.0f || cur_light_io.b > 1000.0f) { LOG_ERROR("Bad light (number %d) when loading '%s'; co-ords [%f %f %f] " "colour [%f %f %f]", i, file_name, cur_light_io.pos_x, cur_light_io.pos_y, cur_light_io.pos_z, cur_light_io.r, cur_light_io.g, cur_light_io.b); cur_light_io.pos_x = cur_light_io.pos_y = 1.0f; cur_light_io.pos_z = 2.0f; cur_light_io.r = cur_light_io.g = cur_light_io.b = 1.0f; continue; } add_light (cur_light_io.pos_x, cur_light_io.pos_y, cur_light_io.pos_z, cur_light_io.r, cur_light_io.g, cur_light_io.b, 1.0f, 0); #ifndef FASTER_MAP_LOAD if (i % 100 == 0) { update_function(load_lights_str, progress); } #endif } LEAVE_DEBUG_MARK("load lights"); #ifdef FASTER_MAP_LOAD update_function(load_particles_str, 20.0f); #else // FASTER_MAP_LOAD progress = (cur_map_header.particles_no + 99) / 100; if (progress > 0.0f) { update_function(load_particles_str, 0.0f); progress = 20.0f / progress; } else { update_function(load_particles_str, 20.0f); progress = 0.0f; } #endif // FASTER_MAP_LOAD LOG_DEBUG("Loading %d particles.", cur_map_header.particles_no); //read particle systems particles = (particles_io *) (file_mem + cur_map_header.particles_offset); ENTER_DEBUG_MARK("load particles"); for (i = 0; i < cur_map_header.particles_no; i++) { particles_io cur_particles_io = particles[i]; cur_particles_io.x_pos = SwapLEFloat (cur_particles_io.x_pos); cur_particles_io.y_pos = SwapLEFloat (cur_particles_io.y_pos); cur_particles_io.z_pos = SwapLEFloat (cur_particles_io.z_pos); LOG_DEBUG("Adding particle(%d) '%s' at <%d, %f, %f>.", i, cur_particles_io.file_name, cur_particles_io.x_pos, cur_particles_io.y_pos, cur_particles_io.z_pos); if (!strncmp(cur_particles_io.file_name, "ec://", 5)) { ec_create_effect_from_map_code(cur_particles_io.file_name + 5, cur_particles_io.x_pos, cur_particles_io.y_pos, cur_particles_io.z_pos, (poor_man ? 6 : 10)); } else { #ifdef NEW_SOUND add_map_particle_sys (cur_particles_io.file_name, cur_particles_io.x_pos, cur_particles_io.y_pos, cur_particles_io.z_pos, 0); #else add_particle_sys (cur_particles_io.file_name, cur_particles_io.x_pos, cur_particles_io.y_pos, cur_particles_io.z_pos, 0); #endif // NEW_SOUND } #ifndef FASTER_MAP_LOAD if (i % 100 == 0) { update_function(load_particles_str, progress); } #endif } LEAVE_DEBUG_MARK("load particles"); // Everything copied, get rid of the file data el_close(file); update_function(bld_sectors_str, 0.0f); LOG_DEBUG("Building bbox tree for map '%s'.", file_name); init_bbox_tree(main_bbox_tree, main_bbox_tree_items); free_bbox_items(main_bbox_tree_items); main_bbox_tree_items = 0; update_function(init_done_str, 20.0f); #ifdef EXTRA_DEBUG ERR();//We finished loading the new map apparently... #endif return 1; }
void add_enhanced_actor_from_server(char * in_data) { short actor_id; short x_pos; short y_pos; short z_pos; short z_rot; short max_health; short cur_health; Uint8 actor_type; Uint8 skin; Uint8 hair; Uint8 shirt; Uint8 pants; Uint8 boots; Uint8 frame; Uint8 cape; Uint8 head; Uint8 shield; Uint8 weapon; Uint8 helmet; int i; int dead=0; int kind_of_actor; enhanced_actor *this_actor; char cur_frame[20]; double f_x_pos,f_y_pos,f_z_pos,f_z_rot; actor_id=*((short *)(in_data)); x_pos=*((short *)(in_data+2)); y_pos=*((short *)(in_data+4)); z_pos=*((short *)(in_data+6)); z_rot=*((short *)(in_data+8)); actor_type=*(in_data+10); skin=*(in_data+12); hair=*(in_data+13); shirt=*(in_data+14); pants=*(in_data+15); boots=*(in_data+16); head=*(in_data+17); shield=*(in_data+18); weapon=*(in_data+19); cape=*(in_data+20); helmet=*(in_data+21); frame=*(in_data+22); max_health=*((short *)(in_data+23)); cur_health=*((short *)(in_data+25)); kind_of_actor=*(in_data+27); //translate from tile to world f_x_pos=x_pos*0.5; f_y_pos=y_pos*0.5; f_z_pos=z_pos; f_z_rot=z_rot; //get the current frame switch(frame) { case frame_walk: my_strcp(cur_frame,actors_defs[actor_type].walk_frame);break; case frame_run: my_strcp(cur_frame,actors_defs[actor_type].run_frame);break; case frame_die1: my_strcp(cur_frame,actors_defs[actor_type].die1_frame); dead=1; break; case frame_die2: my_strcp(cur_frame,actors_defs[actor_type].die2_frame); dead=1; break; case frame_pain1: my_strcp(cur_frame,actors_defs[actor_type].pain1_frame);break; case frame_pain2: my_strcp(cur_frame,actors_defs[actor_type].pain2_frame);break; case frame_pick: my_strcp(cur_frame,actors_defs[actor_type].pick_frame);break; case frame_drop: my_strcp(cur_frame,actors_defs[actor_type].drop_frame);break; case frame_idle: my_strcp(cur_frame,actors_defs[actor_type].idle_frame);break; case frame_sit_idle: my_strcp(cur_frame,actors_defs[actor_type].idle_sit_frame);break; case frame_harvest: my_strcp(cur_frame,actors_defs[actor_type].harvest_frame);break; case frame_cast: my_strcp(cur_frame,actors_defs[actor_type].attack_cast_frame);break; case frame_attack_up_1: my_strcp(cur_frame,actors_defs[actor_type].attack_up_1_frame);break; case frame_attack_up_2: my_strcp(cur_frame,actors_defs[actor_type].attack_up_2_frame);break; case frame_attack_up_3: my_strcp(cur_frame,actors_defs[actor_type].attack_up_3_frame);break; case frame_attack_up_4: my_strcp(cur_frame,actors_defs[actor_type].attack_up_4_frame);break; case frame_attack_down_1: my_strcp(cur_frame,actors_defs[actor_type].attack_down_1_frame);break; case frame_attack_down_2: my_strcp(cur_frame,actors_defs[actor_type].attack_down_2_frame);break; case frame_combat_idle: my_strcp(cur_frame,actors_defs[actor_type].combat_idle_frame);break; default: { } } //find out if there is another actor with that ID //ideally this shouldn't happen, but just in case for(i=0;i<max_actors;i++) { if(actors_list[i]) { if(actors_list[i]->actor_id==actor_id) { char str[256]; sprintf(str,"%s %d = %s => %s\n",duplicate_actors_str,actor_id, actors_list[i]->actor_name ,&in_data[28]); log_error(str); destroy_actor(actors_list[i]->actor_id);//we don't want two actors with the same ID i--;// last actor was put here, he needs to be checked too } else if(kind_of_actor==COMPUTER_CONTROLLED_HUMAN && (actors_list[i]->kind_of_actor==COMPUTER_CONTROLLED_HUMAN || actors_list[i]->kind_of_actor==PKABLE_COMPUTER_CONTROLLED) && !my_strcompare(&in_data[28], actors_list[i]->actor_name)) { char str[256]; sprintf(str,"%s(%d) = %s => %s\n",duplicate_npc_actor,actor_id, actors_list[i]->actor_name ,&in_data[28]); log_error(str); destroy_actor(actors_list[i]->actor_id);//we don't want two actors with the same ID i--;// last actor was put here, he needs to be checked too } } } this_actor=calloc(1,sizeof(enhanced_actor)); //get the torso my_strcp(this_actor->arms_tex,actors_defs[actor_type].shirt[shirt].arms_name); my_strcp(this_actor->torso_tex,actors_defs[actor_type].shirt[shirt].torso_name); my_strcp(this_actor->torso_fn,actors_defs[actor_type].shirt[shirt].model_name); //skin my_strcp(this_actor->hands_tex,actors_defs[actor_type].skin[skin].hands_name); my_strcp(this_actor->hands_tex_save,actors_defs[actor_type].skin[skin].hands_name); my_strcp(this_actor->head_tex,actors_defs[actor_type].skin[skin].head_name); //hair my_strcp(this_actor->hair_tex,actors_defs[actor_type].hair[hair].hair_name); //boots my_strcp(this_actor->boots_tex,actors_defs[actor_type].boots[boots].boots_name); //legs my_strcp(this_actor->pants_tex,actors_defs[actor_type].legs[pants].legs_name); my_strcp(this_actor->legs_fn,actors_defs[actor_type].legs[pants].model_name); //cape if(cape!=CAPE_NONE) { my_strcp(this_actor->cape_tex,actors_defs[actor_type].cape[cape].skin_name); my_strcp(this_actor->cape_fn,actors_defs[actor_type].cape[cape].model_name); } else { my_strcp(this_actor->cape_tex,""); my_strcp(this_actor->cape_fn,""); } //head my_strcp(this_actor->head_fn,actors_defs[actor_type].head[head].model_name); //shield if(shield!=SHIELD_NONE) { my_strcp(this_actor->shield_tex,actors_defs[actor_type].shield[shield].skin_name); my_strcp(this_actor->shield_fn,actors_defs[actor_type].shield[shield].model_name); } else { my_strcp(this_actor->shield_tex,""); my_strcp(this_actor->shield_fn,""); } my_strcp(this_actor->weapon_tex,actors_defs[actor_type].weapon[weapon].skin_name); my_strcp(this_actor->weapon_fn,actors_defs[actor_type].weapon[weapon].model_name); this_actor->weapon_glow=actors_defs[actor_type].weapon[weapon].glow; if(weapon == GLOVE_FUR || weapon == GLOVE_LEATHER){ my_strcp(this_actor->hands_tex, actors_defs[actor_type].weapon[weapon].skin_name); } //helmet if(helmet!=HELMET_NONE) { my_strcp(this_actor->helmet_tex,actors_defs[actor_type].helmet[helmet].skin_name); my_strcp(this_actor->helmet_fn,actors_defs[actor_type].helmet[helmet].model_name); } else { my_strcp(this_actor->helmet_tex,""); my_strcp(this_actor->helmet_fn,""); } i=add_enhanced_actor(this_actor,cur_frame,f_x_pos,f_y_pos,f_z_pos,f_z_rot,actor_id); actors_list[i]->x_tile_pos=x_pos; actors_list[i]->y_tile_pos=y_pos; actors_list[i]->actor_type=actor_type; actors_list[i]->damage=0; actors_list[i]->damage_ms=0; actors_list[i]->sitting=0; actors_list[i]->fighting=0; //test only actors_list[i]->max_health=max_health; actors_list[i]->cur_health=cur_health; if(frame==frame_sit_idle) { if(actors_list[i]->actor_id==yourself)you_sit_down(); actors_list[i]->sitting=1; } else if(frame==frame_combat_idle) actors_list[i]->fighting=1; //ghost or not? actors_list[i]->ghost=0; actors_list[i]->dead=dead; actors_list[i]->stop_animation=1;//helps when the actor is dead... actors_list[i]->cur_weapon=weapon; actors_list[i]->kind_of_actor=kind_of_actor; if(strlen(&in_data[28]) >= 30) { char str[120]; snprintf(str, 120, "%s (%d): %s/%d\n", bad_actor_name_length, actors_list[i]->actor_type,&in_data[28], (int)strlen(&in_data[28])); log_error(str); return; } my_strncp(actors_list[i]->actor_name,&in_data[28],30); if(caps_filter && my_isupper(actors_list[i]->actor_name, -1)) my_tolower(actors_list[i]->actor_name); unlock_actors_lists(); //unlock it }
void actor_wear_item(int actor_id,Uint8 which_part, Uint8 which_id) { int i; for(i=0;i<max_actors;i++) { if(actors_list[i]) if(actors_list[i]->actor_id==actor_id) { if(which_part==KIND_OF_WEAPON) { if(which_id == GLOVE_FUR || which_id == GLOVE_LEATHER){ my_strcp(actors_list[i]->body_parts->hands_tex, actors_defs[actors_list[i]->actor_type].weapon[which_id].skin_name); } my_strcp(actors_list[i]->body_parts->weapon_tex,actors_defs[actors_list[i]->actor_type].weapon[which_id].skin_name); my_strcp(actors_list[i]->body_parts->weapon_fn,actors_defs[actors_list[i]->actor_type].weapon[which_id].model_name); no_bounding_box=1; actors_list[i]->body_parts->weapon=(md2*)load_md2_cache(actors_list[i]->body_parts->weapon_fn); no_bounding_box=0; glDeleteTextures(1,&actors_list[i]->texture_id); actors_list[i]->texture_id=load_bmp8_enhanced_actor(actors_list[i]->body_parts, 255); actors_list[i]->cur_weapon=which_id; actors_list[i]->body_parts->weapon_glow=actors_defs[actors_list[i]->actor_type].weapon[which_id].glow; return; } if(which_part==KIND_OF_SHIELD) { my_strcp(actors_list[i]->body_parts->shield_tex,actors_defs[actors_list[i]->actor_type].shield[which_id].skin_name); my_strcp(actors_list[i]->body_parts->shield_fn,actors_defs[actors_list[i]->actor_type].shield[which_id].model_name); no_bounding_box=1; actors_list[i]->body_parts->shield=(md2*)load_md2_cache(actors_list[i]->body_parts->shield_fn); no_bounding_box=0; glDeleteTextures(1,&actors_list[i]->texture_id); actors_list[i]->texture_id=load_bmp8_enhanced_actor(actors_list[i]->body_parts, 255); return; } if(which_part==KIND_OF_CAPE) { my_strcp(actors_list[i]->body_parts->cape_tex,actors_defs[actors_list[i]->actor_type].cape[which_id].skin_name); my_strcp(actors_list[i]->body_parts->cape_fn,actors_defs[actors_list[i]->actor_type].cape[which_id].model_name); no_bounding_box=1; actors_list[i]->body_parts->cape=(md2*)load_md2_cache(actors_list[i]->body_parts->cape_fn); no_bounding_box=0; glDeleteTextures(1,&actors_list[i]->texture_id); actors_list[i]->texture_id=load_bmp8_enhanced_actor(actors_list[i]->body_parts, 255); return; } if(which_part==KIND_OF_HELMET) { my_strcp(actors_list[i]->body_parts->helmet_tex,actors_defs[actors_list[i]->actor_type].helmet[which_id].skin_name); my_strcp(actors_list[i]->body_parts->helmet_fn,actors_defs[actors_list[i]->actor_type].helmet[which_id].model_name); no_bounding_box=1; actors_list[i]->body_parts->helmet=(md2*)load_md2_cache(actors_list[i]->body_parts->helmet_fn); no_bounding_box=0; glDeleteTextures(1,&actors_list[i]->texture_id); actors_list[i]->texture_id=load_bmp8_enhanced_actor(actors_list[i]->body_parts, 255); return; } if(which_part==KIND_OF_BODY_ARMOR) { my_strcp(actors_list[i]->body_parts->arms_tex,actors_defs[actors_list[i]->actor_type].shirt[which_id].arms_name); my_strcp(actors_list[i]->body_parts->torso_tex,actors_defs[actors_list[i]->actor_type].shirt[which_id].torso_name); my_strcp(actors_list[i]->body_parts->torso_fn,actors_defs[actors_list[i]->actor_type].shirt[which_id].model_name); no_bounding_box=1; actors_list[i]->body_parts->torso=(md2*)load_md2_cache(actors_list[i]->body_parts->torso_fn); no_bounding_box=0; glDeleteTextures(1,&actors_list[i]->texture_id); actors_list[i]->texture_id=load_bmp8_enhanced_actor(actors_list[i]->body_parts, 255); return; } if(which_part==KIND_OF_LEG_ARMOR) { my_strcp(actors_list[i]->body_parts->pants_tex,actors_defs[actors_list[i]->actor_type].legs[which_id].legs_name); my_strcp(actors_list[i]->body_parts->legs_fn,actors_defs[actors_list[i]->actor_type].legs[which_id].model_name); no_bounding_box=1; actors_list[i]->body_parts->legs=(md2*)load_md2_cache(actors_list[i]->body_parts->legs_fn); no_bounding_box=0; glDeleteTextures(1,&actors_list[i]->texture_id); actors_list[i]->texture_id=load_bmp8_enhanced_actor(actors_list[i]->body_parts, 255); return; } if(which_part==KIND_OF_BOOT_ARMOR) { my_strcp(actors_list[i]->body_parts->boots_tex,actors_defs[actors_list[i]->actor_type].boots[which_id].boots_name); actors_list[i]->texture_id=load_bmp8_enhanced_actor(actors_list[i]->body_parts, 255); return; } return; } } }
//return the ID (number in the actors_list[]) of the new allocated actor int add_enhanced_actor(enhanced_actor *this_actor,char * frame_name,float x_pos, float y_pos, float z_pos, float z_rot, int actor_id) { int texture_id; int i; int k; actor *our_actor; no_bounding_box=1; //ok, load the legs if(this_actor->legs_fn[0]) { this_actor->legs=(md2*)load_md2_cache(this_actor->legs_fn); if(!this_actor->legs) { char str[120]; sprintf(str,"%s: %s: %s\n",reg_error_str,error_body_part,this_actor->legs_fn); log_error(str); this_actor->legs=0; } } else this_actor->legs=0; //ok, load the head if(this_actor->head_fn[0]) { this_actor->head=(md2*)load_md2_cache(this_actor->head_fn); if(!this_actor->head) { char str[120]; sprintf(str,"%s: %s (%s): %s\n",reg_error_str,error_body_part,error_head,this_actor->head_fn); log_error(str); this_actor->head=0; } } else this_actor->head=0; //ok, load the torso if(this_actor->torso_fn[0]) { this_actor->torso=(md2*)load_md2_cache(this_actor->torso_fn); if(!this_actor->torso) { char str[120]; sprintf(str,"%s: %s (%s): %s\n",reg_error_str,error_body_part,error_torso,this_actor->torso_fn); log_error(str); this_actor->torso=0; } } else this_actor->torso=0; //ok, load the weapon if(this_actor->weapon_fn[0]) { this_actor->weapon=(md2*)load_md2_cache(this_actor->weapon_fn); if(!this_actor->weapon) { char str[120]; sprintf(str,"%s: %s (%s): %s\n",reg_error_str,error_body_part,error_weapon,this_actor->weapon_fn); log_error(str); this_actor->weapon=0; } } else this_actor->weapon=0; //ok, load the shield if(this_actor->shield_fn[0]) { this_actor->shield=(md2*)load_md2_cache(this_actor->shield_fn); if(!this_actor->shield) { char str[120]; sprintf(str,"%s: %s (%s): %s\n",reg_error_str,error_body_part,error_weapon,this_actor->shield_fn); log_error(str); this_actor->shield=0; } } else this_actor->shield=0; //ok, load the helmet if(this_actor->helmet_fn[0]) { this_actor->helmet=(md2*)load_md2_cache(this_actor->helmet_fn); if(!this_actor->helmet) { char str[120]; sprintf(str,"%s: %s (%s): %s\n",reg_error_str,error_body_part,error_helmet,this_actor->helmet_fn); log_error(str); this_actor->helmet=0; } } else this_actor->helmet=0; //ok, load the cape if(this_actor->cape_fn[0]) { this_actor->cape=(md2*)load_md2_cache(this_actor->cape_fn); if(!this_actor->cape) { char str[120]; sprintf(str,"%s: %s (%s): %s\n",reg_error_str,error_body_part,error_cape,this_actor->cape_fn); log_error(str); this_actor->cape=0; } } else this_actor->cape=0; //get the skin texture_id= load_bmp8_enhanced_actor(this_actor, 255); our_actor = calloc(1, sizeof(actor)); memset(our_actor->current_displayed_text, 0, max_current_displayed_text_len); our_actor->current_displayed_text_time_left = 0; our_actor->texture_id=texture_id; our_actor->is_enhanced_model=1; our_actor->actor_id=actor_id; our_actor->x_pos=x_pos; our_actor->y_pos=y_pos; our_actor->z_pos=z_pos; our_actor->x_speed=0; our_actor->y_speed=0; our_actor->z_speed=0; our_actor->x_rot=0; our_actor->y_rot=0; our_actor->z_rot=z_rot; //reset the script related things our_actor->move_x_speed=0; our_actor->move_y_speed=0; our_actor->move_z_speed=0; our_actor->rotate_x_speed=0; our_actor->rotate_y_speed=0; our_actor->rotate_z_speed=0; our_actor->movement_frames_left=0; our_actor->moving=0; our_actor->rotating=0; our_actor->busy=0; our_actor->last_command=nothing; //clear the que for(k=0;k<10;k++)our_actor->que[k]=nothing; our_actor->model_data=0; my_strcp(our_actor->cur_frame,frame_name); our_actor->stand_idle=0; our_actor->sit_idle=0; our_actor->body_parts=this_actor; //find a free spot, in the actors_list lock_actors_lists(); //lock it to avoid timing issues for(i=0;i<max_actors;i++) { if(!actors_list[i])break; } actors_list[i]=our_actor; if(i>=max_actors)max_actors=i+1; no_bounding_box=0; //We're unlocking it later return i; }
//returns -1 if the name is already filtered, 1 on sucess, -2 if no more filter slots int add_to_filter_list (const char *name, char local, char save_name) { int i, j; char left[256]; char right[256]; int t, tp; int l=0; //ok, find a free spot for (i = 0; i < MAX_FILTERS; i++) { if (filter_list[i].len <= 0) { // excellent, a free spot safe_strncpy (left, name, sizeof(left)); for (t = 0; ; t++) { if (left[t] == '\0') { safe_strncpy (right, "smeg", sizeof(right)); break; } if(left[t]=='=') { left[t] = '\0'; tp = t - 1; for (tp = t-1; tp >= 0 && isspace (left[tp]); tp--) { left[tp] = '\0'; } for (tp = t + 1; left[tp] != '\0' && !(left[tp]&0x80) && isspace(left[tp]); tp++) ; safe_strncpy (right, &left[tp], sizeof(right)); break; } } // See if this name is already on the list for (j = 0; j < MAX_FILTERS; j++) { if (filter_list[j].len > 0) { if (my_strcompare (filter_list[j].name, left)) return -1; // Already in the list } } // add to the local filter file, if the case if (save_name) { FILE *f = open_file_config("local_filters.txt", "a"); if (f == NULL){ LOG_ERROR("%s: %s \"local_filters.txt\": %s\n", reg_error_str, cant_open_file, strerror(errno)); } else { fprintf (f, "%s = %s\n", left, right); fclose(f); } } left[sizeof(filter_list[i].name)-1] = '\0'; right[sizeof(filter_list[i].replacement)-1] = '\0'; filter_list[i].wildcard_type = 0; l = strlen (left) - 1; if (left[0] == '*' && left[l] != '*') filter_list[i].wildcard_type = 1; if (left[0] != '*' && left[l] == '*') filter_list[i].wildcard_type = 2; if (left[0] == '*' && left[l] == '*') filter_list[i].wildcard_type = 3; my_strcp (filter_list[i].name, left); my_strcp (filter_list[i].replacement, right); filter_list[i].len = strlen(filter_list[i].name);//memorize the length filter_list[i].rlen = strlen(filter_list[i].replacement);//memorize the length filter_list[i].local = local; filtered_so_far++; return 1; } } return -2;//if we are here, it means the filters list is full }
//in case the actor is not busy, and has commands in it's que, execute them void next_command() { int i; int max_queue=0; /* #ifdef EXTRA_DEBUG ERR(); #endif*/ lock_actors_lists(); for(i=0;i<max_actors;i++) { if(!actors_list[i])continue;//actor exists? if(!actors_list[i]->busy || (actors_list[i]->busy && actors_list[i]->after_move_frames_left && (actors_list[i]->que[0]>=move_n && actors_list[i]->que[0]<=move_nw)))//is it not busy? { if(actors_list[i]->que[0]==nothing)//do we have something in the que? { //if que is empty, set on idle if(!actors_list[i]->dead) { actors_list[i]->stop_animation=0; if(actors_list[i]->fighting) { my_strcp(actors_list[i]->cur_frame,actors_defs[actors_list[i]->actor_type].combat_idle_frame); } else if(!actors_list[i]->sitting) { if(!actors_list[i]->sit_idle) { my_strcp(actors_list[i]->cur_frame,actors_defs[actors_list[i]->actor_type].idle_frame); actors_list[i]->sit_idle=1; } } else { if(!actors_list[i]->stand_idle) { my_strcp(actors_list[i]->cur_frame,actors_defs[actors_list[i]->actor_type].idle_sit_frame); actors_list[i]->stand_idle=1; } } } actors_list[i]->last_command=nothing;//prevents us from not updating the walk/run animation } else { int actor_type; int last_command=actors_list[i]->last_command; float z_rot=actors_list[i]->z_rot; float targeted_z_rot; int k; actors_list[i]->sit_idle=0; actors_list[i]->stand_idle=0; actor_type=actors_list[i]->actor_type; switch(actors_list[i]->que[0]) { case kill_me: #ifdef KILL_ME //This is obsolete... if(actors_list[i]->remapped_colors) glDeleteTextures(1,&actors_list[i]->texture_id); free(actors_list[i]); actors_list[i]=0; #endif break; case die1: my_strcp(actors_list[i]->cur_frame,actors_defs[actor_type].die1_frame); actors_list[i]->stop_animation=1; actors_list[i]->dead=1; break; case die2: my_strcp(actors_list[i]->cur_frame,actors_defs[actor_type].die2_frame); actors_list[i]->stop_animation=1; actors_list[i]->dead=1; break; case pain1: my_strcp(actors_list[i]->cur_frame,actors_defs[actor_type].pain1_frame); actors_list[i]->stop_animation=1; break; case pain2: my_strcp(actors_list[i]->cur_frame,actors_defs[actor_type].pain2_frame); actors_list[i]->stop_animation=1; break; case pick: my_strcp(actors_list[i]->cur_frame,actors_defs[actor_type].pick_frame); actors_list[i]->stop_animation=1; break; case drop: my_strcp(actors_list[i]->cur_frame,actors_defs[actor_type].drop_frame); actors_list[i]->stop_animation=1; break; case harvest: my_strcp(actors_list[i]->cur_frame,actors_defs[actor_type].harvest_frame); actors_list[i]->stop_animation=1; break; case cast: my_strcp(actors_list[i]->cur_frame,actors_defs[actor_type].attack_cast_frame); actors_list[i]->stop_animation=1; break; case ranged: my_strcp(actors_list[i]->cur_frame,actors_defs[actor_type].attack_ranged_frame); actors_list[i]->stop_animation=1; break; case sit_down: my_strcp(actors_list[i]->cur_frame,actors_defs[actor_type].sit_down_frame); actors_list[i]->stop_animation=1; actors_list[i]->sitting=1; if(actors_list[i]->actor_id==yourself) you_sit_down(); break; case stand_up: my_strcp(actors_list[i]->cur_frame,actors_defs[actor_type].stand_up_frame); actors_list[i]->stop_animation=1; actors_list[i]->sitting=0; if(actors_list[i]->actor_id==yourself) you_stand_up(); break; case enter_combat: my_strcp(actors_list[i]->cur_frame,actors_defs[actor_type].in_combat_frame); actors_list[i]->stop_animation=1; actors_list[i]->fighting=1; break; case leave_combat: my_strcp(actors_list[i]->cur_frame,actors_defs[actor_type].out_combat_frame); actors_list[i]->stop_animation=1; actors_list[i]->fighting=0; break; case attack_up_1: if(actors_list[i]->is_enhanced_model) my_strcp(actors_list[i]->cur_frame,actors_defs[actor_type].weapon[actors_list[i]->cur_weapon].attack_up1); else my_strcp(actors_list[i]->cur_frame,actors_defs[actor_type].attack_up_1_frame); actors_list[i]->stop_animation=1; actors_list[i]->fighting=1; break; case attack_up_2: if(actors_list[i]->is_enhanced_model) my_strcp(actors_list[i]->cur_frame,actors_defs[actor_type].weapon[actors_list[i]->cur_weapon].attack_up1); else my_strcp(actors_list[i]->cur_frame,actors_defs[actor_type].attack_up_2_frame); actors_list[i]->stop_animation=1; actors_list[i]->fighting=1; break; case attack_up_3: if(actors_list[i]->is_enhanced_model) my_strcp(actors_list[i]->cur_frame,actors_defs[actor_type].weapon[actors_list[i]->cur_weapon].attack_up2); else my_strcp(actors_list[i]->cur_frame,actors_defs[actor_type].attack_up_3_frame); actors_list[i]->stop_animation=1; actors_list[i]->fighting=1; break; case attack_up_4: if(actors_list[i]->is_enhanced_model) my_strcp(actors_list[i]->cur_frame,actors_defs[actor_type].weapon[actors_list[i]->cur_weapon].attack_up2); else my_strcp(actors_list[i]->cur_frame,actors_defs[actor_type].attack_up_4_frame); actors_list[i]->stop_animation=1; actors_list[i]->fighting=1; break; case attack_down_1: if(actors_list[i]->is_enhanced_model) my_strcp(actors_list[i]->cur_frame,actors_defs[actor_type].weapon[actors_list[i]->cur_weapon].attack_down1); else my_strcp(actors_list[i]->cur_frame,actors_defs[actor_type].attack_down_1_frame); actors_list[i]->stop_animation=1; actors_list[i]->fighting=1; break; case attack_down_2: if(actors_list[i]->is_enhanced_model) my_strcp(actors_list[i]->cur_frame,actors_defs[actor_type].weapon[actors_list[i]->cur_weapon].attack_down2); else my_strcp(actors_list[i]->cur_frame,actors_defs[actor_type].attack_down_2_frame); actors_list[i]->stop_animation=1; actors_list[i]->fighting=1; break; case turn_left: actors_list[i]->rotate_z_speed=45.0/9.0; actors_list[i]->rotate_frames_left=9; actors_list[i]->rotating=1; //generate a fake movement, so we will know when to make the actor //not busy actors_list[i]->move_x_speed=0; actors_list[i]->move_y_speed=0; actors_list[i]->movement_frames_left=9; actors_list[i]->moving=1; //test my_strcp(actors_list[i]->cur_frame,actors_defs[actor_type].walk_frame); actors_list[i]->stop_animation=1; break; case turn_right: actors_list[i]->rotate_z_speed=-45.0/9.0; actors_list[i]->rotate_frames_left=9; actors_list[i]->rotating=1; //generate a fake movement, so we will know when to make the actor //not busy actors_list[i]->move_x_speed=0; actors_list[i]->move_y_speed=0; actors_list[i]->movement_frames_left=9; actors_list[i]->moving=1; //test my_strcp(actors_list[i]->cur_frame,actors_defs[actor_type].walk_frame); actors_list[i]->stop_animation=1; break; //ok, now the movement, this is the tricky part default: if(actors_list[i]->que[0]>=move_n && actors_list[i]->que[0]<=move_nw) { float rotation_angle; if(last_command<move_n || last_command>move_nw)//update the frame name too my_strcp(actors_list[i]->cur_frame,actors_defs[actor_type].walk_frame); actors_list[i]->stop_animation=0; if(last_command!=actors_list[i]->que[0])//we need to calculate the rotation... { targeted_z_rot=(actors_list[i]->que[0]-move_n)*45.0f; rotation_angle=get_rotation_vector(z_rot,targeted_z_rot); actors_list[i]->rotate_z_speed=rotation_angle/6; if(auto_camera) if(actors_list[i]->actor_id==yourself) { camera_rotation_speed=rotation_angle/18; camera_rotation_frames=18; } actors_list[i]->rotate_frames_left=6; actors_list[i]->rotating=1; } else targeted_z_rot=z_rot; //ok, now calculate the motion vector... actors_list[i]->move_x_speed=actors_defs[actor_type].walk_speed*sin(targeted_z_rot*3.1415926/180.0); actors_list[i]->move_y_speed=actors_defs[actor_type].walk_speed*cos(targeted_z_rot*3.1415926/180.0); actors_list[i]->movement_frames_left=18/4; actors_list[i]->after_move_frames_left=0; actors_list[i]->moving=1; //test to see if we have a diagonal movement, and if we do, adjust the speeds if((actors_list[i]->move_x_speed>0.01f || actors_list[i]->move_x_speed<-0.01f) && (actors_list[i]->move_y_speed>0.01f || actors_list[i]->move_y_speed<-0.01f)) { actors_list[i]->move_x_speed*=1.4142315; actors_list[i]->move_y_speed*=1.4142315; } } else if(actors_list[i]->que[0]>=turn_n && actors_list[i]->que[0]<=turn_nw) { float rotation_angle; targeted_z_rot=(actors_list[i]->que[0]-turn_n)*45.0f; rotation_angle=get_rotation_vector(z_rot,targeted_z_rot); actors_list[i]->rotate_z_speed=rotation_angle/6.0f; actors_list[i]->rotate_frames_left=6; actors_list[i]->rotating=1; actors_list[i]->stop_animation=1; } } //mark the actor as being busy actors_list[i]->busy=1; //save the last command. It is especially good for run and walk actors_list[i]->last_command=actors_list[i]->que[0]; //move que down with one command for(k=0;k<10-1;k++) { if(k>max_queue && actors_list[i]->que[k]!=nothing)max_queue=k; actors_list[i]->que[k]=actors_list[i]->que[k+1]; } actors_list[i]->que[k]=nothing; } } } unlock_actors_lists(); if(max_queue >= 4)my_timer_adjust+=6+(max_queue-4); //speed up the timer clock if we are building up too much }
// Returns 1 if ignored, 0 if not ignored int pre_check_if_ignored (const char *input_text, int len, Uint8 channel) { int offset; char name[MAX_USERNAME_LENGTH] = {0}; if (channel == CHAT_MODPM) { return 0; // Don't ever ignore MOD PM's } switch(channel) { case CHAT_PERSONAL: offset = strlen(pm_from_str) + 2; get_name_from_text(input_text, len, 0, offset, name); // Type 0 = ":" or " " break; case CHAT_LOCAL: offset = 0; while (is_color (input_text[offset])) { offset++; } offset += get_name_from_text(input_text, len, 1, offset, name); // Type 1 = ":", " " or is_color if (!name_is_valid(name)) { //This can be a lot. Let's separate them based on the color for now. switch (from_color_char (*input_text)) { case c_grey1: //Check for summoning messages //(*) NAME summoned a %s if (strcmp(name, "(*)") == 0) { while (offset < len && isspace(input_text[offset])) { offset++; } get_name_from_text(input_text, len, 2, offset, name); // Type 2 = isspace } break; } } break; case CHAT_GM: for (offset = 0; is_color (input_text[offset]); offset++); // Ignore colours if(strncasecmp(input_text+offset, gm_from_str, strlen(gm_from_str)) == 0) { offset = strlen(gm_from_str)+2; get_name_from_text(input_text, len, 0, offset, name); // Type 0 = ":" or " " } else if(strncasecmp(input_text+offset, ig_from_str, strlen(ig_from_str)) == 0) { offset = strlen(ig_from_str)+1; get_name_from_text(input_text, len, 4, offset, name); // Type 4 = ":", "-" or " " } break; case CHAT_MOD: for (offset = 0; is_color (input_text[offset]); offset++); // Ignore colours if(strncasecmp(input_text+offset, mc_from_str, strlen(mc_from_str)) == 0) { offset = strlen(mc_from_str)+2; get_name_from_text(input_text, len, 0, offset, name); // Type 0 = ":" or " " } break; case CHAT_SERVER: for (offset = 0; is_color (input_text[offset]); offset++); // Ignore colours if(strncasecmp(input_text+offset, "delayed: ", 9) == 0) { offset = 10; if(strncasecmp(input_text+offset, pm_from_str, strlen(pm_from_str)) == 0) { offset += strlen(pm_from_str)+1; get_name_from_text(input_text, len, 0, offset, name); // Type 0 = ":" or " " } } break; } #if defined(OTHER_LIFE) && defined(OTHER_LIFE_EXTENDED_CHAT) if(loadsofchannels == 3) { switch(channel) { case CHAT_CHANNEL1: case CHAT_CHANNEL2: case CHAT_CHANNEL3: for (offset = 0; is_color (input_text[offset]); offset++); // Ignore colours if (input_text[offset] == '[') { offset++; } get_name_from_text(input_text, len, 3, offset, name); // Type 3 = ":", " " or "]" } } else { switch(channel) { case CHAT_CHANNEL1: case CHAT_CHANNEL2: case CHAT_CHANNEL3: case CHAT_CHANNEL4: case CHAT_CHANNEL5: case CHAT_CHANNEL6: case CHAT_CHANNEL7: case CHAT_CHANNEL8: case CHAT_CHANNEL9: case CHAT_CHANNEL10: case CHAT_CHANNEL11: case CHAT_CHANNEL12: case CHAT_CHANNEL13: case CHAT_CHANNEL14: case CHAT_CHANNEL15: case CHAT_CHANNEL16: case CHAT_CHANNEL17: case CHAT_CHANNEL18: case CHAT_CHANNEL19: case CHAT_CHANNEL20: case CHAT_CHANNEL21: case CHAT_CHANNEL22: case CHAT_CHANNEL23: case CHAT_CHANNEL24: case CHAT_CHANNEL25: case CHAT_CHANNEL26: case CHAT_CHANNEL27: case CHAT_CHANNEL28: case CHAT_CHANNEL29: case CHAT_CHANNEL30: case CHAT_CHANNEL31: case CHAT_CHANNEL32: for (offset = 0; is_color (input_text[offset]); offset++); // Ignore colours if (input_text[offset] == '[') { offset++; } get_name_from_text(input_text, len, 3, offset, name); // Type 3 = ":", " " or "]" } } #else switch (channel) { case CHAT_CHANNEL1: case CHAT_CHANNEL2: case CHAT_CHANNEL3: for (offset = 0; is_color (input_text[offset]); offset++); // Ignore colours if (input_text[offset] == '[') { offset++; } get_name_from_text(input_text, len, 3, offset, name); // Type 3 = ":", " " or "]" } #endif // if defined(OTHER_LIFE) && defined(OTHER_LIFE_EXTENDED_CHAT) if (*name && name_is_valid(name)) { add_name_to_tablist(name); } else { for (offset = 0; is_color (input_text[offset]); offset++); // Ignore colours get_name_from_text(input_text, len, 1, offset, name); // Type 1 = ":", " " or is_color } if (!check_if_ignored (name)) { if (channel == CHAT_PERSONAL || channel == CHAT_MODPM) { //memorise the name my_strcp (last_pm_from, name); } return 0; } else { return 1; } }