int get_tile_walkable(const int x, const int y) { if (!get_tile_valid(x, y)) { return 0; } return (height_map[x * tile_map_size_x * 6 + y] & 0x3F) != 0; }
float get_tile_height(const float x, const float y) { float z; int pos_x, pos_y, i, j, tmp, count; if (!get_tile_valid(x, y)) { return 0.0f; } pos_x = x; pos_y = y; tmp = height_map[pos_y * tile_map_size_x * 6 + pos_x]; if (tmp != 0) { return tmp * 0.2f - 2.2f; } tmp = 0; count = 0; for (j = pos_y - 1; j <= (pos_y + 1); ++j) { for (i = pos_x - 1; i <= (pos_x + 1); ++i) { if (get_tile_walkable(i, j)) { tmp += height_map[j * tile_map_size_x * 6 + i]; count++; } } } z = tmp; if (count > 1) { z /= count; } return z * 0.2f - 2.2f; }
void add_teleporters_from_list (const Uint8 *teleport_list) { Uint16 teleporters_no; int i; int teleport_x,teleport_y,my_offset; float x,y,z; teleporters_no=SDL_SwapLE16(*((Uint16 *)(teleport_list))); for (i = 0; i < teleporters_no; i++) { my_offset = i * 5 + 2; teleport_x=SDL_SwapLE16(*((Uint16 *)(teleport_list+my_offset))); teleport_y=SDL_SwapLE16(*((Uint16 *)(teleport_list+my_offset+2))); //later on, maybe we want to have different visual types //now, get the Z position if (!get_tile_valid(teleport_x, teleport_y)) { continue; } z = get_tile_height(teleport_x, teleport_y); //convert from height values to meters x=(float)teleport_x/2; y=(float)teleport_y/2; //center the object x += 0.25f; y += 0.25f; add_particle_sys ("./particles/teleporter.part", x, y, z, 1); engine_add_dynamic_object("./3dobjects/portal1.e3d", x, y, z, 0.0f, 0.0f, 0.0f, 0, 1.0f, 1.0f, 1.0f, engine_get_next_free_dynamic_object_id(), est_detect); //mark the teleporter as an unwalkable so that the pathfinder //won't try to plot a path through it pf_tile_map[teleport_y*tile_map_size_x*6+teleport_x].z = 0; } }
void add_bags_from_list (const Uint8 *data) { Uint16 bags_no; int i; int bag_x,bag_y,my_offset; //bag_type unused? float x,y,z; int obj_3d_id, bag_id; bags_no=data[0]; if(bags_no > NUM_BAGS) { return;//something nasty happened } for(i=0;i<bags_no;i++) { my_offset=i*5+1; bag_x=SDL_SwapLE16(*((Uint16 *)(data+my_offset))); bag_y=SDL_SwapLE16(*((Uint16 *)(data+my_offset+2))); bag_id=*((Uint8 *)(data+my_offset+4)); if(bag_id >= NUM_BAGS) { continue; } //now, get the Z position if (!get_tile_valid(bag_x, bag_y)) { //Warn about this error! LOG_WARNING("A bag was located OUTSIDE the map!\n"); continue; } z = get_tile_height(bag_x, bag_y); //convert from height values to meters x=(float)bag_x/2; y=(float)bag_y/2; //center the object (slightly randomized) x = x + 0.25f; // + get_bag_offset_x(bag_x, bag_y, bag_id, tile_map_size_x, tile_map_size_y); y = y + 0.25f; // + get_bag_offset_y(bag_x, bag_y, bag_id, tile_map_size_x, tile_map_size_y); // DEBUG LOG_DEBUG_VERBOSE("bag <%i> (%f,%f) rot %f tilt %f\n", bag_id, x, y, get_bag_rotation(bag_x, bag_y, bag_id, tile_map_size_x, tile_map_size_y), get_bag_tilt(bag_x, bag_y, bag_id, tile_map_size_x, tile_map_size_y)); if (use_eye_candy) { #ifdef ONGOING_BAG_EFFECT // start an ongoing effect until the ongoing bag effect is coded bag_list[bag_id].ongoing_bag_effect_reference = ec_create_lamp(x, y, z, 0.0, 1.0, 0.75, (poor_man ? 6 : 10)); #endif // ONGOING_BAG_EFFECT } // Now, find a place into the bags list, so we can destroy the bag properly if (bag_list[bag_id].obj_3d_id != -1) { char buf[256]; // oops, slot already taken! safe_snprintf(buf, sizeof(buf), "Oops, trying to add an existing bag! id=%d\n", bag_id); LOG_ERROR(buf); return; } #ifdef OLD_MISC_OBJ_DIR obj_3d_id = add_e3d("./3dobjects/misc_objects/bag1.e3d", x, y, z, #else obj_3d_id = add_e3d("./3dobjects/bag1.e3d", x, y, z, #endif get_bag_tilt(bag_x, bag_y, bag_id, tile_map_size_x, tile_map_size_y), 0, get_bag_rotation(bag_x, bag_y, bag_id, tile_map_size_x, tile_map_size_y), 1, 0, 1.0f, 1.0f, 1.0f, 1); bag_list[bag_id].x=bag_x; bag_list[bag_id].y=bag_y; bag_list[bag_id].obj_3d_id=obj_3d_id; } }
void put_bag_on_ground(int bag_x,int bag_y,int bag_id) { float x,y,z; int obj_3d_id; #ifdef NEW_SOUND int snd; #endif // NEW_SOUND //now, get the Z position if (!get_tile_valid(bag_x, bag_y)) { //Warn about this error: LOG_WARNING("A bag was placed OUTSIDE the map!\n"); return; } z = get_tile_height(bag_x, bag_y); //convert from height values to meters x=(float)bag_x/2; y=(float)bag_y/2; //center the object (slightly randomized) x = x + 0.25f; // + get_bag_offset_x(bag_x, bag_y, bag_id, tile_map_size_x, tile_map_size_y); y = y + 0.25f; // + get_bag_offset_y(bag_x, bag_y, bag_id, tile_map_size_x, tile_map_size_y); // DEBUG // printf("bag <%i> (%f,%f) rot %f tilt %f\n", bag_id, x, y, // get_bag_rotation(bag_x, bag_y, bag_id, tile_map_size_x, tile_map_size_y), // get_bag_tilt(bag_x, bag_y, bag_id, tile_map_size_x, tile_map_size_y)); //Launch the animation if (use_eye_candy) { ec_create_bag_drop(x, y, z, (poor_man ? 6 : 10)); #ifdef ONGOING_BAG_EFFECT // start an ongoing effect until the ongoing bag effect is coded bag_list[bag_id].ongoing_bag_effect_reference = ec_create_lamp(x, y, z, 0.0, 1.0, 0.75, (poor_man ? 6 : 10)); #endif // ONGOING_BAG_EFFECT } #ifdef NEW_SOUND if (your_actor && bag_x == your_actor->x_pos * 2 && bag_y == your_actor->y_pos * 2) { snd = get_sound_index_for_particle_file_name("./particles/bag_in.part"); if (snd >= 0) { add_sound_object (snd, bag_x, bag_y, 0); } } #endif // NEW_SOUND #ifdef OLD_MISC_OBJ_DIR obj_3d_id=add_e3d("./3dobjects/misc_objects/bag1.e3d", x, y, z, #else obj_3d_id=add_e3d("./3dobjects/bag1.e3d", x, y, z, #endif get_bag_tilt(bag_x, bag_y, bag_id, tile_map_size_x, tile_map_size_y), 0, get_bag_rotation(bag_x, bag_y, bag_id, tile_map_size_x, tile_map_size_y), 1 ,0 ,1.0f ,1.0f, 1.0f, 1); //now, find a place into the bags list, so we can destroy the bag properly bag_list[bag_id].x=bag_x; bag_list[bag_id].y=bag_y; bag_list[bag_id].obj_3d_id=obj_3d_id; }