Crossfire Server, Trunk  R22047
mimic.c
Go to the documentation of this file.
1 /*
2  CrossFire, A Multiplayer game for X-windows
3 
4  Copyright (C) 2018 Mark Wedel & Crossfire Development Team
5  Copyright (C) 1992 Frank Tore Johansen
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21  The authors can be reached via e-mail at crossfire-devel@real-time.com
22 */
23 
30 #include <global.h>
31 #include <ob_methods.h>
32 #include <ob_types.h>
33 #include <sounds.h>
34 #include <sproto.h>
35 #include <string.h>
36 #include <stdlib.h>
37 
38 static method_ret mimic_type_apply(ob_methods *context, object *op, object *applier, int aflags);
39 
43 void init_type_mimic(void) {
45 }
46 
47 static inline const char *object_try_get_value(object *op, const char *key) {
48  const char *val = object_get_value(op, key);
49  return val ? val : "0";
50 }
51 
62 static method_ret mimic_type_apply(ob_methods *context, object *op, object *applier, int aflags) {
63  if (applier->type == PLAYER) {
64 
65  draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS, "Ah! It's alive!");
66  /* We become a monster */
67  op->type = MONSTER;
68  /* We are animated, too, assuming we have a face right now. */
69  if (op->face)
70  {
71  char anim_name_buf[128];
72  int anim_name_len = strlen(op->face->name);
73  strncpy(anim_name_buf, op->face->name, 128);
74  // Remove the .11x from the end of the face name.
75  anim_name_buf[anim_name_len-4] = '\0';
76  strncat(anim_name_buf, "_mimic", 128-anim_name_len+4);
77  op->animation = find_animation(anim_name_buf);
79  }
80  SET_FLAG(op, FLAG_ALIVE);
82  // If we don't have a level set, use the map difficulty
83  if (!op->level)
84  op->level = op->map ? op->map->difficulty : 0;
85  // Set the scalable stats based off the level given to the mimic at load.
86  int level = op->level;
87  op->stats.hp = op->stats.maxhp = op->stats.maxhp + (int16_t)(atof(object_try_get_value(op, "hp_per_level")) * level);
88  op->stats.dam = op->stats.dam + (int16_t)(atof(object_try_get_value(op, "dam_per_level")) * level);
89  op->stats.ac = op->stats.ac + (int8_t)(atof(object_try_get_value(op, "ac_per_level")) * level);
90  op->stats.wc = op->stats.wc + (int8_t)(atof(object_try_get_value(op, "wc_per_level")) * level);
91  op->stats.exp = op->stats.exp + (int64_t)(atof(object_try_get_value(op, "xp_per_level")) * level);
92  op->speed = FABS(op->speed) + atof(object_try_get_value(op, "speed_per_level")) * level;
93  // Set enemy to the triggerer.
94  op->enemy = applier;
95  // TODO: Should this be able to be set dynamically?
96  FREE_AND_COPY(op->name, "mimic");
97  return METHOD_OK;
98  }
99  return METHOD_UNHANDLED;
100 }
static const char * object_try_get_value(object *op, const char *key)
Definition: mimic.c:47
#define SET_FLAG(xyz, p)
Definition: define.h:223
#define FABS(x)
Definition: define.h:22
const char * object_get_value(const object *op, const char *const key)
Definition: object.c:4136
Animations * find_animation(const char *name)
Definition: assets.cpp:265
void draw_ext_info(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *message)
Definition: main.c:308
#define MSG_TYPE_APPLY
Definition: newclient.h:384
char method_ret
Definition: ob_methods.h:14
#define FLAG_ALIVE
Definition: define.h:230
signed short int16_t
Definition: win32.h:160
#define METHOD_OK
Definition: ob_methods.h:15
void register_apply(int ob_type, apply_func method)
Definition: ob_types.c:62
#define METHOD_UNHANDLED
Definition: ob_methods.h:16
signed __int64 int64_t
Definition: win32.h:168
static method_ret mimic_type_apply(ob_methods *context, object *op, object *applier, int aflags)
Definition: mimic.c:62
#define FLAG_ANIMATE
Definition: define.h:242
#define FREE_AND_COPY(sv, nv)
Definition: global.h:204
signed char int8_t
Definition: win32.h:158
#define MSG_TYPE_APPLY_SUCCESS
Definition: newclient.h:598
#define FLAG_MONSTER
Definition: define.h:245
#define NDI_UNIQUE
Definition: newclient.h:245
int level
Definition: readable.c:1589
void init_type_mimic(void)
Definition: mimic.c:43