|
Atrinik Server 2.5
|
00001 /************************************************************************ 00002 * Atrinik, a Multiplayer Online Role Playing Game * 00003 * * 00004 * Copyright (C) 2009-2011 Alex Tokar and Atrinik Development Team * 00005 * * 00006 * Fork from Daimonin (Massive Multiplayer Online Role Playing Game) * 00007 * and Crossfire (Multiplayer game for X-windows). * 00008 * * 00009 * This program is free software; you can redistribute it and/or modify * 00010 * it under the terms of the GNU General Public License as published by * 00011 * the Free Software Foundation; either version 2 of the License, or * 00012 * (at your option) any later version. * 00013 * * 00014 * This program is distributed in the hope that it will be useful, * 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00017 * GNU General Public License for more details. * 00018 * * 00019 * You should have received a copy of the GNU General Public License * 00020 * along with this program; if not, write to the Free Software * 00021 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * 00022 * * 00023 * The author can be reached at admin@atrinik.org * 00024 ************************************************************************/ 00025 00030 #include <global.h> 00031 00039 void insert_multisquare_ob_in_map(object *new_obj, mapstruct *map) 00040 { 00041 int x, y; 00042 archetype *at; 00043 object *old_seg; 00044 object *head; 00045 00046 /* first insert the head */ 00047 insert_ob_in_map(new_obj, map, new_obj, INS_NO_MERGE | INS_NO_WALK_ON); 00048 00049 x = new_obj->x; 00050 y = new_obj->y; 00051 old_seg = new_obj; 00052 head = new_obj; 00053 00054 for (at = new_obj->arch->more; at != NULL; at = at->more) 00055 { 00056 object *new_seg = arch_to_object(at); 00057 00058 new_seg->x = x + at->clone.x; 00059 new_seg->y = y + at->clone.y; 00060 new_seg->map = old_seg->map; 00061 00062 insert_ob_in_map(new_seg, new_seg->map, new_seg, INS_NO_MERGE | INS_NO_WALK_ON); 00063 00064 new_seg->head = head; 00065 old_seg->more = new_seg; 00066 old_seg = new_seg; 00067 } 00068 00069 old_seg->more = NULL; 00070 } 00071 00080 void place_monsters(mapstruct *map, char *monsterstyle, int difficulty, RMParms *RP) 00081 { 00082 mapstruct *style_map = NULL; 00083 int failed_placements = 0, number_monsters = 0; 00084 00085 style_map = find_style("/styles/monsterstyles", monsterstyle, difficulty); 00086 00087 if (style_map == NULL) 00088 { 00089 return; 00090 } 00091 00092 while (number_monsters < RP->num_monsters && failed_placements < 100) 00093 { 00094 object *this_monster = pick_random_object(style_map); 00095 int x, y, freeindex; 00096 00097 if (this_monster == NULL) 00098 { 00099 return; 00100 } 00101 00102 x = RANDOM() % RP->Xsize; 00103 y = RANDOM() % RP->Ysize; 00104 freeindex = find_first_free_spot(this_monster->arch, NULL, map, x, y); 00105 00106 if (freeindex != -1) 00107 { 00108 object *new_monster = object_create_clone(this_monster); 00109 00110 x += freearr_x[freeindex]; 00111 y += freearr_y[freeindex]; 00112 new_monster->x = x; 00113 new_monster->y = y; 00114 insert_multisquare_ob_in_map(new_monster, map); 00115 number_monsters++; 00116 } 00117 else 00118 { 00119 failed_placements++; 00120 } 00121 } 00122 }
1.7.4