Exemple #1
0
void handleCommand(string command)
{
	hC_begin

	CMD("look")
		cout << "You see:" << endl;
		for (unsigned i = 0; i < stuff.size(); i++)
			cout << " * " << stuff[i] << endl;
	CMD("open")
		if (args[1] == "door")
			if (has_item("key"))
			{
				cout << "The door opened!" << endl;
				ACHIEVE(DOOR_OPEN);
				goNextLevel();
			}
			else
				cout << "The door is locked!" << endl;
	CMD("take")
		if (args[1] == "comment")
		{
			if (has_achievement(EA_CAPTCHA)) {
				FIND("comment");
			} else
				cout << "You can't! It's not your's!" << endl;
		}
		if (args[1] == "captcha")
			FIND("captcha");
	CMD("say")
		if (args[1] == "captcha")
			if (has_item("captcha"))
			{
				cout << "Man, that captcha was lamer than i thought!" << endl;
				ACHIEVE(CAPTCHA);
			}
			else
				cout << "What does that captcha say? I don't know!" << endl;
	CMD("post")
		if (args[1] == "comment")
			if (has_item("comment"))
			{
				FIND("key");
				ACHIEVE(COMMENT);
			}
			else
				cout << "You can't! It's not your's!" << endl;
	CMD("help")
		cout << "The following commands are availeble:" << endl << " * look\n * open\n * take\n * say\n * post\n";

	hC_end
}
Exemple #2
0
static void print_tags(blkid_dev dev, char *show[], int output)
{
	blkid_tag_iterate	iter;
	const char		*type, *value, *devname;
	int			num = 1;

	if (!dev)
		return;

	if (output & OUTPUT_PRETTY_LIST) {
		pretty_print_dev(dev);
		return;
	}

	devname = blkid_dev_devname(dev);

	if (output & OUTPUT_DEVICE_ONLY) {
		printf("%s\n", devname);
		return;
	}

	iter = blkid_tag_iterate_begin(dev);
	while (blkid_tag_next(iter, &type, &value) == 0) {
		if (show[0] && !has_item(show, type))
			continue;
		print_value(output, num++, devname, value, type, strlen(value));
	}
	blkid_tag_iterate_end(iter);

	if (num > 1 && !(output & (OUTPUT_VALUE_ONLY | OUTPUT_UDEV_LIST)))
		printf("\n");
}
void minegateway(int in,int cn)
{
	int x,y,a;

        if (!cn) return;	// always make sure its not an automatic call if you don't handle it
	if (!(ch[cn].flags&CF_PLAYER)) return;

	if (!has_item(cn,IID_MINEGATEWAY)) {
		log_char(cn,LOG_SYSTEM,0,"The door won't open. You notice an inscription: \"This door leads to the Dwarven town Grimroot. Only those who have proven their abilities as miners and fighters may enter.");
		return;
	}

	x=*(unsigned short*)(it[in].drdata+0);
	y=*(unsigned short*)(it[in].drdata+2);
	a=*(unsigned short*)(it[in].drdata+4);

	if (x<1 || x>MAXMAP-2 || y<1 || y>MAXMAP-2 || !a) {
		log_area(ch[cn].x,ch[cn].y,LOG_INFO,cn,10,"%s touches a teleport object but nothing happens - BUG (%d,%d,%d).",ch[cn].name,x,y,a);
		return;
	}

        if (!change_area(cn,a,x,y)) {
		log_area(ch[cn].x,ch[cn].y,LOG_INFO,cn,10,"%s touches a teleport object but nothing happens - target area server is down.",ch[cn].name);
	}
}
bool item_group::group_contains_item( const Group_tag &group_id, const itype_id &type_id )
{
    const auto group = item_controller->get_group( group_id );
    if( group == nullptr ) {
        return false;
    }
    return group->has_item( type_id );
}
Exemple #5
0
void INI::merge_map(SectionMap & data2, const chowstring & src_group,
                    const chowstring & dst_group, bool overwrite)
{
    OptionMap & items = data2[src_group];
    OptionMap::const_iterator it;
    for (it = items.begin(); it != items.end(); ++it) {
        if (!overwrite && has_item(dst_group, (*it).first))
            continue;
        (*data)[dst_group][(*it).first] = (*it).second;
    }
    save_auto();
}
Exemple #6
0
/*
 *  Thu Oct  8 18:30:46 1998 -- Scott Turner
 *
 *  Calculate someone's effective workforce, including artifacts.
 *
 */
int
effective_workers(int who)
{
  int w = has_item(who, item_worker);
  int a = best_artifact(who, ART_WORKERS, 0, 0);

  if (a) {
    w = (w * (100 + rp_item_artifact(a)->param1)) / 100;
  };

  return w;

};
Exemple #7
0
void INI::parse_handler(const chowstring & section, const chowstring & name,
                        const chowstring & value)
{
    if (!overwrite && has_item(section, name))
        return;
#ifdef CHOWDREN_INI_FILTER_QUOTES
    if (value[0] == '"' && *value.rbegin() == '"') {
        (*data)[section][name] = value.substr(1, value.size() - 2);
        return;
    }
#endif
    (*data)[section][name] = value;
}
Exemple #8
0
void INI::merge_map(const SectionMap & data2, bool overwrite)
{
    SectionMap::const_iterator it1;
    OptionMap::const_iterator it2;
    for (it1 = data2.begin(); it1 != data2.end(); ++it1) {
        for (it2 = (*it1).second.begin(); it2 != (*it1).second.end();
             ++it2) {
            if (!overwrite && has_item((*it1).first, (*it2).first))
                continue;
            (*data)[(*it1).first][(*it2).first] = (*it2).second;
        }
    }
    save_auto();
}
Exemple #9
0
char *
loc_civ_s(int where)
{
  int n;

  if (loc_depth(where) != LOC_province ||
      subkind(where) == sub_ocean || in_faery(where) || in_hades(where)) {
    return "";
  }

  n = has_item(where, item_peasant);

  if (n < 100)
    return ", wilderness";

  return sout(", peasants: %d", n);
}
Exemple #10
0
/*
 *  Tue Jul  7 09:59:59 1998 -- Scott Turner
 *
 *  Replenish up to "qty" but not more than max total.
 *
 *  Tue Jul  7 10:31:23 1998 -- Scott Turner
 *
 *  For "population" type production, driving the population to zero
 *  is a bad idea.  max != qty in the terr_prod table indicates a
 *  population type resource.
 *
 */
