Ejemplo n.º 1
0
int
display_mark(i_type only_itype, int only_cheapest)
{
    struct comstr comm;
    struct comstr comm2;
    int sellers = 0;
    int cnt = 0;
    int cheapest_items[I_MAX + 1];
    i_type i;

    /* Execute trades so report lists only lots that are still available. */
    check_market();
    check_trade();

    pr("\n     Empire Market Report\n   ");
    prdate();
    pr(" lot  high bid/unit  by  time left  owner  item  amount  sector\n");
    pr(" ---  -------------  --  ---------  -----  ----  ------  ------\n");

    if (only_cheapest) {
	for (i = I_NONE + 1; i <= I_MAX; i++)
	    cheapest_items[i] = -1;
	for (sellers = 0; getcomm(sellers, &comm); sellers++) {
	    if (comm.com_owner == 0)
		continue;
	    if (CANT_HAPPEN(comm.com_type <= I_NONE || comm.com_type > I_MAX))
		continue;
	    if (cheapest_items[comm.com_type] != -1) {
		getcomm(cheapest_items[comm.com_type], &comm2);
		if (comm.com_price < comm2.com_price) {
		    cheapest_items[comm.com_type] = sellers;
		}
	    } else {
		cheapest_items[comm.com_type] = sellers;
	    }
	}
	CANT_HAPPEN(only_itype != I_NONE); /* not implemented */
	for (i = I_NONE + 1; i <= I_MAX; i++) {
	    if (cheapest_items[i] == -1)
		continue;
	    getcomm(cheapest_items[i], &comm);
	    cnt = 1;
	    pr_mark(&comm);
	}
    } else {
	for (sellers = 0; getcomm(sellers, &comm); sellers++) {
	    if (comm.com_owner == 0)
		continue;
	    if (only_itype != I_NONE && comm.com_type != only_itype)
		continue;
	    cnt = 1;
	    pr_mark(&comm);
	}
    }
    if (cnt <= 0)
	pr("\nHmmmm, the market seems to be empty today.\n");
    else
	pr("\nLooks just like Christmas at K-mart, doesn't it!\n");
    return RET_OK;
}
Ejemplo n.º 2
0
void MainWindow::init_com()
{
    QString path="HKEY_LOCAL_MACHINE\\HARDWARE\\DEVICEMAP\\SERIALCOMM";
    QSettings *settings=new QSettings(path,QSettings::NativeFormat);
    QStringList key=settings->allKeys();
    QStringList comlist ;
    QStringList Baudlist ;
    QStringList Paritylist ;
    QStringList DataBitslist;
    QStringList StopBitslist;
    QStringList ControlFlowlist;

    int kk = key.size();
    int i;
    comlist.clear();
    for(i=0;i<kk;i++)
    {
        comlist << getcomm(i,"value");
    }
    ui->portNameComboBox->addItems(comlist);

    //波特率
    Baudlist.clear();
    Baudlist<< "300" << "600" << "2400" << "4800" << "9600"<< "19200" <<
             "56000" << "57600" << "115200"<<"128000"<<"256000"<< "921600";
    ui->baudRateComboBox->addItems(Baudlist);
    ui->baudRateComboBox->setCurrentText("19200");


}
Ejemplo n.º 3
0
void MainWindow::init_comm()
{
    QString path = "HKEY_LOCAL_MACHINE\\HARDWARE\\DEVICEMAP\\SERIALCOMM";
    QSettings *settings = new QSettings(path, QSettings::NativeFormat);
    QStringList key = settings->allKeys();
    qDebug()<<tr("key size = %1").arg(key.size());
    QStringList comlist ;
    QStringList Baudlist ;

    comlist.clear();

    /* 取串口名 */
    for (int i=0; i<key.size(); i++) {
        comlist << getcomm(i, "value");
    }
    ui->comboBox->addItems(comlist);
}
Ejemplo n.º 4
0
tableput()
{
saveline();
savefill();
ifdivert();
cleanfc();
getcomm();
getspec();
gettbl();
getstop();
checkuse();
choochar();
maktab();
runout();
release();
rstofill();
endoff();
restline();
}
Ejemplo n.º 5
0
void MainWindow::init_com()
{
    QString path="HKEY_LOCAL_MACHINE\\HARDWARE\\DEVICEMAP\\SERIALCOMM";
    QSettings *settings=new QSettings(path,QSettings::NativeFormat);
    QStringList key=settings->allKeys();
    QStringList comlist ;
    QStringList Baudlist ;
    QStringList Paritylist ;
    QStringList DataBitslist;
    QStringList StopBitslist;
    QStringList ControlFlowlist;

    int kk = key.size();
    int i;
    comlist.clear();
    for(i=0;i<kk;i++)
    {
        comlist << getcomm(i,"value");
    }
    ui->portNameComboBox->addItems(comlist);

    //波特率
    Baudlist.clear();
    Baudlist<< "300" << "600" << "2400" << "4800" << "9600"<< "19200" <<
             "56000" << "57600" << "115200"<<"128000"<<"256000"<< "921600";
    ui->baudRateComboBox->addItems(Baudlist);
    ui->baudRateComboBox->setCurrentText("19200");

    ui->Red_horizontalSlider->setMinimum(0);//Slider的最小值
    ui->Green_horizontalSlider->setMinimum(0);
    ui->Blue_horizontalSlider->setMinimum(0);
    ui->Red_horizontalSlider->setMaximum(255);//Slider的最大值
    ui->Green_horizontalSlider->setMaximum(255);
    ui->Blue_horizontalSlider->setMaximum(255);
    ui->Red_horizontalSlider->setValue(Red.toInt());//Slider的初始化值
    ui->Green_horizontalSlider->setValue(Green.toInt());
    ui->Blue_horizontalSlider->setValue(Blue.toInt());
    ui->Red_horizontalSlider->setPageStep(1);//Slider的每次变化为1
    ui->Green_horizontalSlider->setPageStep(1);
    ui->Blue_horizontalSlider->setPageStep(1);
}
Ejemplo n.º 6
0
/*
 * format: trade
 */
