1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409
|
static int randquest_hero[] = { 20, 13, 15, 16, 9, 17, 18, -1 };
bool is_randhero()
{
int i;
for (i = 0; randquest_hero[i] != -1; i++)
if (random_quests[dun_level].type == randquest_hero[i]) break;
if (randquest_hero[i] != -1)
return (TRUE);
else
return (FALSE);
}
void do_get_new_obj(int y, int x)
{
obj_theme theme;
char *items[3];
object_type *q_ptr[3], forge[3];
int max = 0, res, i;
/* Create 3 ones */
max = 0;
for (i = 0; i < 3; i++)
{
/* Get local object */
q_ptr[max] = &forge[max];
/* Wipe the object */
object_wipe(q_ptr[max]);
/* No themes */
theme.treasure = 100;
theme.combat = 100;
theme.magic = 100;
theme.tools = 100;
/* Make a great object */
make_object(q_ptr[max], TRUE, TRUE, theme);
q_ptr[max]->found = OBJ_FOUND_REWARD;
C_MAKE(items[max], 100, char);
object_desc(items[max], q_ptr[max], 0, 0);
max++;
}
while (TRUE)
{
res = ask_menu("Choose a reward to get(a-c to choose, ESC to cancel)?", (char **)items, 3);
/* Ok ? lets learn ! */
if (res > -1)
{
/* Drop it in the dungeon */
drop_near(q_ptr[res], -1, y + 1, x);
cmsg_print(TERM_YELLOW, "There Noble Hero, I put it there. Thanks again!");
break;
}
}
for (i = 0; i < 3; i++)
{
object_type *o_ptr = q_ptr[i];
/* Check if there is any not chosen artifact */
if (i != res && artifact_p(o_ptr))
{
/* Mega-Hack -- Preserve the artifact */
if (o_ptr->tval == TV_RANDART)
{
random_artifacts[o_ptr->sval].generated = FALSE;
}
else if (k_info[o_ptr->k_idx].flags3 & TR3_NORM_ART)
{
k_info[o_ptr->k_idx].artifact = FALSE;
}
else if (o_ptr->name1)
{
a_info[o_ptr->name1].cur_num = 0;
}
}
}
for (i = 0; i < 3; i++)
C_KILL(items[i], 100, char);
}
void princess_death(s32b m_idx, s32b r_idx)
{
int r;
cmsg_print(TERM_YELLOW, "O Great And Noble Hero, you saved me!");
cmsg_print(TERM_YELLOW, "I am heading home now. I cannot reward you as I should, but please take this.");
/* Look for the princess */
for (r = m_max - 1; r >= 1; r--)
{
/* Access the monster */
monster_type *m_ptr = &m_list[r];
/* Ignore "dead" monsters */
if (!m_ptr->r_idx) continue;
/* Is it the princess? */
if (m_ptr->r_idx == 969)
{
int x = m_ptr->fx;
int y = m_ptr->fy;
int i, j;
delete_monster_idx(r);
/* Wipe the glass walls and create a stair */
for (i = x - 1; i <= x + 1; i++)
for (j = y - 1; j <= y + 1; j++)
{
if (in_bounds(j, i)) cave_set_feat(j, i, FEAT_FLOOR);
}
cave_set_feat(y, x, FEAT_MORE);
do_get_new_obj(y, x);
random_quests[dun_level].type = 0;
random_quests[dun_level].done = TRUE;
break;
}
}
}
void hero_death(s32b m_idx, s32b r_idx)
{
random_quests[dun_level].type = 0;
random_quests[dun_level].done = TRUE;
cmsg_print(TERM_YELLOW, "The adventurer steps out of the shadows and picks up his sword:");
cmsg_print(TERM_YELLOW, "'Ah ! my sword ! my trusty sword ! Thanks.");
if (!can_create_companion())
{
cmsg_print(TERM_YELLOW, "I must go on my own way now");
cmsg_print(TERM_YELLOW, "But before I can help your skills.'");
cmsg_print(TERM_YELLOW, "He touches your forehead.");
do_get_new_skill();
return;
}
cmsg_print(TERM_YELLOW, "If you wish I can help you in your adventures.'");
/* Flush input */
flush();
if (get_check("Do you want him to join you? "))
{
int x, y, i;
/* Look for a location */
for (i = 0; i < 20; ++i)
{
/* Pick a distance */
int d = (i / 15) + 1;
/* Pick a location */
scatter(&y, &x, p_ptr->py, p_ptr->px, d, 0);
/* Require "empty" floor grid */
if (!cave_empty_bold(y, x)) continue;
/* Hack -- no summon on glyph of warding */
if (cave[y][x].feat == FEAT_GLYPH) continue;
if (cave[y][x].feat == FEAT_MINOR_GLYPH) continue;
/* Nor on the between */
if (cave[y][x].feat == FEAT_BETWEEN) continue;
/* ... nor on the Pattern */
if ((cave[y][x].feat >= FEAT_PATTERN_START) &&
(cave[y][x].feat <= FEAT_PATTERN_XTRA2))
continue;
/* Okay */
break;
}
if (i < 20)
{
int m_idx;
m_allow_special[test_monster_name("Adventurer")] = TRUE;
m_idx = place_monster_one(y, x, test_monster_name("Adventurer"), 0, FALSE, MSTATUS_COMPANION);
m_allow_special[test_monster_name("Adventurer")] = FALSE;
if (m_idx)
{
m_list[m_idx].exp = MONSTER_EXP(1 + (dun_level * 3 / 2));
m_list[m_idx].status = MSTATUS_COMPANION;
monster_check_experience(m_idx, TRUE);
}
}
else
msg_print("The adventurer suddenly seems afraid and flees...");
}
else
{
cmsg_print(TERM_YELLOW, "'As you wish, but I want to do something for you.'");
cmsg_print(TERM_YELLOW, "He touches your forehead.");
do_get_new_skill();
}
}
bool quest_random_death_hook(char *fmt)
{
int r_idx;
s32b m_idx;
m_idx = get_next_arg(fmt);
r_idx = m_list[m_idx].r_idx;
if (!(dungeon_flags1 & DF1_PRINCIPAL)) return (FALSE);
if ((dun_level < 1) || (dun_level >= MAX_RANDOM_QUEST)) return (FALSE);
if (!random_quests[dun_level].type) return (FALSE);
if (p_ptr->inside_quest) return (FALSE);
if (random_quests[dun_level].r_idx != r_idx) return (FALSE);
if (!(m_list[m_idx].mflag & MFLAG_QUEST)) return (FALSE);
/* Killed enough ?*/
quest[QUEST_RANDOM].data[0]++;
if (quest[QUEST_RANDOM].data[0] == random_quests[dun_level].type)
{
if (is_randhero())
hero_death(m_idx, r_idx);
else
princess_death(m_idx, r_idx);
}
return (FALSE);
}
bool quest_random_turn_hook(char *fmt)
{
quest[QUEST_RANDOM].data[0] = 0;
quest[QUEST_RANDOM].data[1] = 0;
return (FALSE);
}
bool quest_random_feeling_hook(char *fmt)
{
if (!(dungeon_flags1 & DF1_PRINCIPAL)) return (FALSE);
if ((dun_level < 1) || (dun_level >= MAX_RANDOM_QUEST)) return (FALSE);
if (!random_quests[dun_level].type) return (FALSE);
if (p_ptr->inside_quest) return (FALSE);
if (!dun_level) return (FALSE);
if (is_randhero())
{
cmsg_format(TERM_YELLOW, "A strange man wrapped in a dark cloak steps out of the shadows:");
cmsg_format(TERM_YELLOW, "'Ah please help me ! A group of %s stole my sword! I'm nothing without it'", r_info[random_quests[dun_level].r_idx].name + r_name);
}
else
cmsg_format(TERM_YELLOW, "You hear someone shouting: 'Leave me alone, stupid %s'", r_info[random_quests[dun_level].r_idx].name + r_name);
return (FALSE);
}
bool quest_random_gen_hero_hook(char *fmt)
{
int i;
if (!(dungeon_flags1 & DF1_PRINCIPAL)) return (FALSE);
if ((dun_level < 1) || (dun_level >= MAX_RANDOM_QUEST)) return (FALSE);
if (!random_quests[dun_level].type) return (FALSE);
if (p_ptr->inside_quest) return (FALSE);
if (!is_randhero()) return (FALSE);
i = random_quests[dun_level].type;
m_allow_special[random_quests[dun_level].r_idx] = TRUE;
while (i)
{
int m_idx, y = rand_range(1, cur_hgt - 2), x = rand_range(1, cur_wid - 2);
m_idx = place_monster_one(y, x, random_quests[dun_level].r_idx, 0, FALSE, MSTATUS_ENEMY);
if (m_idx)
{
monster_type *m_ptr = &m_list[m_idx];
m_ptr->mflag |= MFLAG_QUEST;
i--;
}
}
m_allow_special[random_quests[dun_level].r_idx] = FALSE;
return (FALSE);
}
bool quest_random_gen_hook(char *fmt)
{
s32b x, y, bx0, by0;
int xstart;
int ystart;
int y2, x2, yval, xval;
int y1, x1, xsize, ysize;
cave_type *c_ptr;
by0 = get_next_arg(fmt);
bx0 = get_next_arg(fmt);
if (!(dungeon_flags1 & DF1_PRINCIPAL)) return (FALSE);
if ((dun_level < 1) || (dun_level >= MAX_RANDOM_QUEST)) return (FALSE);
if (!random_quests[dun_level].type) return (FALSE);
if (p_ptr->inside_quest) return (FALSE);
if (quest[QUEST_RANDOM].data[1]) return (FALSE);
if (is_randhero()) return (FALSE);
/* Pick a room size */
xsize = 0;
ysize = 0;
init_flags = INIT_GET_SIZE;
process_dungeon_file_full = TRUE;
process_dungeon_file(NULL, format("qrand%d.map", random_quests[dun_level].type), &ysize, &xsize, cur_hgt, cur_wid, TRUE);
process_dungeon_file_full = FALSE;
/* Try to allocate space for room. If fails, exit */
if (!room_alloc(xsize + 2, ysize + 2, FALSE, by0, bx0, &xval, &yval)) return FALSE;
/* Get corner values */
y1 = yval - ysize / 2;
x1 = xval - xsize / 2;
y2 = yval + (ysize) / 2;
x2 = xval + (xsize) / 2;
/* Place a full floor under the room */
for (y = y1 - 1; y <= y2 + 1; y++)
{
for (x = x1 - 1; x <= x2 + 1; x++)
{
c_ptr = &cave[y][x];
cave_set_feat(y, x, floor_type[rand_int(100)]);
c_ptr->info |= (CAVE_ROOM);
c_ptr->info |= (CAVE_GLOW);
}
}
build_rectangle(y1 - 1, x1 - 1, y2 + 1, x2 + 1, feat_wall_outer, CAVE_ROOM | CAVE_GLOW);
/* Set the correct monster hook */
set_mon_num_hook();
/* Prepare allocation table */
get_mon_num_prep();
xstart = x1;
ystart = y1;
init_flags = INIT_CREATE_DUNGEON;
process_dungeon_file_full = TRUE;
process_dungeon_file(NULL, format("qrand%d.map", random_quests[dun_level].type), &ystart, &xstart, cur_hgt, cur_wid, TRUE);
process_dungeon_file_full = FALSE;
for (x = x1; x < xstart; x++)
for (y = y1; y < ystart; y++)
{
cave[y][x].info |= CAVE_ICKY | CAVE_ROOM;
if (cave[y][x].feat == FEAT_MARKER)
{
monster_type *m_ptr;
int i;
m_allow_special[random_quests[dun_level].r_idx] = TRUE;
i = place_monster_one(y, x, random_quests[dun_level].r_idx, 0, FALSE, MSTATUS_ENEMY);
m_allow_special[random_quests[dun_level].r_idx] = FALSE;
if (i)
{
m_ptr = &m_list[i];
m_ptr->mflag |= MFLAG_QUEST;
}
}
}
/* Dont try another one for this generation */
quest[QUEST_RANDOM].data[1] = 1;
/* Boost level feeling a bit - a la pits */
rating += 10;
return (TRUE);
}
bool quest_random_dump_hook(char *fmt)
{
int i, p = 0;
for (i = 0; i < MAX_RANDOM_QUEST; i++)
{
if (random_quests[i].done) p++;
}
if (p > 1) fprintf(hook_file, "\n You saved %d princesses.", p);
else if (p == 1) fprintf(hook_file, "\n You saved one princess.");
else fprintf(hook_file, "\n You saved no princesses.");
return (FALSE);
}
bool quest_random_init_hook(int q_idx)
{
add_hook(HOOK_MONSTER_DEATH, quest_random_death_hook, "rand_death");
add_hook(HOOK_NEW_LEVEL, quest_random_turn_hook, "rand_new_lvl");
add_hook(HOOK_LEVEL_REGEN, quest_random_turn_hook, "rand_regen_lvl");
add_hook(HOOK_LEVEL_END_GEN, quest_random_gen_hero_hook, "rand_gen_hero");
add_hook(HOOK_BUILD_ROOM1, quest_random_gen_hook, "rand_gen");
add_hook(HOOK_FEELING, quest_random_feeling_hook, "rand_feel");
add_hook(HOOK_CHAR_DUMP, quest_random_dump_hook, "rand_dump");
return (FALSE);
}
|