static void
replenish(int where, int item, int qty, int max)
{
  int n;

  n = has_item(where, item);
  if (n == 0 && max != qty) {
    if (rnd(1, 100) > 50)
      gen_item(where, item, 1);
  }
  else if (n < max) {
    int m = max - n;
    if (m > qty)
      m = qty;
    gen_item(where, item, m);
  };
}
Exemple #11
0
int warpkeydoor_driver(int in,int cn)
{
    int in2,dx,dy;

    if (!cn) return 1;

    dx=it[in].x-ch[cn].x;
    dy=it[in].y-ch[cn].y;
    if (!dx && !dy) {
        log_char(cn,LOG_SYSTEM,0,"Bug #329i, sorry.");
        return 2;
    }

    in2=has_item(cn,IID_AREA25_DOORKEY);

    if (!in2) {
        log_char(cn,LOG_SYSTEM,0,"The door is locked and you do not have the right key.");
        return 2;
    }

    if (teleport_char_driver(cn,it[in].x+dx,it[in].y+dy)) {
        log_char(cn,LOG_SYSTEM,0,"A %s vanished.",it[in2].name);
        remove_item_char(in2);
        destroy_item(in2);
        switch(ch[cn].dir) {
        case DX_RIGHT:
            ch[cn].dir=DX_LEFT;
            break;
        case DX_LEFT:
            ch[cn].dir=DX_RIGHT;
            break;
        case DX_UP:
            ch[cn].dir=DX_DOWN;
            break;
        case DX_DOWN:
            ch[cn].dir=DX_UP;
            break;
        }
        return 1;
    } else {
        log_char(cn,LOG_SYSTEM,0,"Oops. Please try again.");
        return 2;
    }
}
Exemple #12
0
static void print_tags(blkid_dev dev, char *show[], int output)
{
	blkid_tag_iterate	iter;
	const char		*type, *value, *devname;
	int			num = 1;
	static int		first = 1;

	if (!dev)
		return;

	if (output & OUTPUT_PRETTY_LIST) {
		pretty_print_dev(dev);
		return;
	}

	devname = blkid_dev_devname(dev);

	if (output & OUTPUT_DEVICE_ONLY) {
		printf("%s\n", devname);
		return;
	}

	iter = blkid_tag_iterate_begin(dev);
	while (blkid_tag_next(iter, &type, &value) == 0) {
		if (show[0] && !has_item(show, type))
			continue;

		if (num == 1 && !first &&
		    (output & (OUTPUT_UDEV_LIST | OUTPUT_EXPORT_LIST)))
			/* add extra line between output from more devices */
			fputc('\n', stdout);

		print_value(output, num++, devname, value, type, strlen(value));
	}
	blkid_tag_iterate_end(iter);

	if (num > 1) {
		if (!(output & (OUTPUT_VALUE_ONLY | OUTPUT_UDEV_LIST |
						OUTPUT_EXPORT_LIST)))
			printf("\n");
		first = 0;
	}
}
Exemple #13
0
int
v_eat_dead(struct command *c)
{
  int body = c->a;

  /*
   *  Sun Jun  1 10:31:40 1997 -- Scott Turner
   *
   *  Might have a lost soul as a prisoner...
   *
   */
  if (!valid_box(body)) {
    wout(c->who, "Don't have %s.", box_code(body));
    return FALSE;
  }

  if (kind(body) == T_item) {
    if (subkind(body) != sub_dead_body) {
      wout(c->who, "%s is not a dead body.", box_code(body));
      return FALSE;
    };
    if (!has_item(c->who, body)) {
      wout(c->who, "You do not possess that body.");
      return FALSE;
    };
  }
  else if (kind(body) == T_char) {
    if (subkind(body) != sub_lost_soul) {
      wout(c->who, "%s is not a lost soul.", box_code(body));
      return FALSE;
    };
    if (!has_prisoner(c->who, body)) {
      wout(c->who, "You have not captured that lost soul.");
      return FALSE;
    };
  };

  return TRUE;
}
Exemple #14
0
static int lowprobe_device(blkid_probe pr, const char *devname,
			int chain, char *show[], int output,
			blkid_loff_t offset, blkid_loff_t size)
{
	const char *data;
	const char *name;
	int nvals = 0, n, num = 1;
	size_t len;
	int fd;
	int rc = 0;
	static int first = 1;

	fd = open(devname, O_RDONLY);
	if (fd < 0) {
		fprintf(stderr, "error: %s: %s\n", devname, strerror(errno));
		return 2;
	}
	if (blkid_probe_set_device(pr, fd, offset, size))
		goto done;

	if (chain & LOWPROBE_TOPOLOGY)
		rc = lowprobe_topology(pr);
	if (rc >= 0 && (chain & LOWPROBE_SUPERBLOCKS))
		rc = lowprobe_superblocks(pr);
	if (rc < 0)
		goto done;

	nvals = blkid_probe_numof_values(pr);

	if (nvals && !first && output & (OUTPUT_UDEV_LIST | OUTPUT_EXPORT_LIST))
		/* add extra line between output from devices */
		fputc('\n', stdout);

	if (output & OUTPUT_DEVICE_ONLY) {
		printf("%s\n", devname);
		goto done;
	}

	for (n = 0; n < nvals; n++) {
		if (blkid_probe_get_value(pr, n, &name, &data, &len))
			continue;
		if (show[0] && !has_item(show, name))
			continue;
		len = strnlen((char *) data, len);
		print_value(output, num++, devname, (char *) data, name, len);
	}

	if (first)
		first = 0;
	if (nvals >= 1 && !(output & (OUTPUT_VALUE_ONLY |
					OUTPUT_UDEV_LIST | OUTPUT_EXPORT_LIST)))
		printf("\n");
done:
	if (rc == -2) {
		if (output & OUTPUT_UDEV_LIST)
			print_udev_ambivalent(pr);
		else
			fprintf(stderr,
				"%s: ambivalent result (probably more "
				"filesystems on the device, use wipefs(8) "
				"to see more details)\n",
				devname);
	}
	close(fd);
	return !nvals ? 2 : 0;
}
Exemple #15
0
static int lowprobe_device(blkid_probe pr, const char *devname,
			int chain, char *show[], int output,
			blkid_loff_t offset, blkid_loff_t size)
{
	const char *data;
	const char *name;
	int nvals = 0, n, num = 1;
	size_t len;
	int fd;
	int rc = 0;
	static int first = 1;

	fd = open(devname, O_RDONLY);
	if (fd < 0) {
		fprintf(stderr, "error: %s: %m\n", devname);
		return 2;
	}
	if (blkid_probe_set_device(pr, fd, offset, size))
		goto done;

	if (chain & LOWPROBE_TOPOLOGY)
		rc = lowprobe_topology(pr);
	if (rc >= 0 && (chain & LOWPROBE_SUPERBLOCKS))
		rc = lowprobe_superblocks(pr);
	if (rc < 0)
		goto done;

	if (!rc)
		nvals = blkid_probe_numof_values(pr);

	if (nvals &&
	    !(chain & LOWPROBE_TOPOLOGY) &&
	    !(output & OUTPUT_UDEV_LIST) &&
	    !blkid_probe_has_value(pr, "TYPE") &&
	    !blkid_probe_has_value(pr, "PTTYPE"))
		/*
		 * Ignore probing result if there is not any filesystem or
		 * partition table on the device and udev output is not
		 * requested.
		 *
		 * The udev db stores information about partitions, so
		 * PART_ENTRY_* values are alway important.
		 */
		nvals = 0;

	if (nvals && !first && output & (OUTPUT_UDEV_LIST | OUTPUT_EXPORT_LIST))
		/* add extra line between output from devices */
		fputc('\n', stdout);

	if (nvals && (output & OUTPUT_DEVICE_ONLY)) {
		printf("%s\n", devname);
		goto done;
	}

	for (n = 0; n < nvals; n++) {
		if (blkid_probe_get_value(pr, n, &name, &data, &len))
			continue;
		if (show[0] && !has_item(show, name))
			continue;
		len = strnlen((char *) data, len);
		print_value(output, num++, devname, (char *) data, name, len);
	}

	if (first)
		first = 0;
	if (nvals >= 1 && !(output & (OUTPUT_VALUE_ONLY |
					OUTPUT_UDEV_LIST | OUTPUT_EXPORT_LIST)))
		printf("\n");
done:
	if (rc == -2) {
		if (output & OUTPUT_UDEV_LIST)
			print_udev_ambivalent(pr);
		else
			fprintf(stderr,
				"%s: ambivalent result (probably more "
				"filesystems on the device, use wipefs(8) "
				"to see more details)\n",
				devname);
	}
	close(fd);

	if (rc == -2)
		return 8;	/* ambivalent probing result */
	if (!nvals)
		return 2;	/* nothing detected */

	return 0;		/* sucess */
}
Exemple #16
0
static char *
liner_desc_char(int n)
{
  char buf[LEN];
  extern int show_combat_flag;
  char *s;
  int sk;

  strcpy(buf, box_name(n));

  sk = subkind(n);

  if (sk == sub_ni) {
    int mk = noble_item(n);
    int num = has_item(n, mk) + 1;

    if (num == 1)
      strcat(buf, sout(", %s", plural_item_name(mk, num)));
    else
      strcat(buf, sout(", %s, number:~%s",
                       plural_item_name(mk, num), comma_num(num)));
  }
  else if (sk) {
    if (sk == sub_temple) {
      if (is_temple(n)) {
        strcat(buf, sout(", Temple of %s", god_name(is_temple(n))));
      }
      else {
        strcat(buf, sout(", undedicated temple"));
      };
    }
    else if (sk == sub_guild) {
      strcat(buf, sout(", %s Guild", box_name(is_guild(n))));
    }
    else {
      strcat(buf, sout(", %s", subkind_s[sk]));
    };
  }

  strcat(buf, nation_s(n));
  strcat(buf, deserted_s(n));
  strcat(buf, rank_s(n));
  strcat(buf, mage_s(n));
  strcat(buf, priest_s(n));
#if 0
  strcat(buf, wield_s(n));
#endif

  if (show_combat_flag) {
    if (char_behind(n))
      strcat(buf, sout(", behind~%d%s", char_behind(n), combat_ally));
    else
      strcat(buf, combat_ally);
  }
  else if (char_guard(n) && stack_leader(n) == n &&
           subkind(n) != sub_garrison)
    strcat(buf, ", on guard");

#if 0
  if (subkind(n) == 0) {        /* only show lord for regular players */
    int sp = lord(n);

    if (sp != indep_player && !cloak_lord(n))
      strcat(buf, sout(", of~%s", box_code_less(sp)));
  }
#endif

  if (show_display_string) {
    s = banner(n);

    if (s && *s)
      strcat(buf, sout(", \"%s\"", s));
  }

  strcat(buf, with_inventory_string(n));

  if (is_prisoner(n))
    strcat(buf, ", prisoner");

  return sout("%s", buf);
}
Exemple #17
0
bool INI::has_item(const chowstring & option)
{
    return has_item(current_group, option);
}
Exemple #18
0
void dwarfchief_driver(int cn,int ret,int lastact)
{
	struct dwarfchief_data *dat;
	struct staffer_ppd *ppd;
        int co,in,didsay=0,talkdir=0;
	struct msg *msg,*next;

        dat=set_data(cn,DRD_DWARFCHIEFDRIVER,sizeof(struct dwarfchief_data));
	if (!dat) return;	// oops...

        // loop through our messages
	for (msg=ch[cn].msg; msg; msg=next) {
		next=msg->next;

                // did we see someone?
		if (msg->type==NT_CHAR) {
			
                        co=msg->dat1;

			// dont talk to other NPCs
			if (!(ch[co].flags&CF_PLAYER)) { remove_message(cn,msg); continue; }

			// dont talk to players without connection
			if (ch[co].driver==CDR_LOSTCON) { remove_message(cn,msg); continue; }
			
			// only talk every ten seconds
			if (ticker<dat->last_talk+TICKS*4) { remove_message(cn,msg); continue; }

			if (ticker<dat->last_talk+TICKS*10 && dat->current_victim!=co) { remove_message(cn,msg); continue; }

                        // dont talk to someone we cant see, and dont talk to ourself
			if (!char_see_char(cn,co) || cn==co) { remove_message(cn,msg); continue; }

			// dont talk to someone far away
			if (char_dist(cn,co)>10) { remove_message(cn,msg); continue; }

                        // get current status with player
                        ppd=set_data(co,DRD_STAFFER_PPD,sizeof(struct staffer_ppd));

                        if (ppd) {
                                switch(ppd->dwarfchief_state) {
					case 0:         quiet_say(cn,"Welcome, stranger, to Grimroot, home of the dwarves. I would introduce you to our town further, but I have urgent matters to attend to.");
							questlog_open(co,47);
							ppd->dwarfchief_state++; didsay=1;
                                                        break;
					case 1:		quiet_say(cn,"Four of our miners have gone missing, one each in one of the 4 mine areas, and we can only think it's because of those bothersome golems...");
                                                        ppd->dwarfchief_state++; didsay=1;
							break;
                                        case 2:         quiet_say(cn,"If you wish, here's a scroll so you can help one of them. Give this one to the miner in the first section, then come back for another scroll for the next miner.");
                                                        ppd->dwarfchief_state++; didsay=1;
							if (!has_item(co,IID_DWARFRECALL1)) {
								in=create_item("dwarf_recall90");
								if (in) give_char_item(co,in);
							}
                                                        break;
					case 3:		break; // waiting for player to save first miner
					
					case 4:		questlog_done(co,47);
                                                        ppd->dwarfchief_state++;
							// fall-through intended
					case 5:		if (questlog_isdone(co,48)) { ppd->dwarfchief_state=8; break; }
							quiet_say(cn,"Not too bad for a human, you people are sturdier than I thought... Don't cheer up though, the miner in the next section is surrounded by stronger golems. Don't let them hurt your precious nails!");
							questlog_open(co,48);
                                                        ppd->dwarfchief_state++; didsay=1;
                                                        if (!has_item(co,IID_DWARFRECALL2)) {
								in=create_item("dwarf_recall100");
								if (in) give_char_item(co,in);
							}
                                                        break;
					case 6:		break; // waiting for player to save second miner
					
					case 7:		questlog_done(co,48);
                                                        ppd->dwarfchief_state++;
							// fall-through intended
					case 8:		if (questlog_isdone(co,49)) { ppd->dwarfchief_state=11; break; }
							quiet_say(cn,"A job well done! It's that we have enough hands already, otherwise I'd ask you to go out there and mine for us. Anyway, back to business. Go and find the next miner, and you will be rewarded again.");
							questlog_open(co,49);
                                                        ppd->dwarfchief_state++; didsay=1;
                                                        if (!has_item(co,IID_DWARFRECALL2)) {
								in=create_item("dwarf_recall110");
								if (in) give_char_item(co,in);
							}
                                                        break;
					case 9:		break; // waiting for player to save third miner
					
					case 10:	questlog_done(co,49);
                                                        ppd->dwarfchief_state++;
							// fall-through intended
					case 11:	if (questlog_isdone(co,50)) { ppd->dwarfchief_state=14; break; }
							quiet_say(cn,"Just in time! If you had been any later, he wouldn't have had his dinner, and trust me, you don't want to see a dwarf hungry, it's not a pretty sight. The fourth miner should be ok, he always packs more than the others, but do hurry and find him.");
							questlog_open(co,50);
                                                        ppd->dwarfchief_state++; didsay=1;
                                                        if (!has_item(co,IID_DWARFRECALL2)) {
								in=create_item("dwarf_recall120");
								if (in) give_char_item(co,in);
							}
                                                        break;
					case 12:	break; // waiting for player to save fourth miner

					case 13:	questlog_done(co,50);
                                                        ppd->dwarfchief_state++;
							// fall-through intended
					case 14:	quiet_say(cn,"Thank you for saving the last one! You have been of great help to us. Now let's hope they can stay out of the hands of those golems once and for all. Those recall scrolls aren't cheap you know!");
                                                        ppd->dwarfchief_state++; didsay=1;
                                                        break;
					case 15:	break; // all done

				}
				if (didsay) {
					dat->last_talk=ticker;
					talkdir=offset2dx(ch[cn].x,ch[cn].y,ch[co].x,ch[co].y);
					dat->current_victim=co;
				}
			}
		}

                // talk back
		if (msg->type==NT_TEXT) {
			co=msg->dat3;

			if (ch[co].flags&CF_PLAYER) {
				ppd=set_data(co,DRD_STAFFER_PPD,sizeof(struct staffer_ppd));
                                switch((didsay=analyse_text_driver(cn,msg->dat1,(char*)msg->dat2,co))) {
					case 2:         if (ppd && ppd->dwarfchief_state<=3) { dat->last_talk=0; ppd->dwarfchief_state=0; }
                                                        if (ppd && ppd->dwarfchief_state>=5 && ppd->dwarfchief_state<=6) { dat->last_talk=0; ppd->dwarfchief_state=5; }
							if (ppd && ppd->dwarfchief_state>=8 && ppd->dwarfchief_state<=9) { dat->last_talk=0; ppd->dwarfchief_state=8; }
							if (ppd && ppd->dwarfchief_state>=11 && ppd->dwarfchief_state<=12) { dat->last_talk=0; ppd->dwarfchief_state=11; }
							if (ppd && ppd->dwarfchief_state>=14 && ppd->dwarfchief_state<=15) { dat->last_talk=0; ppd->dwarfchief_state=14; }
                                                        break;
					case 3:		if (ch[co].flags&CF_GOD) { say(cn,"reset done"); ppd->dwarfchief_state=0; }
							break;
				}
                                if (didsay) {
					talkdir=offset2dx(ch[cn].x,ch[cn].y,ch[co].x,ch[co].y);
					dat->current_victim=co;
				}
			}
		}

		// got an item?
		if (msg->type==NT_GIVE) {
			co=msg->dat1;

                        if ((in=ch[cn].citem)) {	// we still have it
				quiet_say(cn,"Thou hast better use for this than I do. Well, if there is use for it at all.");
				if (!give_char_item(co,ch[cn].citem)) destroy_item(ch[cn].citem);
				ch[cn].citem=0;				
			}
		}

		remove_message(cn,msg);
	}

        // do something. whenever possible, call do_idle with as high a tick count
	// as reasonable when doing nothing.

	if (talkdir) turn(cn,talkdir);

	if (dat->last_talk+TICKS*30<ticker) {
		if (secure_move_driver(cn,ch[cn].tmpx,ch[cn].tmpy,DX_RIGHT,ret,lastact)) return;
	}

        do_idle(cn,TICKS);
}
Exemple #19
0
/* ---------------------------------------------------------------------
 * CMD_EVAL
 * This monster evaluates an if/or/and statement
 * There are five kinds of statement:
 * 1) keyword and value (no $-code)	    if random 30
 * 2) keyword, comparison and value	    if people > 2
 * 3) keyword and actor		    	    if isnpc $n
 * 4) keyword, actor and value		    if carries $n sword
 * 5) keyword, actor, comparison and value  if level $n >= 10
 *
 *----------------------------------------------------------------------
 */