int
trad(void)
{
    struct sctstr sect;
    struct natstr *natp;
    struct comstr comt;
    int lotno;
    float price;
    coord sx, sy;
    int n;
    char *p;
    struct nstr_item ni;
    struct trdstr trade;
    struct trdstr tmpt;
    union empobj_storage tg;
    double canspend;
    time_t now, tleft;
    int bid;
    double tally;
    int i;
    char buf[1024];

    if (!opt_MARKET) {
	pr("The market is disabled.\n");
	return RET_FAIL;
    }
    /* First, we execute all trades, so that we can only buy what is available. */
    check_market();
    check_trade();

    pr("\n     Empire Trade Report\n  ");
    prdate();
    n = 0;
    pr(" lot high bid  by time left owner  description\n");
    pr(" --- --------  -- --------- -----  -------------------------\n");

    snxtitem_all(&ni, EF_TRADE);
    while (nxtitem(&ni, &trade)) {
	if (trade.trd_owner == 0)
	    continue;
	if (!trade_getitem(&trade, &tg)) {
	    continue;
	};
	pr(" %3d ", ni.cur);
	(void)time(&now);
	tleft = trade.trd_markettime + TRADE_DELAY - now;
	if (tleft < 0)
	    tleft = 0;
	pr("$%7d  %2d %5.2f hrs ",
	   trade.trd_price, trade.trd_maxbidder, tleft / 3600.0);
	trade_desc(&tg.gen);	/* XXX */
	pr("\n");
	if (trade.trd_owner == player->cnum && !player->god)
	    pr(" (your own lot)\n");
	n++;
    }
    if (n == 0) {
	pr("Nothing to buy at the moment...\n");
	return RET_OK;
    }
    p = getstring("Which lot to buy: ", buf);
    if (!p || !*p)
	return RET_OK;
    if (isdigit(*p) == 0)
	return RET_OK;
    lotno = atoi(p);
    if (lotno < 0 || lotno >= ni.cur) {
	pr("Bad lot number\n");
	return RET_OK;
    }
    if (!gettrade(lotno, &trade)) {
	pr("No such lot number\n");
	return RET_OK;
    }
    if (trade.trd_unitid < 0) {
	pr("Invalid lot number.\n");
	return RET_OK;
    }
    if (!trade_getitem(&trade, &tg)) {
	pr("Can't find trade #%d!\n", trade.trd_unitid);
	trade.trd_owner = 0;
	trade.trd_unitid = -1;
	if (!puttrade(lotno, &trade)) {
	    logerror("trad: can't write trade");
	    pr("Couldn't save after getitem failed; get help!\n");
	    return RET_FAIL;
	}
	return RET_OK;
    }
    switch (trade.trd_type) {
    case EF_NUKE:
    case EF_PLANE:
    case EF_SHIP:
    case EF_LAND:
	break;
    default:
	pr("Bad unit type on lot number %d\n", lotno);
	return RET_FAIL;
    }
    if (trade.trd_owner == player->cnum) {
	pr("You can't buy from yourself!\n");
	return RET_OK;
    }
    price = trade.trd_price;
    natp = getnatp(player->cnum);
    if (natp->nat_money < price) {
	pr("You don't have %.2f to spend!\n", price);
	return RET_OK;
    }
    tally = 0.0;
    for (i = 0; gettrade(i, &tmpt); i++) {
	if (tmpt.trd_maxbidder == player->cnum &&
	    tmpt.trd_unitid >= 0 && tmpt.trd_owner != player->cnum) {
	    tally += tmpt.trd_price * tradetax;
	}
    }
    for (i = 0; getcomm(i, &comt); i++) {
	if (comt.com_maxbidder == player->cnum &&
	    comt.com_owner != 0 && comt.com_owner != player->cnum) {
	    tally += (comt.com_price * comt.com_amount) * buytax;
	}
    }
    canspend = natp->nat_money - tally;

    /* Find the destination sector for the trade */
    if (((trade.trd_type == EF_PLANE) && !pln_is_in_orbit(&tg.plane))
	|| (trade.trd_type == EF_NUKE)) {
	while (1) {
	    p = getstring("Destination sector: ", buf);
	    if (!trade_check_ok(&trade, &tg.gen))
		return RET_FAIL;
	    if (!p) {
		return RET_FAIL;
	    }
	    if (!sarg_xy(p, &sx, &sy) || !getsect(sx, sy, &sect)) {
		pr("Bad sector designation; try again!\n");
		continue;
	    }
	    if (!player->owner) {
		pr("You don't own that sector; try again!\n");
		continue;
	    }
	    if (!(plchr[tg.plane.pln_type].pl_flags & P_V)) {
		if (!player->god && (sect.sct_type != SCT_AIRPT)) {
		    pr("Destination sector is not an airfield!\n");
		    continue;
		}
		if (!player->god && (sect.sct_effic < 60)) {
		    pr("That airport still under construction!\n");
		    continue;
		}
	    }
	    break;
	}
    } else if (trade.trd_type == EF_LAND) {
	while (1) {
	    p = getstring("Destination sector: ", buf);
	    if (!trade_check_ok(&trade, &tg.gen))
		return RET_FAIL;
	    if (!p) {
		return RET_FAIL;
	    }
	    if (!sarg_xy(p, &sx, &sy) || !getsect(sx, sy, &sect)) {
		pr("Bad sector designation; try again!\n");
		continue;
	    }
	    if (!player->owner) {
		pr("You don't own that sector; try again!\n");
		continue;
	    }
	    if (!player->god && (sect.sct_type != SCT_HEADQ)) {
		pr("Destination sector is not a headquarters!\n");
		continue;
	    }
	    if (!player->god && (sect.sct_effic < 60)) {
		pr("That headquarters still under construction!\n");
		continue;
	    }
	    break;
	}
    } else {
	/* This trade doesn't teleport; make destination invalid */
	sx = 1;
	sy = 0;
    }

    p = getstring("How much do you bid: ", buf);
    if (!p || !*p)
	return RET_OK;
    if (!trade_check_ok(&trade, &tg.gen))
	return RET_FAIL;
    bid = atoi(p);
    if (bid < price)
	bid = price;
    if (bid > canspend) {
	pr("You don't have %.2f to spend!\n", price);
	return RET_OK;
    }
    if (bid > trade.trd_price) {
	time(&now);
	if (trade.trd_markettime  + TRADE_DELAY - now < minutes(5) &&
	    trade.trd_maxbidder != player->cnum)
	    trade.trd_markettime = now + minutes(5) - TRADE_DELAY;
	trade.trd_price = bid;
	trade.trd_maxbidder = player->cnum;
	trade.trd_x = sx;
	trade.trd_y = sy;
	pr("Your bid on lot #%d is being considered.\n", lotno);
	if (!puttrade(lotno, &trade))
	    pr("Problems with the trade file.  Get help\n");
    } else
	pr("Your bid wasn't high enough (you need to bid more than someone else.)\n");

    check_trade();

    return RET_OK;
}
Ejemplo n.º 7
0
/*
 * format: buy <COMMODITY>
 *
 */
