[CF-Devel] patch for generators to create special ability mo

Norbert Irmer norbert.irmer at t-online.de
Thu Apr 18 10:35:07 CDT 2002


Mark Wedel wrote:

>
     
     
     >
     
       Probably because the fog type is not a monster.
     
     >
     
     
     >
     
       IT is unclear to me why you want to put fog in the inventory of a 
     
     >
     
      generator - the only reason somethign needs to be in the inventory are 
     
     >
     
      if you are changing the values.  If you are just using the standard 
     
     >
     
      fog arch, then you should use the other_arch. 
     
     

The reason was, that i noticed that fog is swallowed by deep_swamp. 
After browsing
the swamp code, i saw that swamp swallows everything which is a player or
not alive (like fog). So i just wanted to try out to create fog which 
has the alive flag set to
prevent this (i did not fully understand at that point in time why fog 
has to be a
generator, and that this would not solve the problem).

But anyway, this gave me the idea, that sometimes it might be necessary 
to put
something else (not a monster) into the inventory of a generator
(monsters without maps doesn't seem to be processed anyway, at least i 
had no
problems when i put monsters into the inv of generators).

>>
     
      I would propose to change 'find_free_spot' or even better 
     
     >>
     
      'arch_out_of_map',
     
     >>
     
      which is called by 'find_free_spot', so that false is returned if 
     
     >>
     
      map==NULL.
     
     >
     
     
     >
     
       The change should be higher up - in generator monster in this case.
     
     >
     
     
     >
     
       Changing find_free_spot or arch_out_of_map is not the right place - 
     
     >
     
      that will mask other programming problems in the future.  Certain 
     
     >
     
      programming practices should be caught with errors.  If find_free_spot 
     
     >
     
      is passed a null map, IMO, it should crash - the code calling it 
     
     >
     
      should make sure it is doing the right thing.  One reason I say this 
     
     >
     
      is that in some cases, if find_free_spot returns that there is no 
     
     >
     
      space available, it may be use other fallback code.
     
     

You are probably right. This could hide other programming errors. If it 
is intended that
find_free_spot or arch_out_of_map should never be called with map=0, 
then it is the
wrong way to put such a check into them (interesting idea: if there is 
no map, is there
then no free spot either ? (theory of undefined terms:))

I removed the check "if(m==0) return 1;" from arch_out_of_map in map.c again
(just don't apply the patch "common-map.c.diff" i sent), and added a 
similiar check
to "generate_monster" instead.









-------------- next part --------------
Index: time.c
===================================================================
RCS file: /cvsroot/crossfire/crossfire/server/time.c,v
retrieving revision 1.40
diff -c -5 -r1.40 time.c
*** time.c	2 Jan 2002 06:53:23 -0000	1.40
--- time.c	18 Apr 2002 15:25:51 -0000
***************
*** 83,103 ****
    free_object(op);
  }
  
  void generate_monster(object *gen) {
    int i;
!   object *op,*head=NULL,*prev=NULL;
!   archetype *at=gen->other_arch;
  
    if(GENERATE_SPEED(gen)&&rndm(0, GENERATE_SPEED(gen)-1))
      return;
!   if(gen->other_arch==NULL) {
!     LOG(llevError,"Generator without other_arch: %s\n",gen->name);
      return;
    }
!   i=find_free_spot(at,gen->map,gen->x,gen->y,1,9);
!   if (i==-1) return;
    while(at!=NULL) {
      op=arch_to_object(at);
      op->x=gen->x+freearr_x[i]+at->clone.x;
      op->y=gen->y+freearr_y[i]+at->clone.y;
      if(head!=NULL)
--- 83,130 ----
    free_object(op);
  }
  
  void generate_monster(object *gen) {
    int i;
!   object *op,*head=NULL,*prev=NULL,*gob;
!   archetype *at;
  
    if(GENERATE_SPEED(gen)&&rndm(0, GENERATE_SPEED(gen)-1))
      return;
! 
!   if(gen->map==NULL) /* generators doesn't operate if not in a map */
      return;
+   
+   if(gen->inv!=NULL) {
+     gob=gen->inv; /* the generator inv just contains the head of the monster, */
+                   /* if it is mulipart */ 
+     i=find_free_spot(gob->arch,gen->map,gen->x,gen->y,1,9);
+     if (i==-1) return;
+     op=get_object();
+     copy_object(gob,op);
+     op->x=gen->x+freearr_x[i]+gob->arch->clone.x;
+     op->y=gen->y+freearr_y[i]+gob->arch->clone.y;
+     if (rndm(0, 9)) generate_artifact(op, gen->map->difficulty);
+     insert_ob_in_map(op,gen->map,gen,0);
+     if (QUERY_FLAG(op, FLAG_FREED)) return;
+     if(op->randomitems!=NULL)
+       create_treasure(op->randomitems,op,GT_APPLY,
+                       gen->map->difficulty,0);
+     head=op; 
+     prev=op;
+     at=gob->arch->more;
+   }
+   else {
+     if(gen->other_arch==NULL) {
+       LOG(llevError,"Generator without other_arch or inv: %s\n",gen->name);
+       return;
+     }
+     at=gen->other_arch;
+     i=find_free_spot(at,gen->map,gen->x,gen->y,1,9);
+     if (i==-1) return;
    }
! 
    while(at!=NULL) {
      op=arch_to_object(at);
      op->x=gen->x+freearr_x[i]+at->clone.x;
      op->y=gen->y+freearr_y[i]+at->clone.y;
      if(head!=NULL)
    
    


More information about the crossfire mailing list