Date sent: Wed, 16 Jul 1997 18:43:31 -0200 To: "Liner/Nosferatu" From: Rick Rogers (by way of Rick Rogers ) Subject: RCL 6: Spec Examples - more rooms and the switch statement I've had a couple of requests for more room specs. Well here is another one. This one does minor damage to all chars in the room every tick and will also cast frostbreath on the character from a CMD_KILL. #define DEATH_ROOM 3999 int room_of_death(int room, CHAR *ch, int cmd, char *arg) { CHAR *vict=0,*next_vict; if(world[room].number!= DEATH_ROOM) return FALSE; /* A redundant check to be safe */ if(CMD==MSG_TICK) { for(vict = world[room].people; vict;vict = next_vict) { next_vict = vict->next_in_room; if(IS_MORTAL(vict) { act("A streak of fire shoots out of the ceiling!",0,vict,0,0,TO_CHAR); damage(vict,vict,50,TYPE_UNDEFINED); /* Here there is no mob, so we just use the vict to damage himself */ } } return FALSE; /* Alway return false from TICK */ } if(!ch) return FALSE; if(GET_LEVEL(ch)>=LEVEL_IMM || IS_NPC(ch)) return FALSE; /* The rest of the spec wants a mortal PC to send the cmd */ if (cmd != CMD_KILL) return FALSE; /* Also the only command left in the spec is KILL */ act("As you lift your hand to strike, a freezing wind hits you.",0,ch,0,0,TO_CHAR); act("As $n lifts $s hand to strike, a freezing wind hits $m.",0,ch,0,0,TO_ROOM); /* Standard messages */ damage(ch,ch,100,TYPE_UNDEFINED); return TRUE; } ----------------- Up to this point I have been using if statements for the specs. This is fine with only one or two commands to consider. However, a neater way is to use the switch statement. The following is exactly the same as above. int room_of_death(int room, CHAR *ch, int cmd, char *arg) { CHAR *vict=0,*next_vict; if(world[room].number!= DEATH_ROOM) return FALSE; switch (cmd) { case MSG_TICK: for(vict = world[room].people; vict;vict = next_vict) { next_vict = vict->next_in_room; if(IS_MORTAL(vict) { act("A streak of fire shoots out of the ceiling!",0,vict,0,0,TO_CHAR); damage(vict,vict,50,TYPE_UNDEFINED); } } return FALSE; break; case CMD_KILL: if(!ch) return FALSE; if(GET_LEVEL(ch)>=LEVEL_IMM || IS_NPC(ch)) return FALSE; act("As you lift your hand to strike, a freezing wind hits you.",0,ch,0,0,TO_CHAR); act("As $n lifts $s hand to strike, a freezing wind hits $m.",0,ch,0,0,TO_ROOM); damage(ch,ch,100,TYPE_UNDEFINED); return TRUE; break; default: } return FALSE; } ----------- By the way, I'm running out of ideas - if you have any requests, let me know. Rick (Ranger)