int cmd_eval( sh_int vnum, char *line, int check,
	CHAR_DATA *mob, CHAR_DATA *ch, 
	const void *arg1, const void *arg2, CHAR_DATA *rch )
{
    CHAR_DATA *lval_char = mob;
    CHAR_DATA *vch = (CHAR_DATA *) arg2;
    OBJ_DATA *obj1 = (OBJ_DATA  *) arg1;
    OBJ_DATA *obj2 = (OBJ_DATA  *) arg2;
    OBJ_DATA  *lval_obj = NULL;

    char *original, buf[MAX_INPUT_LENGTH], code;
    int lval = 0, oper = 0, rval = -1;

    original = line;
    line = one_argument( line, buf );
    if ( buf[0] == '\0' || mob == NULL )
	return FALSE;

    /*
     * If this mobile has no target, let's assume our victim is the one
     */
    if ( mob->mprog_target == NULL )
	mob->mprog_target = ch;

    switch ( check )
    {
	/*
	 * Case 1: keyword and value
	 */
	case CHK_RAND:
	    return( atoi( buf ) < number_percent() );
	case CHK_MOBHERE:
	    if ( is_number( buf ) )
		return( get_mob_vnum_room( mob, atoi(buf) ) );
	    else
		return( (bool) (get_char_room( mob, buf) != NULL) );
	case CHK_OBJHERE:
	    if ( is_number( buf ) )
		return( get_obj_vnum_room( mob, atoi(buf) ) );
	    else
		return( (bool) (get_obj_here( mob, buf) != NULL) );
        case CHK_MOBEXISTS:
	    return( (bool) (get_char_world( mob, buf) != NULL) );
	case CHK_OBJEXISTS:
	    return( (bool) (get_obj_world( mob, buf) != NULL) );
	/*
	 * Case 2 begins here: We sneakily use rval to indicate need
	 * 		       for numeric eval...
	 */
	case CHK_PEOPLE:
	    rval = count_people_room( mob, 0 ); break;
	case CHK_PLAYERS:
	    rval = count_people_room( mob, 1 ); break;
	case CHK_MOBS:
	    rval = count_people_room( mob, 2 ); break;
	case CHK_CLONES:
	    rval = count_people_room( mob, 3 ); break;
	case CHK_ORDER:
	    rval = get_order( mob ); break;
	case CHK_HOUR:
	    rval = time_info.hour; break;
	default:;
    }

    /*
     * Case 2 continued: evaluate expression
     */
    if ( rval >= 0 )
    {
	if ( (oper = keyword_lookup( fn_evals, buf )) < 0 )
	{
	    sprintf( buf, "Cmd_eval: prog %d syntax error(2) '%s'",
		vnum, original );
	    bug( buf, 0 );
	    return FALSE;
	}
	one_argument( line, buf );
	lval = rval;
	rval = atoi( buf );
	return( num_eval( lval, oper, rval ) );
    }

    /*
     * Case 3,4,5: Grab actors from $* codes
     */
    if ( buf[0] != '$' || buf[1] == '\0' )
    {
	sprintf( buf, "Cmd_eval: prog %d syntax error(3) '%s'",
		vnum, original );
	bug( buf, 0 );
        return FALSE;
    }
    else
        code = buf[1];
    switch( code )
    {
    	case 'i':
            lval_char = mob; break;
        case 'n':
            lval_char = ch; break;
        case 't':
            lval_char = vch; break;
        case 'r':
            lval_char = rch == NULL ? get_random_char( mob ) : rch ; break;
        case 'o':
            lval_obj = obj1; break;
        case 'p':
            lval_obj = obj2; break;
	case 'q':
	    lval_char = mob->mprog_target; break;
	default:
	    sprintf( buf, "Cmd_eval: prog %d syntax error(4) '%s'",
		vnum, original );
	    bug( buf, 0 );
	    return FALSE;
    }
    /*
     * From now on, we need an actor, so if none was found, bail out
     */
    if ( lval_char == NULL && lval_obj == NULL )
    	return FALSE;

    /*
     * Case 3: Keyword, comparison and value
     */
    switch( check )
    {
	case CHK_ISPC:
            return( lval_char != NULL && !IS_NPC( lval_char ) );
        case CHK_ISNPC:
            return( lval_char != NULL && IS_NPC( lval_char ) );
        case CHK_ISGOOD:
            return( lval_char != NULL && IS_GOOD( lval_char ) );
        case CHK_ISEVIL:
            return( lval_char != NULL && IS_EVIL( lval_char ) );
        case CHK_ISNEUTRAL:
            return( lval_char != NULL && IS_NEUTRAL( lval_char ) );
	case CHK_ISIMMORT:
            return( lval_char != NULL && IS_IMMORTAL( lval_char ) );
        case CHK_ISCHARM: /* A relic from MERC 2.2 MOBprograms */
            return( lval_char != NULL && IS_AFFECTED( lval_char, AFF_CHARM ) );
        case CHK_ISFOLLOW:
            return( lval_char != NULL && lval_char->master != NULL 
		 && lval_char->master->in_room == lval_char->in_room );
	case CHK_ISACTIVE:
	    return( lval_char != NULL && lval_char->position > POS_SLEEPING );
	case CHK_ISDELAY:
	    return( lval_char != NULL && lval_char->mprog_delay > 0 );
	case CHK_ISVISIBLE:
            switch( code )
            {
                default :
                case 'i':
                case 'n':
                case 't':
                case 'r':
		case 'q':
	    	    return( lval_char != NULL && can_see( mob, lval_char ) );
		case 'o':
		case 'p':
	    	    return( lval_obj != NULL && can_see_obj( mob, lval_obj ) );
	    }
	case CHK_HASTARGET:
	    return( lval_char != NULL && lval_char->mprog_target != NULL
		&&  lval_char->in_room == lval_char->mprog_target->in_room );
	case CHK_ISTARGET:
	    return( lval_char != NULL && mob->mprog_target == lval_char );
	default:;
     }

     /* 
      * Case 4: Keyword, actor and value
      */
     line = one_argument( line, buf );
     switch( check )
     {
	case CHK_AFFECTED:
	    return( lval_char != NULL 
		&&  IS_SET(lval_char->affected_by, flag_lookup(buf, affect_flags)) );
	case CHK_ACT:
	    return( lval_char != NULL 
		&&  IS_SET(lval_char->act, flag_lookup(buf, act_flags)) );
	case CHK_IMM:
	    return( lval_char != NULL 
		&&  IS_SET(lval_char->imm_flags, flag_lookup(buf, imm_flags)) );
	case CHK_OFF:
	    return( lval_char != NULL 
		&&  IS_SET(lval_char->off_flags, flag_lookup(buf, off_flags)) );
	case CHK_CARRIES:
	    if ( is_number( buf ) )
		return( lval_char != NULL && has_item( lval_char, atoi(buf), -1, FALSE ) );
	    else
		return( lval_char != NULL && (get_obj_carry( lval_char, buf ) != NULL) );
	case CHK_WEARS:
	    if ( is_number( buf ) )
		return( lval_char != NULL && has_item( lval_char, atoi(buf), -1, TRUE ) );
	    else
		return( lval_char != NULL && (get_obj_wear( lval_char, buf ) != NULL) );
	case CHK_HAS:
	    return( lval_char != NULL && has_item( lval_char, -1, item_lookup(buf), FALSE ) );
	case CHK_USES:
	    return( lval_char != NULL && has_item( lval_char, -1, item_lookup(buf), TRUE ) );
	case CHK_NAME:
            switch( code )
            {
                default :
                case 'i':
                case 'n':
                case 't':
                case 'r':
		case 'q':
		    return( lval_char != NULL && is_name( buf, lval_char->name ) );
		case 'o':
		case 'p':
		    return( lval_obj != NULL && is_name( buf, lval_obj->name ) );
	    }
	case CHK_POS:
	    return( lval_char != NULL && lval_char->position == position_lookup( buf ) );
	case CHK_CLAN:
	    return( lval_char != NULL && lval_char->clan == clan_lookup( buf ) );
	case CHK_RACE:
	    return( lval_char != NULL && lval_char->race == race_lookup( buf ) );
	case CHK_OBJTYPE:
	    return( lval_obj != NULL && lval_obj->item_type == item_lookup( buf ) );
	default:;
    }

    /*
     * Case 5: Keyword, actor, comparison and value
     */
    if ( (oper = keyword_lookup( fn_evals, buf )) < 0 )
    {
	sprintf( buf, "Cmd_eval: prog %d syntax error(5): '%s'",
		vnum, original );
	bug( buf, 0 );
	return FALSE;
    }
    one_argument( line, buf );
    rval = atoi( buf );

    switch( check )
    {
	case CHK_VNUM:
	    switch( code )
            {
                default :
                case 'i':
                case 'n':
                case 't':
                case 'r':
		case 'q':
                    if( lval_char != NULL && IS_NPC( lval_char ) )
                        lval = lval_char->pIndexData->vnum;
                    break;
                case 'o':
                case 'p':
                     if ( lval_obj != NULL )
                        lval = lval_obj->pIndexData->vnum;
            }
            break;
	case CHK_HPCNT:
	    if ( lval_char != NULL ) lval = (lval_char->hit * 100)/(UMAX(1,lval_char->max_hit)); break;
	case CHK_ROOM:
	    if ( lval_char != NULL && lval_char->in_room != NULL )
		lval = lval_char->in_room->vnum; break;
        case CHK_SEX:
	    if ( lval_char != NULL ) lval = lval_char->sex; break;
        case CHK_LEVEL:
            if ( lval_char != NULL ) lval = lval_char->level; break;
	case CHK_ALIGN:
            if ( lval_char != NULL ) lval = lval_char->alignment; break;
	case CHK_MONEY:  /* Money is converted to silver... */
	    if ( lval_char != NULL ) 
		lval = lval_char->gold + (lval_char->silver * 100); break;
	case CHK_OBJVAL0:
            if ( lval_obj != NULL ) lval = lval_obj->value[0]; break;
        case CHK_OBJVAL1:
            if ( lval_obj != NULL ) lval = lval_obj->value[1]; break;
        case CHK_OBJVAL2: 
            if ( lval_obj != NULL ) lval = lval_obj->value[2]; break;
        case CHK_OBJVAL3:
            if ( lval_obj != NULL ) lval = lval_obj->value[3]; break;
	case CHK_OBJVAL4:
	    if ( lval_obj != NULL ) lval = lval_obj->value[4]; break;
	case CHK_GRPSIZE:
	    if( lval_char != NULL ) lval = count_people_room( lval_char, 4 ); break;
	default:
            return FALSE;
    }
    return( num_eval( lval, oper, rval ) );
}
Exemple #20
0
/* parses portsmanrc file and resets config if needed,
   returns 0 if everything was ok, ERROR_NO_RC_FILE if
   file could not be opened or a positive int of the
   line number where ERROR_CORRUPT_RC_FILE succeeded or
   an unknown keyword exist */
