Crossfire Server, Trunk  R21024
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 
37 static method_ret mimic_type_apply(ob_methods *context, object *op, object *applier, int aflags);
38 
42 void init_type_mimic(void) {
44 }
45 
56 static method_ret mimic_type_apply(ob_methods *context, object *op, object *applier, int aflags) {
57  if (applier->type == PLAYER) {
58 
59  draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS, "Ah! Its alive!");
60  /* We become a monster */
61  op->type = MONSTER;
62  /* We are animated, too, assuming we have a face right now. */
63  if (op->face)
64  {
65  char anim_name_buf[128];
66  int anim_name_len = strlen(op->face->name);
67  strncpy(anim_name_buf, op->face->name, 128);
68  // Remove the .11x from the end of the face name.
69  anim_name_buf[anim_name_len-4] = '\0';
70  strncat(anim_name_buf, "_mimic", 128-anim_name_len+4);
71  op->animation_id = find_animation(anim_name_buf);
73  }
74  SET_FLAG(op, FLAG_ALIVE);
76  op->enemy = applier;
77  // TODO: Should this be able to be set dynamically?
78  FREE_AND_COPY(op->name, "mimic");
79  return METHOD_OK;
80  }
81  return METHOD_UNHANDLED;
82 }
#define SET_FLAG(xyz, p)
Definition: define.h:223
uint16_t animation_id
Definition: object.h:416
Definition: object.h:249
struct obj * enemy
Definition: object.h:381
void draw_ext_info(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *message)
Definition: main.c:310
#define MSG_TYPE_APPLY
Definition: newclient.h:384
char method_ret
Definition: ob_methods.h:14
const char * name
Definition: face.h:20
#define FLAG_ALIVE
Definition: define.h:230
#define METHOD_OK
Definition: ob_methods.h:15
const char * name
Definition: object.h:311
int find_animation(const char *name)
Definition: anim.c:170
void register_apply(int ob_type, apply_func method)
Definition: ob_types.c:62
#define METHOD_UNHANDLED
Definition: ob_methods.h:16
static method_ret mimic_type_apply(ob_methods *context, object *op, object *applier, int aflags)
Definition: mimic.c:56
Definition: object.h:107
#define FLAG_ANIMATE
Definition: define.h:242
#define FREE_AND_COPY(sv, nv)
Definition: global.h:211
uint8_t type
Definition: object.h:338
#define MSG_TYPE_APPLY_SUCCESS
Definition: newclient.h:598
#define FLAG_MONSTER
Definition: define.h:245
#define NDI_UNIQUE
Definition: newclient.h:245
const New_Face * face
Definition: object.h:332
void init_type_mimic(void)
Definition: mimic.c:42