int
buy(void)
{
    struct sctstr sect;
    struct natstr *natp;
    struct comstr comm;
    struct comstr comt;
    struct trdstr tmpt;
    struct ichrstr *ip;
    int qty;
    int o, n;
    coord x, y;
    char *p;
    float bid;
    time_t now;
    double tally;
    double canspend;
    char buf[1024];

    if (!opt_MARKET) {
	pr("The market is disabled.\n");
	return RET_FAIL;
    }
    natp = getnatp(player->cnum);
    ip = whatitem(player->argp[1], "Commodity you want to buy: ");
    if (!ip)
	return RET_SYN;
    display_mark(ip->i_uid, 0);
    pr("\n");
    p = getstarg(player->argp[2], "Which lot are you bidding on: ", buf);
    if (!p)
	return RET_SYN;
    if (*p == 0)
	return RET_SYN;
    o = atoi(p);
    if (o < 0)
	return RET_SYN;
    if (!getcomm(o, &comm) || comm.com_owner == 0) {
	pr("Invalid lot number.\n");
	return RET_OK;
    }
    if (comm.com_type != ip->i_uid) {
	pr("That lot is not of the type you specified.\n");
	return RET_OK;
    }
    if (comm.com_owner == player->cnum) {
	pr("You can't bid on your own lot.\n");
	return RET_OK;
    }
    if (!(p = getstarg(player->argp[3], "How much per unit: ", buf)))
	return RET_SYN;
    bid = atof(p);
    if (bid <= 0)
	return RET_FAIL;
    if (natp->nat_money < bid * comm.com_amount * buytax) {
	pr("This purchase would cost %.2f, %.2f more than you have.\n",
	   bid * comm.com_amount * buytax,
	   bid * comm.com_amount * buytax - natp->nat_money);
	return RET_FAIL;
    }
/*  check to see if all of the bids that this player has out plus this new bid
    would make him go broke.  Ken, I ought to skin you alive for making me code
    this part up.*/
    tally = 0.0;
    for (n = 0; gettrade(n, &tmpt); n++) {
	if (tmpt.trd_maxbidder == player->cnum &&
	    tmpt.trd_unitid >= 0 && tmpt.trd_owner != player->cnum) {
	    tally += tmpt.trd_price * tradetax;
	}
    }
    for (n = 0; getcomm(n, &comt); n++) {
	if (comt.com_maxbidder == player->cnum &&
	    comt.com_owner != 0 && comt.com_owner != player->cnum) {
	    tally += comt.com_price * comt.com_amount * buytax;
	}
    }
    canspend = natp->nat_money - tally;
    check_comm_ok(&comm);
    if (bid * comm.com_amount * buytax > canspend) {
	pr("You have overextended yourself in the market\n");
	pr("You can not bid on the current items at that price.\n");
	return RET_OK;
    }
    if (!(p = getstarg(player->argp[4], "destination sector : ", buf)))
	return RET_SYN;
    if (!sarg_xy(p, &x, &y))
	return RET_SYN;
    if (!getsect(x, y, &sect)) {
	pr("Could not access sector");
	return RET_FAIL;
    }
    if ((sect.sct_type != SCT_WAREH && sect.sct_type != SCT_HARBR) ||
	sect.sct_own != player->cnum) {
	pr("The destination sector is not one of your warehouses.\n");
	return RET_FAIL;
    }
    if (sect.sct_effic < 60) {
	pr("That sector is under construction.\n");
	return RET_FAIL;
    }
    n = sect.sct_item[ip->i_uid];
    qty = comm.com_amount;
    if (qty + n > ITEM_MAX) {
	pr("That sector cannot hold %d more %s. It currently holds %d.\n",
	   qty, ip->i_name, n);
	return RET_FAIL;
    }
    if (bid * comm.com_amount > natp->nat_money) {
	pr("You don't have that much to spend!\n");
	return RET_FAIL;
    }
    if (!check_comm_ok(&comm))
	return RET_FAIL;
    if (bid > 0.04 + comm.com_price) {
	comm.com_price = bid;
	time(&now);
	if (comm.com_markettime + MARK_DELAY - now < minutes(5) &&
	    comm.com_maxbidder != player->cnum)
	    comm.com_markettime = now + minutes(5) - MARK_DELAY;
	comm.com_maxbidder = player->cnum;
	comm.com_x = x;
	comm.com_y = y;
	putcomm(o, &comm);
	pr("Your bid is being considered.\n");
    } else {
	pr("Your bid wasn't high enough (you need to bid at least $0.05 higher\n");
	pr("than the last bid.\n");
	return RET_OK;
    }

    check_market();

    return RET_OK;
}
Ejemplo n.º 8
0
int
check_market(void)
{
    struct comstr comm;
    struct sctstr *sect;
    struct natstr *natp;
    int m;
    int n;
    time_t now;
    double gain;
    double price;

    for (n = 0; getcomm(n, &comm); n++) {
	if (comm.com_maxbidder == comm.com_owner || comm.com_owner == 0)
	    continue;
	(void)time(&now);
	if (comm.com_markettime + MARK_DELAY > now)
	    continue;
	if (CANT_HAPPEN(comm.com_type <= I_NONE || comm.com_type > I_MAX))
	    continue;
	sect = getsectp(comm.com_x, comm.com_y);
	m = sect->sct_item[comm.com_type];

	price = comm.com_price * comm.com_amount * buytax;
	gain = comm.com_price * comm.com_amount;

	natp = getnatp(comm.com_maxbidder);
	if (natp->nat_money < price) {
	    nreport(comm.com_maxbidder, N_WELCH_DEAL, comm.com_owner, 1);
	    wu(0, comm.com_maxbidder,
	       "You didn't have enough cash to cover the cost.\n");
	    wu(0, comm.com_owner,
	       "Sale #%d fell through.  Goods remain on the market.\n", n);
	    comm.com_maxbidder = comm.com_owner;
	} else if (sect->sct_type != SCT_WAREH
		   && sect->sct_type != SCT_HARBR) {
	    wu(0, comm.com_maxbidder,
	       "Sector not a warehouse now, sale #%d fell though.\n", n);
	    wu(0, comm.com_owner,
	       "Sale #%d fell through.  Goods remain on the market.\n", n);
	    comm.com_maxbidder = comm.com_owner;
	} else if (m + comm.com_amount > ITEM_MAX) {
	    wu(0, comm.com_maxbidder,
	       "Warehouse full,  sale #%d fell though.\n", n);
	    wu(0, comm.com_owner,
	       "Sale #%d fell through.  Goods remain on the market.\n", n);
	    comm.com_maxbidder = comm.com_owner;
	} else {
	    sect->sct_item[comm.com_type] = m + comm.com_amount;
	    putsect(sect);
	    nreport(comm.com_owner, N_MAKE_SALE, comm.com_maxbidder, 1);
	    wu(0, comm.com_owner, "%s bought %d %s from you for $%.2f\n",
	       cname(comm.com_maxbidder), comm.com_amount,
	       ichr[comm.com_type].i_name, gain);
	    wu(0, comm.com_maxbidder,
	       "You just bought %d %s from %s for $%.2f\n",
	       comm.com_amount, ichr[comm.com_type].i_name,
	       cname(comm.com_owner), price);
	    natp->nat_money -= roundavg(price);
	    putnat(natp);
	    natp = getnatp(comm.com_owner);
	    natp->nat_money += roundavg(gain);
	    putnat(natp);
	    comm.com_owner = 0;
	}
	comm.com_owner = 0;
	putcomm(n, &comm);
    }
    return RET_OK;
}