int
parse_rc_file(char *filepath) {
   FILE *fd;
   extern Config config;
   bool readyKey = FALSE;
   bool validKey = FALSE;
   bool readyValue = FALSE;
   bool comment = FALSE;
   char tok[MAX_TOKEN];
   char arg[MAX_TOKEN];
   char *key;
   char *val;
   int i = 0, c = 0, line = 0;
   short sh = 0;
   
   if ((fd = fopen(filepath, "r")) == NULL)
      return ERROR_NO_RC_FILE; /* not present */

   while (feof(fd) == 0) {
      c = fgetc(fd); /* get next char */
      switch (c) {
         case '\t': 
            break;
         case '#':
            comment = TRUE; /* until eol */
            if (validKey && (i > 0)) /* ready value */
               readyValue = TRUE;
            break;
         case '\n': /* eol */
            line++;
            comment = FALSE;
            /* ready value */
            if (validKey && (i > 0))  /* ready value */
               readyValue = TRUE;
            else {
               validKey = FALSE;
               readyKey = FALSE;
            }
            break;
         case '=':
            if (!comment) {
               if (i > 0)
                  readyKey = TRUE;
               else
                  return line;
            }
            break;
         default: /* else it's a alphanum char */
            if (!comment) 
               if ((c != ' ') || ((c == ' ') && validKey))
                  tok[i++] = (char)c;
            break;
      }

      if (readyKey) {
         tok[i] = '\0'; /* terminate key token */
         key = strdup(tok);
         i = 0;
         readyKey = FALSE;
         validKey = TRUE;
      } else if (readyValue) {
         tok[i] = '\0'; /* terminate value token */
         val = tok;

         if (strcmp(key, "use.metacats") == 0) {
            sh = str_to_state(val);
            if (sh == ERROR_CORRUPT_RC_FILE) {
               return (line); /* error */
            } else {
               config.use_metacats = (sh == STATE_SELECTED) ?
                  TRUE : FALSE;
            }
         } else if (strcmp(key, "titlebar.fcolor") == 0) {
            sh = str_to_color(val);
            if (sh == ERROR_CORRUPT_RC_FILE) {
               return (line); /* error */
            } else {
               config.fcolors[CLR_TITLE] = sh;
            }
         } else if (strcmp(key, "titlebar.bcolor") == 0) {
            sh = str_to_color(val);
            if (sh == ERROR_CORRUPT_RC_FILE) {
               return (line); /* error */
            } else {
               config.bcolors[CLR_TITLE] = sh;
            }
         } else if (strcmp(key, "browser.fcolor") == 0) {
            sh = str_to_color(val);
            if (sh == ERROR_CORRUPT_RC_FILE) {
               return (line); /* error */
            } else {
               config.fcolors[CLR_BROWSE] = sh;
            }
         } else if (strcmp(key, "browser.bcolor") == 0) {
            sh = str_to_color(val);
            if (sh == ERROR_CORRUPT_RC_FILE) {
               return (line); /* error */
            } else {
               config.bcolors[CLR_BROWSE] = sh;
            }
         } else if (strcmp(key, "statusbar.fcolor") == 0) {
            sh = str_to_color(val);
            if (sh == ERROR_CORRUPT_RC_FILE) {
               return (line); /* error */
            } else {
               config.fcolors[CLR_STATUS] = sh;
            }
         } else if (strcmp(key, "statusbar.bcolor") == 0) {
            sh = str_to_color(val);
            if (sh == ERROR_CORRUPT_RC_FILE) {
               return (line); /* error */
            } else {
               config.bcolors[CLR_STATUS] = sh;
            }
         } else if (strcmp(key, "cmdbar.fcolor") == 0) {
            sh = str_to_color(val);
            if (sh == ERROR_CORRUPT_RC_FILE) {
               return (line); /* error */
            } else {
               config.fcolors[CLR_CMD] = sh;
            }
         } else if (strcmp(key, "cmdbar.bcolor") == 0) {
            sh = str_to_color(val);
            if (sh == ERROR_CORRUPT_RC_FILE) {
               return (line); /* error */
            } else {
               config.bcolors[CLR_CMD] = sh;
            }
         } else if (strcmp(key, "selector.fcolor") == 0) {
            sh = str_to_color(val);
            if (sh == ERROR_CORRUPT_RC_FILE) {
               return (line); /* error */
            } else {
               config.fcolors[CLR_SELECTOR] = sh;
            }
         } else if (strcmp(key, "selector.bcolor") == 0) {
            sh = str_to_color(val);
            if (sh == ERROR_CORRUPT_RC_FILE) {
               return (line); /* error */
            } else {
               config.bcolors[CLR_SELECTOR] = sh;
            }
         } else if (strcmp(key, "indexfile") == 0) {
            config.index_file = strdup(val);
         } else if (strcmp(key, "pkgdir") == 0) {
            config.inst_pkg_dir = strdup(val);
         } else if (strcmp(key, "portsdir") == 0) {
            config.ports_dir = strdup(val);
         } else if (strcmp(key, "make.cmd") == 0) {
            config.make_cmd = strdup(val);
         } else if (strcmp(key, "make.target.inst") == 0) {
            config.make_target[MK_TARGET_INST] = strdup(val);
         } else if (strcmp(key, "make.target.deinst") == 0) {
            config.make_target[MK_TARGET_DEINST] = strdup(val);
         } else if (strcmp(key, "make.target.update") == 0) {
            config.make_target[MK_TARGET_UPDATE] = strdup(val);
         } else if (strcmp(key, "make.option.force") == 0) {
            sh = str_to_state(val);
            if (sh == ERROR_CORRUPT_RC_FILE) {
               return (line); /* error */
            } else {
               config.make_option[MK_OPTION_FORCE] = sh;
            }
         } else if (strcmp(key, "make.option.pkg") == 0) {
            sh = str_to_state(val);
            if (sh == ERROR_CORRUPT_RC_FILE) {
               return (line); /* error */
            } else {
               config.make_option[MK_OPTION_PKG] = sh;
            }
         } else if (strcmp(key, "make.option.clean") == 0) {
            sh = str_to_state(val);
            if (sh == ERROR_CORRUPT_RC_FILE) {
               return (line); /* error */
            } else {
               config.make_option[MK_OPTION_CLEAN] = sh;
            }
         } else if (strcmp(key, "make.option.nochksum") == 0) {
            sh = str_to_state(val);
            if (sh == ERROR_CORRUPT_RC_FILE) {
               return (line); /* error */
            } else {
               config.make_option[MK_OPTION_NOCHKSUM] = sh;
            }
         } else if (strcmp(key, "make.option.nodeps") == 0) {
            sh = str_to_state(val);
            if (sh == ERROR_CORRUPT_RC_FILE) {
               return (line); /* error */
            } else {
               config.make_option[MK_OPTION_NODEPS] = sh;
            }
         } else if (strcmp(key, "make.option.forcepkgreg") == 0) {
            sh = str_to_state(val);
            if (sh == ERROR_CORRUPT_RC_FILE) {
               return (line); /* error */
            } else {
               config.make_option[MK_OPTION_FORCEPKGREG] = sh;
            }
         } else if (strcmp(key, "make.option.nopkgreg") == 0) {
            sh = str_to_state(val);
            if (sh == ERROR_CORRUPT_RC_FILE) {
               return (line); /* error */
            } else {
               config.make_option[MK_OPTION_NOPKGREG] = sh;
            }
         } else if (strcmp(key, "make.option.force.arg") == 0) {
            sprintf(arg, "%s=yes", val);
            config.make_option_arg[MK_OPTION_FORCE] = strdup(arg);
         } else if (strcmp(key, "make.option.pkg.arg") == 0) {
            sprintf(arg, "%s=yes", val);
            config.make_option_arg[MK_OPTION_PKG] = strdup(arg);
         } else if (strcmp(key, "make.option.clean.arg") == 0) {
            sprintf(arg, "%s=yes", val);
            config.make_option_arg[MK_OPTION_CLEAN] = strdup(arg);
         } else if (strcmp(key, "make.option.nochksum.arg") == 0) {
            sprintf(arg, "%s=yes", val);
            config.make_option_arg[MK_OPTION_NOCHKSUM] = strdup(arg);
         } else if (strcmp(key, "make.option.nodeps.arg") == 0) {
            sprintf(arg, "%s=yes", val);
            config.make_option_arg[MK_OPTION_NODEPS] = strdup(arg);
         } else if (strcmp(key, "make.option.forcepkgreg.arg") == 0) {
            sprintf(arg, "%s=yes", val);
            config.make_option_arg[MK_OPTION_FORCEPKGREG] = strdup(arg);
         } else if (strcmp(key, "make.option.nopkgreg.arg") == 0) {
            sprintf(arg, "%s=yes", val);
            config.make_option_arg[MK_OPTION_NOPKGREG] = strdup(arg);
         } else if (strcmp(key, "rsync.cmd") == 0) {
            config.rsync_cmd = strdup(val);
         } else if (strcmp(key, "rsync.hostname") == 0) {
            if (!has_item(config.lrsynchosts, val, cmp_str))
               add_list_item(config.lrsynchosts, strdup(val));
         } else {
            return line; /* also error: unknown key */
         }

         readyValue = FALSE;
         validKey = FALSE;
         free(key);
         i = 0;
     }

   }
   fclose(fd);

   return (0);
}
Exemple #21
0
static int lowprobe_device(blkid_probe pr, const char *devname,	char *show[],
			int output, blkid_loff_t offset, blkid_loff_t size)
{
	const char *data;
	const char *name;
	int nvals = 0, n, num = 1;
	size_t len;
	int fd;
	int rc = 0;
	struct stat st;

	fd = open(devname, O_RDONLY);
	if (fd < 0) {
		fprintf(stderr, "error: %s: %s\n", devname, strerror(errno));
		return 2;
	}
	if (blkid_probe_set_device(pr, fd, offset, size))
		goto done;

	if (fstat(fd, &st))
		goto done;
	/*
	 * partitions probing
	 */
	blkid_probe_enable_superblocks(pr, 0);	/* enabled by default ;-( */

	blkid_probe_enable_partitions(pr, 1);
	rc = blkid_do_fullprobe(pr);
	blkid_probe_enable_partitions(pr, 0);

	if (rc < 0)
		goto done;	/* -1 = error, 1 = nothing, 0 = succes */

	/*
	 * Don't probe for FS/RAIDs on small devices
	 */
	if (rc || S_ISCHR(st.st_mode) ||
	    blkid_probe_get_size(pr) > 1024 * 1440) {
		/*
		 * filesystems/RAIDs probing
		 */
		blkid_probe_enable_superblocks(pr, 1);

		rc = blkid_do_safeprobe(pr);
		if (rc < 0)
			goto done;
	}

	nvals = blkid_probe_numof_values(pr);

	if (output & OUTPUT_DEVICE_ONLY) {
		printf("%s\n", devname);
		goto done;
	}

	for (n = 0; n < nvals; n++) {
		if (blkid_probe_get_value(pr, n, &name, &data, &len))
			continue;
		if (show[0] && !has_item(show, name))
			continue;
		len = strnlen((char *) data, len);
		print_value(output, num++, devname, (char *) data, name, len);
	}

	if (nvals >= 1 && !(output & (OUTPUT_VALUE_ONLY | OUTPUT_UDEV_LIST)))
		printf("\n");
done:
	if (rc == -2) {
		if (output & OUTPUT_UDEV_LIST)
			print_udev_ambivalent(pr);
		else
			fprintf(stderr,
				"%s: ambivalent result (probably more "
				"filesystems on the device, use wipefs(8) "
				"to see more details)\n",
				devname);
	}
	close(fd);
	return !nvals ? 2 : 0;
}
Exemple #22
0
void
location_production()
{
  int where;
  int i, enclosed;
  int terr, encl_terr;
  int has_city;
  float pop_grow = 0.0;
  int pop_limit = 200, pop, dpop = 0;

  loop_loc(where) {
    terr = subkind(where);
    has_city = 0;

    for (i = 0; terr_prod[i].terr; i++)
      if (terr_prod[i].terr == terr) {
        replenish(where, terr_prod[i].item, terr_prod[i].qty,
                  terr_prod[i].max);
      }

    /*
     *  Mon Sep 16 11:42:22 1996 -- Scott Turner
     *
     *  Now check for production from enclosed locations...
     *
     */
    loop_here(where, enclosed) {
      encl_terr = subkind(enclosed);
      if (encl_terr == sub_city)
        has_city = 1;
      for (i = 0; terr_prod2[i].terr; i++)
        if (terr_prod2[i].terr == encl_terr) {
          replenish(where, terr_prod2[i].item, terr_prod2[i].qty,
                    terr_prod2[i].max);
        };
    }
    next_here;

    /*
     *  First limit poppy fields to normal production level.
     *  Then double opium if poppy field was specially tended.
     */
    if (terr == sub_poppy_field) {
      int n;

      n = has_item(where, item_opium);
      if (n > POPPY_OPIUM)
        consume_item(where, item_opium, n - POPPY_OPIUM);

      if (rp_misc(where) && rp_misc(where)->opium_double) {
        rp_misc(where)->opium_double = FALSE;
        gen_item(where, item_opium, has_item(where, item_opium));
      }
    }

    if (terr == sub_island ||
        (loc_depth(where) == LOC_province && has_ocean_access(where)))
      replenish(where, item_flotsam, 30, 30);

    /*
     *  Sun Dec  1 10:34:41 1996 -- Scott Turner
     *
     *  Peasant production.  Depends upon the location (and
     *  whether it contains a city).
     *
     *  Has_city is set up above...
     *
     *  Tue Sep 22 13:20:18 1998 -- Scott Turner
     *
     *  Faery ought not have peasants.  It should have (I guess)
     *  elf peasants, although what you can do with those is
     *  open to conjecture :-)
     *
     */
    if (pop = has_item(where, item_peasant)) {
      if (has_city) {
        pop_grow = 0.03;
        pop_limit = 10000;
      }
      else {
        switch (terr) {
        case sub_plain:
        case sub_forest:
          pop_grow = 0.01;
          pop_limit = 1000;
          break;
        case sub_mountain:
        case sub_swamp:
          pop_grow = 0.005;
          pop_limit = 1000;
          break;
        default:
          pop_grow = 0.000;
          pop_limit = 500;
          break;
        };
      };

      /*
       *  Might be an effect here.
       *
       */
      if (get_effect(where, ef_grow, 0, 0)) {
        wout(where, "The peasants seem particularly happy this month.");
        pop_grow += 0.02;
      };

      dpop = pop * pop_grow;
      if (pop_grow > 0.0 && dpop < 1)
        dpop = 1;
      /*
       *  Lose population at a reasonable rate.
       *
       */
      if (pop > pop_limit)
        dpop = -(pop - pop_limit) / 10;

      if (p_subloc(province(where))->loot && dpop > 0) {
        wout(where,
             "Pillaging traumatizes the population and no growth occurs.");
      }
      else if (dpop > 0) {
        if (pop > 100)
          wout(where, "The population grows by %s peasant%s.",
               nice_num(dpop), add_s(dpop));
        gen_item(where, item_peasant, dpop);
      }
      else {
        if (pop > 100)
          wout(where, "Overcrowding causes %s peasant death%s.",
               nice_num(-dpop), add_s(-dpop));
        consume_item(where, item_peasant, -dpop);
      };
    };

    /*
     *  Sat Apr 18 16:57:53 1998 -- Scott Turner
     *
     *  Special case for gold production from peasants.
     *  They generate 1 gold per 20 peasants (1/10 in cities)
     *  which accumulates to be removed by various means.
     *
     *  Only in civilized (> 100) provinces
     */
    if ((pop = has_item(where, item_peasant)) > 100) {
      if (has_city) {
        dpop = pop * 0.10;
      }
      else {
        dpop = pop * 0.05;
      };
      gen_item(where, item_gold, dpop);
    };
  }
int
d_breed(struct command *c)
{
  int i1 = c->a;
  int i2 = c->b;
  int offspring;
  int breed_accident = BREED_ACCIDENT;
  int killed = FALSE;

  if (is_real_npc(c->who)) return d_npc_breed(c);

  if (kind(i1) != T_item)
    {
      wout(c->who, "%s is not an item.", c->parse[1]);
      return FALSE;
    }

  if (kind(i2) != T_item)
    {
      wout(c->who, "%s is not an item.", c->parse[2]);
      return FALSE;
    }

  if (has_item(c->who, i1) < 1)
    {
      wout(c->who, "Don't have any %s.", box_code(i1));
      return FALSE;
    }

  if (has_item(c->who, i2) < 1)
    {
      wout(c->who, "Don't have any %s.", box_code(i2));
      return FALSE;
    }

  if (i1 == i2 && has_item(c->who, i1) < 2)
    {
      wout(c->who, "Don't have two %s.", box_code(i1));
      return FALSE;
    }

  /*
   *  A normal union just succeeds.
   *
   */
  if (normal_union(i1, i2)) {
    offspring = find_breed(i1, i2);
    wout(c->who, "Produced %s.", box_name_qty(offspring, 1));
    gen_item(c->who, offspring, 1);
    add_skill_experience(c->who, sk_breed_beasts);
    p_skill(sk_breed_beasts)->use_count++;
    return TRUE;
  };

  /*
   *  A non-normal union is more problematic.
   *
   */
  if (!has_holy_symbol(c->who)) {
    wout(c->who, "A holy symbol is required for that breeding.");
    return FALSE;
  };

  /*
   *  Wed Feb 23 12:01:17 2000 -- Scott Turner
   *
   *  Have to directly encode the piety required here so it won't
   *  be charged automatically in use.c
   *
   */
  if (!use_piety(c->who, 3)) {
    wout(c->who, "You don't have the piety required to use that prayer.");
    return FALSE;
  };

  p_skill(sk_breed_beasts)->use_count++;

  /*
   *  The following isn't quite right -- there is no chance of
   *  killing both the breeders if they are of the same type.
   */

  offspring = find_breed(i1, i2);

  if (offspring == item_dragon)
    breed_accident = 13;

  if (i1 == i2)
    breed_accident *= 2;

  if (i1 && rnd(1,100) <= breed_accident)
    {
      wout(c->who, "%s was killed in the breeding attempt.",
	   cap(box_name_qty(i1, 1)));
      consume_item(c->who, i1, 1);
      killed = TRUE;
    }

  if (i2 && rnd(1,100) <= breed_accident && i1 != i2)
    {
      wout(c->who, "%s was killed in the breeding attempt.",
	   cap(box_name_qty(i2, 1)));
      consume_item(c->who, i2, 1);
      killed = TRUE;
    }

  if (offspring == 0 || rnd(1,4) == 1)
    {
      wout(c->who, "No offspring was produced.");
      return FALSE;
    }

  wout(c->who, "Produced %s.", box_name_qty(offspring, 1));

  gen_item(c->who, offspring, 1);
  add_skill_experience(c->who, sk_breed_beasts);

  return TRUE;
};
/*
 *  Wed Mar  5 12:14:55 1997 -- Scott Turner
 *
 *  Added hooks for npc_breed, which is used by the NPC chars.
 *
 */
int
v_breed(struct command *c)
{
  int i1 = c->a;
  int i2 = c->b;
  int exp;

  if (is_real_npc(c->who)) {
    c->wait += 7;
    return TRUE;
  };

  if (!has_skill(c->who, sk_breed_beasts))
    {
      wout(c->who, "Requires %s.", box_name(sk_breed_beasts));
      return FALSE;
    }
  c->use_skill = sk_breed_beasts;

  if (numargs(c) < 2)
    {
      wout(c->who, "Usage: breed <item> <item>");
      return FALSE;
    }

  if (kind(i1) != T_item)
    {
      wout(c->who, "%s is not an item.", c->parse[1]);
      return FALSE;
    }

  if (kind(i2) != T_item)
    {
      wout(c->who, "%s is not an item.", c->parse[2]);
      return FALSE;
    }

  if (has_item(c->who, i1) < 1)
    {
      wout(c->who, "Don't have any %s.", box_code(i1));
      return FALSE;
    }

  if (has_item(c->who, i2) < 1)
    {
      wout(c->who, "Don't have any %s.", box_code(i2));
      return FALSE;
    }

  if (i1 == i2 && has_item(c->who, i1) < 2)
    {
      wout(c->who, "Don't have two %s.", box_code(i1));
      return FALSE;
    }

  /*
   *  Thu Oct 10 12:15:09 1996 -- Scott Turner
   *
   *  May need a holy symbol & piety.
   *
   */
  if (!normal_union(i1, i2)) {
    if (!has_holy_symbol(c->who)) {
      wout(c->who, "A holy symbol is required for that breeding.");
      return FALSE;
    };

    if (!has_piety(c->who, skill_piety(c->use_skill))) {
      wout(c->who, "You don't have the piety required to use that prayer.");
      return FALSE;
    };
  };

  /* 
   *  Hack to fold experience_use_speedup into this skill
   *  if they use BREED instead of USE xxxx
   */

  c->wait = 7;
  exp = max(has_skill(c->who, sk_breed_beasts) - 1, 0);
  if (exp)
    c->wait--;

  return TRUE;
}