ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/time.C
(Generate patch)

Comparing deliantra/server/server/time.C (file contents):
Revision 1.35 by root, Tue Jan 9 01:28:32 2007 UTC vs.
Revision 1.45 by root, Sun Apr 22 13:06:45 2007 UTC

87 } 87 }
88 88
89 op->destroy (); 89 op->destroy ();
90} 90}
91 91
92/* Will generate a monster according to content
93 * of generator.
94 */
95void 92void
96generate_monster_inv (object *gen) 93generate_monster (object *gen)
97{ 94{
98 int i;
99 object *op, *head = NULL;
100
101 int qty = 0;
102
103 /* Code below assumes the generator is on a map, as it tries
104 * to place the monster on the map. So if the generator
105 * isn't on a map, complain and exit.
106 */
107 if (gen->map == NULL)
108 {
109 //LOG(llevError,"Generator (%s) not on a map?\n", gen->name);
110 return;
111 }
112 /*First count numer of objects in inv */
113 for (op = gen->inv; op; op = op->below)
114 qty++;
115 if (!qty)
116 {
117 LOG (llevError, "Generator (%s) has no inventory in generate_monster_inv?\n", &gen->name);
118 return; /*No inventory */
119 }
120 qty = rndm (0, qty - 1);
121 for (op = gen->inv; qty; qty--)
122 op = op->below;
123 i = find_free_spot (op, gen->map, gen->x, gen->y, 1, 9);
124 if (i == -1)
125 return;
126 head = object_create_clone (op);
127 CLEAR_FLAG (head, FLAG_IS_A_TEMPLATE);
128 unflag_inv (head, FLAG_IS_A_TEMPLATE);
129 if (rndm (0, 9))
130 generate_artifact (head, gen->map->difficulty);
131 insert_ob_in_map_at (head, gen->map, gen, 0, gen->x + freearr_x[i], gen->y + freearr_y[i]);
132 if (QUERY_FLAG (head, FLAG_FREED))
133 return;
134 if (head->has_random_items ())
135 create_treasure (head->randomitems, head, GT_APPLY, gen->map->difficulty, 0);
136}
137
138void
139generate_monster_arch (object *gen)
140{
141 int i;
142 object *op, *head = NULL, *prev = NULL;
143 archetype *at = gen->other_arch;
144
145 if (!gen->other_arch)
146 return;
147
148 /* Code below assumes the generator is on a map, as it tries
149 * to place the monster on the map. So if the generator
150 * isn't on a map, complain and exit.
151 */
152 if (!gen->map) 95 if (!gen->map)
153 return; 96 return;
154 97
155 i = find_free_spot (&at->clone, gen->map, gen->x, gen->y, 1, 9);
156 if (i == -1)
157 return;
158
159 while (at)
160 {
161 op = arch_to_object (at);
162 op->x = gen->x + freearr_x[i] + at->clone.x;
163 op->y = gen->y + freearr_y[i] + at->clone.y;
164
165 if (head)
166 op->head = head, prev->more = op;
167
168 if (rndm (0, 9))
169 generate_artifact (op, gen->map->difficulty);
170
171 insert_ob_in_map (op, gen->map, gen, 0);
172 if (QUERY_FLAG (op, FLAG_FREED))
173 return;
174
175 if (op->has_random_items ())
176 create_treasure (op->randomitems, op, GT_APPLY, gen->map->difficulty, 0);
177
178 if (head == NULL)
179 head = op;
180
181 prev = op;
182 at = at->more;
183 }
184}
185
186void
187generate_monster (object *gen)
188{
189
190 if (GENERATE_SPEED (gen) && rndm (0, GENERATE_SPEED (gen) - 1)) 98 if (GENERATE_SPEED (gen) && rndm (0, GENERATE_SPEED (gen) - 1))
191 return; 99 return;
192 100
101 object *op;
102
193 if (QUERY_FLAG (gen, FLAG_CONTENT_ON_GEN)) 103 if (QUERY_FLAG (gen, FLAG_CONTENT_ON_GEN))
194 generate_monster_inv (gen); 104 {
105 // either copy one item form the inventory...
106 if (!gen->inv)
107 return;
108
109 // first select one item from the inventory
110 int index = 0;
111 for (object *tmp = gen->inv; tmp; tmp = tmp->below)
112 if (!rndm (++index))
113 op = tmp;
114
115 op = object_create_clone (op);
116
117 CLEAR_FLAG (op, FLAG_IS_A_TEMPLATE);
118 unflag_inv (op, FLAG_IS_A_TEMPLATE);
119 }
195 else 120 else
196 generate_monster_arch (gen); 121 {
122 // ...or use other_arch
123 if (archetype *at = gen->other_arch)
124 op = arch_to_object (at);
125 else
126 return;
127 }
197 128
129 op->expand_tail ();
130
131 int i = find_free_spot (op, gen->map, gen->x, gen->y, 1, 9);
132 if (i >= 0)
133 {
134 if (insert_ob_in_map_at (op, gen->map, gen, 0, gen->x + freearr_x[i], gen->y + freearr_y[i]))
135 {
136 if (rndm (0, 9))
137 generate_artifact (op, gen->map->difficulty);
138
139 if (op->has_random_items ())
140 create_treasure (op->randomitems, op, GT_APPLY, gen->map->difficulty);
141
142 return;
143 }
144 }
145
146 op->destroy ();
198} 147}
199 148
200void 149void
201remove_force (object *op) 150remove_force (object *op)
202{ 151{
245 return; 194 return;
246 } 195 }
247 196
248 if (op->stats.food == 1) 197 if (op->stats.food == 1)
249 { 198 {
250 /* need to remove the object before fix_player is called, else fix_player 199 /* need to unapply the object before update_stats is called, else fix_player
251 * will not do anything. 200 * will not do anything.
252 */ 201 */
253 if (op->env->type == PLAYER) 202 if (op->env->type == PLAYER)
254 { 203 {
255 CLEAR_FLAG (op, FLAG_APPLIED); 204 CLEAR_FLAG (op, FLAG_APPLIED);
455 404
456 if (op->stats.hp) 405 if (op->stats.hp)
457 { 406 {
458 for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below) 407 for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below)
459 { 408 {
460 if (op->slaying && !strcmp (op->slaying, tmp->name)) 409 if (op->slaying && op->slaying == tmp->name)
461 detected = 1; 410 detected = 1;
411
462 if (tmp2->type == FORCE && tmp2->slaying && !strcmp (tmp2->slaying, op->slaying)) 412 if (tmp2->type == FORCE && tmp2->slaying && tmp2->slaying == op->slaying)
463 detected = 1; 413 detected = 1;
464 } 414 }
465 } 415 }
416
466 if (op->slaying && !strcmp (op->slaying, tmp->name)) 417 if (op->slaying && op->slaying == tmp->name)
467 {
468 detected = 1; 418 detected = 1;
469 }
470 else if (tmp->type == SPECIAL_KEY && tmp->slaying == op->slaying) 419 else if (tmp->type == SPECIAL_KEY && tmp->slaying == op->slaying)
471 detected = 1; 420 detected = 1;
472 } 421 }
473 422
474 /* the detector sets the button if detection is found */ 423 /* the detector sets the button if detection is found */
604void 553void
605fix_stopped_item (object *op, maptile *map, object *originator) 554fix_stopped_item (object *op, maptile *map, object *originator)
606{ 555{
607 if (map == NULL) 556 if (map == NULL)
608 return; 557 return;
558
609 if (QUERY_FLAG (op, FLAG_REMOVED)) 559 if (QUERY_FLAG (op, FLAG_REMOVED))
610 insert_ob_in_map (op, map, originator, 0); 560 insert_ob_in_map (op, map, originator, 0);
611 else if (op->type == ARROW) 561 else if (op->type == ARROW)
612 merge_ob (op, NULL); /* only some arrows actually need this */ 562 merge_ob (op, NULL); /* only some arrows actually need this */
613} 563}
614
615 564
616object * 565object *
617fix_stopped_arrow (object *op) 566fix_stopped_arrow (object *op)
618{ 567{
619 if (rndm (0, 99) < op->stats.food) 568 if (rndm (0, 99) < op->stats.food)
648 op->stats.hp = 0; 597 op->stats.hp = 0;
649 op->stats.grace = 0; 598 op->stats.grace = 0;
650 op->level = 0; 599 op->level = 0;
651 op->face = op->arch->clone.face; 600 op->face = op->arch->clone.face;
652 op->owner = NULL; /* So that stopped arrows will be saved */ 601 op->owner = NULL; /* So that stopped arrows will be saved */
653 update_object (op, UP_OBJ_FACE); 602 update_object (op, UP_OBJ_CHANGE);
654 return op; 603 return op;
655} 604}
656 605
657/* stop_arrow() - what to do when a non-living flying object 606/* stop_arrow() - what to do when a non-living flying object
658 * has to stop. Sept 96 - I added in thrown object code in 607 * has to stop. Sept 96 - I added in thrown object code in
684 } 633 }
685} 634}
686 635
687/* Move an arrow along its course. op is the arrow or thrown object. 636/* Move an arrow along its course. op is the arrow or thrown object.
688 */ 637 */
689
690void 638void
691move_arrow (object *op) 639move_arrow (object *op)
692{ 640{
693 object *tmp; 641 object *tmp;
694 sint16 new_x, new_y; 642 sint16 new_x, new_y;
765 * as below. (Note that for living creatures there is a small 713 * as below. (Note that for living creatures there is a small
766 * chance that reflect_missile fails.) 714 * chance that reflect_missile fails.)
767 */ 715 */
768 if (QUERY_FLAG (tmp, FLAG_REFL_MISSILE) && (rndm (0, 99)) < (90 - op->level / 10)) 716 if (QUERY_FLAG (tmp, FLAG_REFL_MISSILE) && (rndm (0, 99)) < (90 - op->level / 10))
769 { 717 {
770 int number = op->face->number; 718 int number = op->face;
771 719
772 op->direction = absdir (op->direction + 4); 720 op->direction = absdir (op->direction + 4);
773 op->state = 0; 721 update_turn_face (op);
774
775 if (GET_ANIM_ID (op))
776 {
777 number += 4;
778
779 if (number > GET_ANIMATION (op, 8))
780 number -= 8;
781
782 op->face = &new_faces[number];
783 }
784
785 was_reflected = 1; /* skip normal movement calculations */ 722 was_reflected = 1; /* skip normal movement calculations */
786 } 723 }
787 else 724 else
788 { 725 {
789 /* Attack the object. */ 726 /* Attack the object. */
1204 return; 1141 return;
1205 } 1142 }
1206 1143
1207 if (op->above == NULL) 1144 if (op->above == NULL)
1208 return; 1145 return;
1146
1209 for (tmp = op->above; tmp != NULL; tmp = tmp->above) 1147 for (tmp = op->above; tmp; tmp = tmp->above)
1210 { 1148 {
1211 if (strcmp (op->other_arch->name, tmp->arch->name) == 0) 1149 if (op->other_arch->name == tmp->arch->name)
1212 { 1150 {
1213 if (op->level <= 0) 1151 if (op->level <= 0)
1214 tmp->destroy (); 1152 tmp->destroy ();
1215 else 1153 else
1216 { 1154 {
1307 with a specific code as the slaying field. 1245 with a specific code as the slaying field.
1308 At that time, it writes the contents of its own message 1246 At that time, it writes the contents of its own message
1309 field to the player. The marker will decrement hp to 1247 field to the player. The marker will decrement hp to
1310 0 and then delete itself every time it grants a mark. 1248 0 and then delete itself every time it grants a mark.
1311 unless hp was zero to start with, in which case it is infinite.*/ 1249 unless hp was zero to start with, in which case it is infinite.*/
1312
1313void 1250void
1314move_marker (object *op) 1251move_marker (object *op)
1315{ 1252{
1316 if (object *tmp = op->ms ().player ()) 1253 if (object *tmp = op->ms ().player ())
1317 { 1254 {
1318 object *tmp2; 1255 object *tmp2;
1319 1256
1320 /* remove an old force with a slaying field == op->name */ 1257 /* remove an old force with a slaying field == op->name */
1321 for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below) 1258 for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below)
1322 if (tmp2->type == FORCE && tmp2->slaying && !strcmp (tmp2->slaying, op->name)) 1259 if (tmp2->type == FORCE && tmp2->slaying && tmp2->slaying == op->name)
1323 { 1260 {
1324 tmp2->destroy (); 1261 tmp2->destroy ();
1325 break; 1262 break;
1326 } 1263 }
1327 1264
1328 /* cycle through his inventory to look for the MARK we want to 1265 /* cycle through his inventory to look for the MARK we want to
1329 * place 1266 * place
1330 */ 1267 */
1331 for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below) 1268 for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below)
1332 if (tmp2->type == FORCE && tmp2->slaying && !strcmp (tmp2->slaying, op->slaying)) 1269 if (tmp2->type == FORCE && tmp2->slaying && tmp2->slaying == op->slaying)
1333 break; 1270 break;
1334 1271
1335 /* if we didn't find our own MARK */ 1272 /* if we didn't find our own MARK */
1336 if (tmp2 == NULL) 1273 if (!tmp2)
1337 { 1274 {
1338 object *force = get_archetype (FORCE_NAME); 1275 object *force = get_archetype (FORCE_NAME);
1339 1276
1340 if (op->stats.food) 1277 if (op->stats.food)
1341 { 1278 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines