1 | /* |
1 | /* |
2 | * CrossFire, A Multiplayer game |
2 | * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. |
3 | * |
3 | * |
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team |
5 | * Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * This program is free software; you can redistribute it and/or modify |
8 | * Crossfire TRT is free software: you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by |
9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation; either version 2 of the License, or |
10 | * the Free Software Foundation, either version 3 of the License, or |
11 | * (at your option) any later version. |
11 | * (at your option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the GNU General Public License |
19 | * along with this program; if not, write to the Free Software |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|
|
21 | * |
20 | * |
22 | * The author can be reached via e-mail to <crossfire@schmorp.de> |
21 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
23 | */ |
22 | */ |
24 | |
23 | |
25 | #include <global.h> |
24 | #include <global.h> |
26 | #include <sproto.h> |
25 | #include <sproto.h> |
27 | #include <sounds.h> |
26 | #include <sounds.h> |
… | |
… | |
157 | op->x = -1; |
156 | op->x = -1; |
158 | op->y = -1; |
157 | op->y = -1; |
159 | } |
158 | } |
160 | |
159 | |
161 | void |
160 | void |
162 | player::enter_map () |
|
|
163 | { |
|
|
164 | object *tmp = object::create (); |
|
|
165 | |
|
|
166 | EXIT_PATH (tmp) = maplevel; |
|
|
167 | EXIT_X (tmp) = ob->x; |
|
|
168 | EXIT_Y (tmp) = ob->y; |
|
|
169 | ob->enter_exit (tmp); |
|
|
170 | |
|
|
171 | tmp->destroy (); |
|
|
172 | } |
|
|
173 | |
|
|
174 | void |
|
|
175 | player::activate () |
161 | player::activate () |
176 | { |
162 | { |
177 | if (active) |
163 | if (active) |
178 | return; |
164 | return; |
179 | |
165 | |
… | |
… | |
181 | ob->remove (); |
167 | ob->remove (); |
182 | ob->map = 0; |
168 | ob->map = 0; |
183 | ob->activate_recursive (); |
169 | ob->activate_recursive (); |
184 | CLEAR_FLAG (ob, FLAG_FRIENDLY); |
170 | CLEAR_FLAG (ob, FLAG_FRIENDLY); |
185 | add_friendly_object (ob); |
171 | add_friendly_object (ob); |
186 | enter_map (); |
|
|
187 | } |
172 | } |
188 | |
173 | |
189 | void |
174 | void |
190 | player::deactivate () |
175 | player::deactivate () |
191 | { |
176 | { |
… | |
… | |
221 | ob->close_container (); //TODO: client-specific |
206 | ob->close_container (); //TODO: client-specific |
222 | |
207 | |
223 | ns->update_look = 0; |
208 | ns->update_look = 0; |
224 | ns->look_position = 0; |
209 | ns->look_position = 0; |
225 | |
210 | |
226 | clear_los (ob); |
211 | clear_los (this); |
227 | |
212 | |
228 | ns->reset_stats (); |
213 | ns->reset_stats (); |
229 | |
214 | |
230 | /* make sure he's a player -- needed because of class change. */ |
215 | /* make sure he's a player -- needed because of class change. */ |
231 | ob->type = PLAYER; // we are paranoid |
216 | ob->type = PLAYER; // we are paranoid |
232 | ob->race = ob->arch->clone.race; |
217 | ob->race = ob->arch->race; |
233 | |
218 | |
234 | ob->carrying = sum_weight (ob); |
219 | ob->carrying = sum_weight (ob); |
235 | link_player_skills (ob); |
220 | link_player_skills (ob); |
236 | |
221 | |
237 | CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER); |
222 | CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER); |
238 | |
223 | |
239 | assign (title, ob->arch->clone.name); |
224 | assign (title, ob->arch->object::name); |
240 | |
225 | |
241 | /* if it's a dragon player, set the correct title here */ |
226 | /* if it's a dragon player, set the correct title here */ |
242 | if (is_dragon_pl (ob)) |
227 | if (is_dragon_pl (ob)) |
243 | { |
228 | { |
244 | object *tmp, *abil = 0, *skin = 0; |
229 | object *tmp, *abil = 0, *skin = 0; |
245 | |
230 | |
246 | shstr_cmp dragon_ability_force ("dragon_ability_force"); |
|
|
247 | shstr_cmp dragon_skin_force ("dragon_skin_force"); |
|
|
248 | |
|
|
249 | for (tmp = ob->inv; tmp; tmp = tmp->below) |
231 | for (tmp = ob->inv; tmp; tmp = tmp->below) |
250 | if (tmp->type == FORCE) |
232 | if (tmp->type == FORCE) |
251 | if (tmp->arch->name == dragon_ability_force) |
233 | if (tmp->arch->archname == shstr_dragon_ability_force) |
252 | abil = tmp; |
234 | abil = tmp; |
253 | else if (tmp->arch->name == dragon_skin_force) |
235 | else if (tmp->arch->archname == shstr_dragon_skin_force) |
254 | skin = tmp; |
236 | skin = tmp; |
255 | |
237 | |
256 | set_dragon_name (ob, abil, skin); |
238 | set_dragon_name (ob, abil, skin); |
257 | } |
239 | } |
258 | |
240 | |
… | |
… | |
317 | } |
299 | } |
318 | |
300 | |
319 | if (ob) |
301 | if (ob) |
320 | ob->close_container (); //TODO: client-specific |
302 | ob->close_container (); //TODO: client-specific |
321 | |
303 | |
|
|
304 | observe = ob; |
|
|
305 | |
322 | deactivate (); |
306 | deactivate (); |
323 | } |
307 | } |
324 | |
308 | |
325 | // the need for this function can be explained |
309 | // the need for this function can be explained |
326 | // by load_object not returning the object |
310 | // by load_object not returning the object |
327 | void |
311 | void |
328 | player::set_object (object *op) |
312 | player::set_object (object *op) |
329 | { |
313 | { |
330 | ob = op; |
314 | ob = observe = op; |
331 | ob->contr = this; /* this aren't yet in archetype */ |
315 | ob->contr = this; /* this aren't yet in archetype */ |
332 | |
316 | |
333 | ob->speed = 1.0f; |
317 | ob->speed = 1.0f; |
334 | ob->speed_left = 0.5f; |
318 | ob->speed_left = 0.5f; |
335 | |
319 | |
336 | ob->direction = 5; /* So player faces south */ |
320 | ob->direction = 5; /* So player faces south */ |
|
|
321 | } |
|
|
322 | |
|
|
323 | void |
|
|
324 | player::set_observe (object *op) |
|
|
325 | { |
|
|
326 | observe = op ? op : ob; |
|
|
327 | do_los = 1; |
337 | } |
328 | } |
338 | |
329 | |
339 | player::player () |
330 | player::player () |
340 | { |
331 | { |
341 | /* There are some elements we want initialised to non zero value - |
332 | /* There are some elements we want initialised to non zero value - |
… | |
… | |
369 | if (ob) |
360 | if (ob) |
370 | { |
361 | { |
371 | ob->destroy_inv (false); |
362 | ob->destroy_inv (false); |
372 | ob->destroy (); |
363 | ob->destroy (); |
373 | } |
364 | } |
|
|
365 | |
|
|
366 | ob = observe = 0; |
374 | } |
367 | } |
375 | |
368 | |
376 | player::~player () |
369 | player::~player () |
377 | { |
370 | { |
378 | /* Clear item stack */ |
371 | /* Clear item stack */ |
… | |
… | |
405 | * Note: there MUST be at least one player archetype! |
398 | * Note: there MUST be at least one player archetype! |
406 | */ |
399 | */ |
407 | archetype * |
400 | archetype * |
408 | get_player_archetype (archetype *at) |
401 | get_player_archetype (archetype *at) |
409 | { |
402 | { |
410 | archetype *start = at; |
403 | archvec::iterator i = at ? archetypes.find (at) : archetypes.begin (); |
411 | |
404 | |
412 | for (;;) |
405 | for (;;) |
413 | { |
406 | { |
414 | if (at == NULL || at->next == NULL) |
407 | if (++i == archetypes.end ()) |
415 | at = first_archetype; |
408 | i = archetypes.begin (); |
416 | else |
409 | else if (*i == at) |
417 | at = at->next; |
410 | cleanup ("not a single player archetype found"); |
418 | |
411 | |
419 | if (at->clone.type == PLAYER) |
412 | if ((*i)->type == PLAYER) |
420 | return at; |
413 | return *i; |
421 | |
|
|
422 | if (at == start) |
|
|
423 | { |
|
|
424 | LOG (llevError, "No Player archetypes\n"); |
|
|
425 | exit (-1); |
|
|
426 | } |
|
|
427 | } |
414 | } |
428 | } |
415 | } |
429 | |
416 | |
430 | object * |
417 | object * |
431 | get_nearest_player (object *mon) |
418 | get_nearest_player (object *mon) |
… | |
… | |
921 | if (*first_map_ext_path) |
908 | if (*first_map_ext_path) |
922 | { |
909 | { |
923 | object *tmp; |
910 | object *tmp; |
924 | char mapname[MAX_BUF]; |
911 | char mapname[MAX_BUF]; |
925 | |
912 | |
926 | snprintf (mapname, MAX_BUF - 1, "%s/%s", &first_map_ext_path, &ob->arch->name); |
913 | snprintf (mapname, MAX_BUF - 1, "%s/%s", &first_map_ext_path, &ob->arch->archname); |
927 | tmp = object::create (); |
914 | tmp = object::create (); |
928 | EXIT_PATH (tmp) = mapname; |
915 | EXIT_PATH (tmp) = mapname; |
929 | EXIT_X (tmp) = ob->x; |
916 | EXIT_X (tmp) = ob->x; |
930 | EXIT_Y (tmp) = ob->y; |
917 | EXIT_Y (tmp) = ob->y; |
931 | ob->enter_exit (tmp); /* we don't really care if it succeeded; |
918 | ob->enter_exit (tmp); /* we don't really care if it succeeded; |
… | |
… | |
950 | int x = ob->x, y = ob->y; |
937 | int x = ob->x, y = ob->y; |
951 | |
938 | |
952 | ob->remove_statbonus (); |
939 | ob->remove_statbonus (); |
953 | ob->remove (); |
940 | ob->remove (); |
954 | ob->arch = get_player_archetype (ob->arch); |
941 | ob->arch = get_player_archetype (ob->arch); |
955 | ob->arch->clone.copy_to (ob); |
942 | ob->arch->copy_to (ob); |
956 | ob->instantiate (); |
943 | ob->instantiate (); |
957 | ob->stats = ob->contr->orig_stats; |
944 | ob->stats = ob->contr->orig_stats; |
958 | ob->name = ob->name_pl = name; |
945 | ob->name = ob->name_pl = name; |
959 | ob->x = x; |
946 | ob->x = x; |
960 | ob->y = y; |
947 | ob->y = y; |
961 | SET_ANIMATION (ob, 2); /* So player faces south */ |
948 | SET_ANIMATION (ob, 2); /* So player faces south */ |
962 | insert_ob_in_map (ob, ob->map, ob, 0); |
949 | insert_ob_in_map (ob, ob->map, ob, 0); |
963 | assign (ob->contr->title, ob->arch->clone.name); |
950 | assign (ob->contr->title, ob->arch->object::name); |
964 | ob->add_statbonus (); |
951 | ob->add_statbonus (); |
965 | } |
952 | } |
966 | while (!allowed_class (ob)); |
953 | while (!allowed_class (ob)); |
967 | |
954 | |
968 | update_object (ob, UP_OBJ_FACE); |
955 | update_object (ob, UP_OBJ_FACE); |
… | |
… | |
1113 | if (tmp->name != NULL) |
1100 | if (tmp->name != NULL) |
1114 | sprintf (putstring, "item name: %s item type: %d weight/value: %d", |
1101 | sprintf (putstring, "item name: %s item type: %d weight/value: %d", |
1115 | &tmp->name, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1)))); |
1102 | &tmp->name, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1)))); |
1116 | else |
1103 | else |
1117 | sprintf (putstring, "item name: %s item type: %d weight/value: %d", |
1104 | sprintf (putstring, "item name: %s item type: %d weight/value: %d", |
1118 | &tmp->arch->name, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1)))); |
1105 | &tmp->arch->archname, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1)))); |
1119 | |
1106 | |
1120 | new_draw_info (NDI_UNIQUE, 0, op, putstring); |
1107 | new_draw_info (NDI_UNIQUE, 0, op, putstring); |
1121 | } |
1108 | } |
1122 | |
1109 | |
1123 | /* philosophy: |
1110 | /* philosophy: |
… | |
… | |
1316 | /* careful: chairs and tables are weapons! */ |
1303 | /* careful: chairs and tables are weapons! */ |
1317 | if (op->contr->mode & PU_ALLWEAPON) |
1304 | if (op->contr->mode & PU_ALLWEAPON) |
1318 | { |
1305 | { |
1319 | if (tmp->type == WEAPON && tmp->name != NULL) |
1306 | if (tmp->type == WEAPON && tmp->name != NULL) |
1320 | { |
1307 | { |
1321 | if (strstr (tmp->name, "table") == NULL && strstr (tmp->arch->name, "table") == NULL && |
1308 | if (strstr (tmp->name, "table") == NULL && strstr (tmp->arch->archname, "table") == NULL && |
1322 | strstr (tmp->name, "chair") && strstr (tmp->arch->name, "chair") == NULL) |
1309 | strstr (tmp->name, "chair") && strstr (tmp->arch->archname, "chair") == NULL) |
1323 | { |
1310 | { |
1324 | pick_up (op, tmp); |
1311 | pick_up (op, tmp); |
1325 | continue; |
1312 | continue; |
1326 | } |
1313 | } |
1327 | } |
1314 | } |
1328 | |
1315 | |
1329 | if (tmp->type == WEAPON && tmp->name == NULL) |
1316 | if (tmp->type == WEAPON && tmp->name == NULL) |
1330 | { |
1317 | { |
1331 | if (strstr (tmp->arch->name, "table") == NULL && strstr (tmp->arch->name, "chair") == NULL) |
1318 | if (strstr (tmp->arch->archname, "table") == NULL && strstr (tmp->arch->archname, "chair") == NULL) |
1332 | { |
1319 | { |
1333 | pick_up (op, tmp); |
1320 | pick_up (op, tmp); |
1334 | continue; |
1321 | continue; |
1335 | } |
1322 | } |
1336 | } |
1323 | } |
… | |
… | |
1361 | if (tmp->name != NULL) |
1348 | if (tmp->name != NULL) |
1362 | { |
1349 | { |
1363 | fprintf (stderr, "%s", tmp->name); |
1350 | fprintf (stderr, "%s", tmp->name); |
1364 | } |
1351 | } |
1365 | else |
1352 | else |
1366 | fprintf (stderr, "%s", tmp->arch->name); |
1353 | fprintf (stderr, "%s", tmp->arch->archname); |
1367 | fprintf (stderr, ",%d] = ", tmp->type); |
1354 | fprintf (stderr, ",%d] = ", tmp->type); |
1368 | fprintf (stderr, "%d\n", (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1)))); |
1355 | fprintf (stderr, "%d\n", (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1)))); |
1369 | #endif |
1356 | #endif |
1370 | continue; |
1357 | continue; |
1371 | } |
1358 | } |
… | |
… | |
1441 | else |
1428 | else |
1442 | { |
1429 | { |
1443 | for (attacknum = 0; attacknum < NROFATTACKS; attacknum++) |
1430 | for (attacknum = 0; attacknum < NROFATTACKS; attacknum++) |
1444 | { |
1431 | { |
1445 | attacktype = 1 << attacknum; |
1432 | attacktype = 1 << attacknum; |
1446 | if ((arrow->attacktype & attacktype) && (target->arch->clone.resist[attacknum]) < 0) |
1433 | if ((arrow->attacktype & attacktype) && (target->arch->resist[attacknum]) < 0) |
1447 | if (((arrow->magic + arrow->stats.dam) * (100 - target->arch->clone.resist[attacknum]) / 100) > betterby) |
1434 | if (((arrow->magic + arrow->stats.dam) * (100 - target->arch->resist[attacknum]) / 100) > betterby) |
1448 | { |
1435 | { |
1449 | tmp = arrow; |
1436 | tmp = arrow; |
1450 | betterby = (arrow->magic + arrow->stats.dam) * (100 - target->arch->clone.resist[attacknum]) / 100; |
1437 | betterby = (arrow->magic + arrow->stats.dam) * (100 - target->arch->resist[attacknum]) / 100; |
1451 | } |
1438 | } |
1452 | } |
1439 | } |
1453 | if ((2 + arrow->magic + arrow->stats.dam) > betterby) |
1440 | if ((2 + arrow->magic + arrow->stats.dam) > betterby) |
1454 | { |
1441 | { |
1455 | tmp = arrow; |
1442 | tmp = arrow; |
… | |
… | |
1814 | object *tmp; |
1801 | object *tmp; |
1815 | |
1802 | |
1816 | if (item->arch) |
1803 | if (item->arch) |
1817 | { |
1804 | { |
1818 | CLEAR_FLAG (item, FLAG_ANIMATE); |
1805 | CLEAR_FLAG (item, FLAG_ANIMATE); |
1819 | item->face = item->arch->clone.face; |
1806 | item->face = item->arch->face; |
1820 | item->set_speed (0); |
1807 | item->set_speed (0); |
1821 | } |
1808 | } |
1822 | |
1809 | |
1823 | if ((tmp = item->in_player ())) |
1810 | if ((tmp = item->in_player ())) |
1824 | esrv_update_item (UPD_ANIM, tmp, item); |
1811 | esrv_update_item (UPD_ANIM, tmp, item); |
… | |
… | |
2180 | * that party_number -1 is no party, so attacks can still happen. |
2167 | * that party_number -1 is no party, so attacks can still happen. |
2181 | */ |
2168 | */ |
2182 | else if ((mon->stats.hp >= 0) && QUERY_FLAG (mon, FLAG_ALIVE) && |
2169 | else if ((mon->stats.hp >= 0) && QUERY_FLAG (mon, FLAG_ALIVE) && |
2183 | ((mon->type != PLAYER || op->contr->party == NULL || op->contr->party != mon->contr->party))) |
2170 | ((mon->type != PLAYER || op->contr->party == NULL || op->contr->party != mon->contr->party))) |
2184 | { |
2171 | { |
2185 | if (op->contr->weapon_sp_left > 0.f) |
2172 | if (op->contr->weapon_sp_left > 0.f && !op->flag [FLAG_WIZPASS]) |
2186 | { |
2173 | { |
2187 | --op->contr->weapon_sp_left; |
2174 | --op->contr->weapon_sp_left; |
2188 | |
2175 | |
2189 | skill_attack (mon, op, 0, 0, 0); |
2176 | skill_attack (mon, op, 0, 0, 0); |
2190 | |
2177 | |
… | |
… | |
3047 | } |
3034 | } |
3048 | |
3035 | |
3049 | int |
3036 | int |
3050 | is_true_undead (object *op) |
3037 | is_true_undead (object *op) |
3051 | { |
3038 | { |
3052 | if (QUERY_FLAG (&op->arch->clone, FLAG_UNDEAD)) |
3039 | if (QUERY_FLAG (op->arch, FLAG_UNDEAD)) |
3053 | return 1; |
3040 | return 1; |
3054 | |
3041 | |
3055 | return 0; |
3042 | return 0; |
3056 | } |
3043 | } |
3057 | |
3044 | |
… | |
… | |
3227 | * a blocked los square. |
3214 | * a blocked los square. |
3228 | * we use the archetype to figure out offsets. |
3215 | * we use the archetype to figure out offsets. |
3229 | */ |
3216 | */ |
3230 | while (op) |
3217 | while (op) |
3231 | { |
3218 | { |
3232 | dx = rv.distance_x + op->arch->clone.x; |
3219 | dx = rv.distance_x + op->arch->x; |
3233 | dy = rv.distance_y + op->arch->clone.y; |
3220 | dy = rv.distance_y + op->arch->y; |
3234 | |
3221 | |
3235 | /* only the viewable area the player sees is updated by LOS |
3222 | /* only the viewable area the player sees is updated by LOS |
3236 | * code, so we need to restrict ourselves to that range of values |
3223 | * code, so we need to restrict ourselves to that range of values |
3237 | * for any meaningful values. |
3224 | * for any meaningful values. |
3238 | */ |
3225 | */ |
… | |
… | |
3363 | /* LOG(llevDebug, "-> no more treasure for %s\n", change_resist_msg[atnr]); */ |
3350 | /* LOG(llevDebug, "-> no more treasure for %s\n", change_resist_msg[atnr]); */ |
3364 | return; |
3351 | return; |
3365 | } |
3352 | } |
3366 | |
3353 | |
3367 | /* everything seems okay - now bring on the gift: */ |
3354 | /* everything seems okay - now bring on the gift: */ |
3368 | item = &(tr->item->clone); |
3355 | item = tr->item; |
3369 | |
3356 | |
3370 | if (item->type == SPELL) |
3357 | if (item->type == SPELL) |
3371 | { |
3358 | { |
3372 | if (check_spell_known (who, item->name)) |
3359 | if (check_spell_known (who, item->name)) |
3373 | return; |
3360 | return; |
… | |
… | |
3432 | { |
3419 | { |
3433 | /* forces in the treasurelist can alter the player's stats */ |
3420 | /* forces in the treasurelist can alter the player's stats */ |
3434 | object *skin; |
3421 | object *skin; |
3435 | |
3422 | |
3436 | /* first get the dragon skin force */ |
3423 | /* first get the dragon skin force */ |
3437 | shstr_cmp dragon_skin_force ("dragon_skin_force"); |
|
|
3438 | for (skin = who->inv; skin && !(skin->arch->name == dragon_skin_force); skin = skin->below) |
3424 | for (skin = who->inv; skin && !(skin->arch->archname == shstr_dragon_skin_force); skin = skin->below) |
3439 | ; |
3425 | ; |
3440 | |
3426 | |
3441 | if (!skin) |
3427 | if (!skin) |
3442 | return; |
3428 | return; |
3443 | |
3429 | |