Atrinik Server  4.0
monster.c
Go to the documentation of this file.
1 /*************************************************************************
2  * Atrinik, a Multiplayer Online Role Playing Game *
3  * *
4  * Copyright (C) 2009-2014 Alex Tokar and Atrinik Development Team *
5  * *
6  * Fork from Crossfire (Multiplayer game for X-windows). *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
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 *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
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 *
20  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
21  * *
22  * The author can be reached at admin@atrinik.org *
23  ************************************************************************/
24 
30 #include <global.h>
31 #include <object.h>
32 
46 void place_monsters(mapstruct *map, char *monsterstyle, int difficulty, RMParms *RP)
47 {
48  mapstruct *style_map = NULL;
49  int failed_placements = 0, number_monsters = 0;
50 
51  style_map = find_style("/styles/monsterstyles", monsterstyle, difficulty);
52 
53  if (style_map == NULL) {
54  return;
55  }
56 
57  while (number_monsters < RP->num_monsters && failed_placements < 100) {
58  object *this_monster = pick_random_object(style_map);
59  int x, y, freeindex;
60 
61  if (this_monster == NULL) {
62  return;
63  }
64 
65  x = rndm(0, RP->Xsize - 1);
66  y = rndm(0, RP->Ysize - 1);
67  freeindex = map_free_spot_first(map, x, y, this_monster->arch, NULL);
68 
69  if (freeindex != -1) {
70  object *new_monster = object_clone(this_monster);
71 
72  x += freearr_x[freeindex];
73  y += freearr_y[freeindex];
74  new_monster->x = x;
75  new_monster->y = y;
76  object_insert_map(new_monster, map, new_monster, INS_NO_MERGE | INS_NO_WALK_ON);
77  number_monsters++;
78  } else {
79  failed_placements++;
80  }
81  }
82 }
static size_t num_monsters
Definition: readable.c:59
struct archetype * arch
Definition: object.h:225
object * object_clone(const object *op)
Definition: object.c:2385
int16_t y
Definition: object.h:276
mapstruct * find_style(const char *dirname, const char *stylename, int difficulty)
Definition: style.c:169
#define INS_NO_WALK_ON
Definition: object.h:570
object * pick_random_object(mapstruct *style)
Definition: style.c:286
int16_t x
Definition: object.h:273
int Ysize
Definition: random_map.h:77
object * object_insert_map(object *op, mapstruct *m, object *originator, int flag)
Definition: object.c:1741
int Xsize
Definition: random_map.h:74
#define INS_NO_MERGE
Definition: object.h:564
int freearr_x[SIZEOFFREE]
Definition: object.c:84
int map_free_spot_first(mapstruct *m, int x, int y, archetype_t *at, object *op)
Definition: map.c:3009
Definition: map.h:536
void place_monsters(mapstruct *map, char *monsterstyle, int difficulty, RMParms *RP)
Definition: monster.c:46
int freearr_y[SIZEOFFREE]
Definition: object.c:99