/** * Scans map for gold veins, and fills up gold_lookup array with veins found. */ void check_map_for_gold(void) { MapSlabCoord slb_x,slb_y; struct SlabMap *slb; SlabCodedCoords slb_num; unsigned char *treasure_map; unsigned short *vein_list; long gold_next_idx; long i; SYNCDBG(8,"Starting"); //_DK_check_map_for_gold(); for (i=0; i < GOLD_LOOKUP_COUNT; i++) { LbMemorySet(&game.gold_lookup[i], 0, sizeof(struct GoldLookup)); } // Make a map with treasure areas marked treasure_map = (unsigned char *)scratch; vein_list = (unsigned short *)&scratch[map_tiles_x*map_tiles_y]; for (slb_y = 0; slb_y < map_tiles_y; slb_y++) { for (slb_x = 0; slb_x < map_tiles_x; slb_x++) { slb_num = get_slab_number(slb_x, slb_y); slb = get_slabmap_direct(slb_num); treasure_map[slb_num] = 0; const struct SlabAttr *slbattr; slbattr = get_slab_attrs(slb); // Mark areas which are not valuable if ((slbattr->block_flags & (SlbAtFlg_Valuable)) == 0) { treasure_map[slb_num] |= 0x01; } } } // Add treasures to lookup as gold veins gold_next_idx = 0; for (slb_y = 0; slb_y < map_tiles_y; slb_y++) { for (slb_x = 0; slb_x < map_tiles_x; slb_x++) { slb_num = get_slab_number(slb_x, slb_y); if ( ((treasure_map[slb_num] & 0x01) == 0) && ((treasure_map[slb_num] & 0x02) == 0) ) { check_treasure_map(treasure_map, vein_list, &gold_next_idx, slb_x, slb_y); } } } SYNCDBG(8,"Found %ld possible digging locations",gold_next_idx); }
/** * Finds a random training post near to the current position of given creature. * Used when finding a training post seems to be taking too long; in that case, creature should start training with a nearest post. * Note that this routine does not always select the nearest post - it is enough if it's 3 subtiles away. * * @param creatng The creature who wish to train with training post. */ void setup_training_search_for_post(struct Thing *creatng) { struct Room *room; struct Thing *traintng; struct Thing *thing; long start_slab; long min_distance,dist; long slb_x,slb_y; long i,k; room = get_room_thing_is_on(creatng); // Let's start from a random slab slb_x = -1; slb_y = -1; min_distance = LONG_MAX; traintng = INVALID_THING; start_slab = ACTION_RANDOM(room->slabs_count); k = start_slab; i = room->slabs_list; while (i != 0) { slb_x = slb_num_decode_x(i); slb_y = slb_num_decode_y(i); i = get_next_slab_number_in_room(i); if (k <= 0) break; k--; } // Got random starting slab, now sweep room slabs from it thing = INVALID_THING; k = room->slabs_count; i = get_slab_number(slb_x,slb_y); while (k > 0) { slb_x = slb_num_decode_x(i); slb_y = slb_num_decode_y(i); i = get_next_slab_number_in_room(i); if (i == 0) i = room->slabs_list; // Per room tile code - find a nearest training post thing = get_object_at_subtile_of_model_and_owned_by(slab_subtile_center(slb_x), slab_subtile_center(slb_y), 31, creatng->owner); if (!thing_is_invalid(thing)) { dist = get_2d_distance(&creatng->mappos, &thing->mappos); if (dist < min_distance) { traintng = thing; min_distance = dist; if (min_distance < (3<<8)) break; } } // Per room tile code ends k--; } // Got trainer (or not...), now do the correct action if (thing_is_invalid(traintng)) { SYNCDBG(6,"Room no longer have training post, moving somewhere else."); setup_move_to_new_training_position(creatng, room, true); } else { i = get_subtile_number(traintng->mappos.x.stl.num,traintng->mappos.y.stl.num); setup_training_move_near(creatng, i); } }
void make_safe(struct PlayerInfo *player) { //_DK_make_safe(player); unsigned char *areamap; areamap = (unsigned char *)scratch; MapSlabCoord slb_x, slb_y; // Prepare the array to remember which slabs were already taken care of for (slb_y=0; slb_y < map_tiles_y; slb_y++) { for (slb_x=0; slb_x < map_tiles_x; slb_x++) { SlabCodedCoords slb_num; struct SlabMap *slb; slb_num = get_slab_number(slb_x, slb_y); slb = get_slabmap_direct(slb_num); struct SlabAttr *slbattr; slbattr = get_slab_attrs(slb); if ((slbattr->block_flags & (SlbAtFlg_Filled|SlbAtFlg_Digable|SlbAtFlg_Valuable)) != 0) areamap[slb_num] = 0x01; else areamap[slb_num] = 0x00; } } { const struct Coord3d *center_pos; center_pos = dungeon_get_essential_pos(player->id_number); slb_x = subtile_slab_fast(center_pos->x.stl.num); slb_y = subtile_slab_fast(center_pos->y.stl.num); SlabCodedCoords slb_num; slb_num = get_slab_number(slb_x, slb_y); areamap[slb_num] |= 0x02; } unsigned int list_cur, list_len; PlayerNumber plyr_idx; plyr_idx = player->id_number; SlabCodedCoords *slblist; slblist = (SlabCodedCoords *)(scratch + map_tiles_x*map_tiles_y); list_len = 0; list_cur = 0; while (list_cur <= list_len) { SlabCodedCoords slb_num; if (slb_x > 0) { slb_num = get_slab_number(slb_x-1, slb_y); if ((areamap[slb_num] & 0x01) != 0) { areamap[slb_num] |= 0x02; struct SlabMap *slb; slb = get_slabmap_direct(slb_num); struct SlabAttr *slbattr; slbattr = get_slab_attrs(slb); if ((slbattr->category == SlbAtCtg_FriableDirt) && slab_by_players_land(plyr_idx, slb_x-1, slb_y)) { unsigned char pretty_type; pretty_type = choose_pretty_type(plyr_idx, slb_x-1, slb_y); place_slab_type_on_map(pretty_type, slab_subtile(slb_x-1,0), slab_subtile(slb_y,0), plyr_idx, 1); do_slab_efficiency_alteration(slb_x-1, slb_y); fill_in_reinforced_corners(plyr_idx, slb_x-1, slb_y); } } else if ((areamap[slb_num] & 0x02) == 0) { areamap[slb_num] |= 0x02; slblist[list_len] = slb_num; list_len++; } } if (slb_x < map_tiles_x-1) { slb_num = get_slab_number(slb_x+1, slb_y); if ((areamap[slb_num] & 0x01) != 0) { areamap[slb_num] |= 0x02; struct SlabMap *slb; slb = get_slabmap_direct(slb_num); struct SlabAttr *slbattr; slbattr = get_slab_attrs(slb); if ((slbattr->category == SlbAtCtg_FriableDirt) && slab_by_players_land(plyr_idx, slb_x+1, slb_y)) { unsigned char pretty_type; pretty_type = choose_pretty_type(plyr_idx, slb_x+1, slb_y); place_slab_type_on_map(pretty_type, slab_subtile(slb_x+1,0), slab_subtile(slb_y,0), plyr_idx, 1u); do_slab_efficiency_alteration(slb_x+1, slb_y); fill_in_reinforced_corners(plyr_idx, slb_x+1, slb_y); } } else if ((areamap[slb_num] & 0x02) == 0) { areamap[slb_num] |= 0x02; slblist[list_len] = slb_num; list_len++; } } if (slb_y > 0) { slb_num = get_slab_number(slb_x, slb_y-1); if ((areamap[slb_num] & 0x01) != 0) { areamap[slb_num] |= 0x02; struct SlabMap *slb; slb = get_slabmap_direct(slb_num); struct SlabAttr *slbattr; slbattr = get_slab_attrs(slb); if ((slbattr->category == SlbAtCtg_FriableDirt) && slab_by_players_land(plyr_idx, slb_x, slb_y-1)) { unsigned char pretty_type; pretty_type = choose_pretty_type(plyr_idx, slb_x, slb_y-1); place_slab_type_on_map(pretty_type, slab_subtile(slb_x,0), slab_subtile(slb_y-1,0), plyr_idx, 1u); do_slab_efficiency_alteration(slb_x, slb_y-1); fill_in_reinforced_corners(plyr_idx, slb_x, slb_y-1); } } else if ((areamap[slb_num] & 0x02) == 0) { areamap[slb_num] |= 0x02; slblist[list_len] = slb_num; list_len++; } } if (slb_y < map_tiles_y-1) { slb_num = get_slab_number(slb_x, slb_y+1); if ((areamap[slb_num] & 0x01) != 0) { areamap[slb_num] |= 0x02; struct SlabMap *slb; slb = get_slabmap_direct(slb_num); struct SlabAttr *slbattr; slbattr = get_slab_attrs(slb); if ((slbattr->category == SlbAtCtg_FriableDirt) && slab_by_players_land(plyr_idx, slb_x, slb_y+1)) { unsigned char pretty_type; pretty_type = choose_pretty_type(plyr_idx, slb_x, slb_y+1); place_slab_type_on_map(pretty_type, slab_subtile(slb_x,0), slab_subtile(slb_y+1,0), plyr_idx, 1u); do_slab_efficiency_alteration(slb_x, slb_y+1); fill_in_reinforced_corners(plyr_idx, slb_x, slb_y+1); } } else if ((areamap[slb_num] & 0x02) == 0) { areamap[slb_num] |= 0x02; slblist[list_len] = slb_num; list_len++; } } slb_x = slb_num_decode_x(slblist[list_cur]); slb_y = slb_num_decode_y(slblist[list_cur]); list_cur++; } pannel_map_update(0, 0, map_subtiles_x+1, map_subtiles_y+1); }
void check_treasure_map(unsigned char *treasure_map, unsigned short *vein_list, long *gold_next_idx, MapSlabCoord veinslb_x, MapSlabCoord veinslb_y) { struct GoldLookup *gldlook; struct SlabMap *slb; SlabCodedCoords slb_num,slb_around; MapSlabCoord slb_x,slb_y; long gold_slabs,gem_slabs; long vein_total,vein_idx; long gld_v1,gld_v2,gld_v3; long gold_idx; // First, find a vein vein_total = 0; slb_x = veinslb_x; slb_y = veinslb_y; gld_v1 = 0; gld_v2 = 0; gld_v3 = 0; gem_slabs = 0; gold_slabs = 0; slb_num = get_slab_number(slb_x, slb_y); treasure_map[slb_num] |= 0x02; for (vein_idx=0; vein_idx <= vein_total; vein_idx++) { gld_v1 += slb_x; gld_v2 += slb_y; gld_v3++; slb_around = get_slab_number(slb_x, slb_y); slb = get_slabmap_direct(slb_around); if (slb->kind == SlbT_GEMS) { gem_slabs++; } else { gold_slabs++; slb_around = get_slab_number(slb_x-1, slb_y); if ((treasure_map[slb_around] & 0x03) == 0) { treasure_map[slb_around] |= 0x02; vein_list[vein_total] = slb_around; vein_total++; } slb_around = get_slab_number(slb_x+1, slb_y); if ((treasure_map[slb_around] & 0x03) == 0) { treasure_map[slb_around] |= 0x02; vein_list[vein_total] = slb_around; vein_total++; } slb_around = get_slab_number(slb_x, slb_y-1); if ((treasure_map[slb_around] & 0x03) == 0) { treasure_map[slb_around] |= 0x02; vein_list[vein_total] = slb_around; vein_total++; } slb_around = get_slab_number(slb_x, slb_y+1); if ((treasure_map[slb_around] & 0x03) == 0) { treasure_map[slb_around] |= 0x02; vein_list[vein_total] = slb_around; vein_total++; } } // Move to next slab in list slb_x = slb_num_decode_x(vein_list[vein_idx]); slb_y = slb_num_decode_y(vein_list[vein_idx]); } // Now get a GoldLookup struct to put the vein into if (*gold_next_idx < GOLD_LOOKUP_COUNT) { gold_idx = *gold_next_idx; (*gold_next_idx)++; } else { gold_idx = smaller_gold_vein_lookup_idx(gold_slabs, gem_slabs); } // Write the vein to GoldLookup item if (gold_idx != -1) { gldlook = get_gold_lookup(gold_idx); LbMemorySet(gldlook, 0, sizeof(struct GoldLookup)); gldlook->flags |= 0x01; gldlook->x_stl_num = slab_subtile_center(gld_v1 / gld_v3); gldlook->y_stl_num = slab_subtile_center(gld_v2 / gld_v3); gldlook->field_A = gold_slabs; gldlook->field_C = 0; gldlook->num_gold_slabs = gold_slabs; gldlook->num_gem_slabs = gem_slabs; SYNCDBG(8,"Added vein %d at (%d,%d)",(int)gold_idx,(int)gldlook->x_stl_num,(int)gldlook->y_stl_num); } }