Example #1
0
File: ruleset.cpp Project: KDE/kppp
void RuleSet::addRule(RULE r) {
  // check for a default rule
  if((r.type == 2) &&
     (r.weekday.from == 0) && (r.weekday.until == 6) &&
     (r.from == midnight()) &&
     (r.until == beforeMidnight()))
    {
      default_costs = r.costs;
      default_len = r.len;
      return;
    }

  // if from < until (i.e on (monday..friday)
  // from (21:00..05:00) use (0.2,16)
  // split it into two rules
  // ... between (21:00..23:59) use ...
  // ... between (00:00..05:00) use ...
  if(r.from > r.until) {
    RULE r1, r2;
    r1 = r;
    r2 = r;
    r1.until = beforeMidnight();
    r2.from = midnight();
    rules.resize(rules.size()+2);
    rules[rules.size()-2] = r1;
    rules[rules.size()-1] = r2;
  } else {
    rules.resize(rules.size()+1);
    rules[rules.size()-1] = r;
  }
}
QList<T> Utilities::shuffleList(const QList<T>& list)
{
    static bool init = false;
    if ( !init ) {
        QTime midnight( 0, 0, 0 );
        srand( midnight.secsTo(QTime::currentTime()) );
        init = true;
    }

    // Take pointers from input list to an array for shuffling
    uint N = list.size();
    AutoDeletedArray<const T*> deck(N);
    const T** p = deck;
    for (typename QList<T>::const_iterator i = list.begin();
         i != list.end(); ++i) {
        *p = &(*i);
        ++p;
    }

    // Shuffle the array of pointers
    for (uint i = 0; i < N; i++) {
        uint r = i + static_cast<uint>(static_cast<double>(N - i) * rand() /
                                       static_cast<double>(RAND_MAX));
        std::swap(deck[r], deck[i]);
    }

    // Create new list from the array
    QList<T> result;
    const T** const onePastLast = deck + N;
    for (p = deck; p != onePastLast; ++p)
        result.push_back(**p);

    return result;
}
Example #3
0
Man::Man(QGraphicsScene* parent, int x, int y) :
    QObject(NULL),
    AnimatedPixmapItem(parent),
    fromHelicopter(true)
{
    QFileInfo fi(QLatin1String(":image/parashoot/man*"));
    foreach (QString entry, QDir(fi.path(), fi.fileName()).entryList())
        manarray << QPixmap(fi.path() + "/" + entry);

    setSequence(manarray);
    setPos(x, y);
    setFrame(5);
    setZValue(300);
    show();

    static bool first_time = true;
    if (first_time) {
        first_time = false;
        QTime midnight(0, 0, 0);
        qsrand(midnight.secsTo(QTime::currentTime()) );
    }
    int yfallspeed = 0;
    yfallspeed = (qrand() % 3) + 1;
    setVelocity(0, yfallspeed);

    mancount++;
    dead = false;
}
void DisplayRenderer::sendDisplayData(QImage im1, QImage im2)
{
	qDebug() << "sending data for displays";
	
	PC2TB_PACKET outPacket;

	// pack tha packet:
	outPacket.magicNumber1 = MAGIC_NUMBER1;
	outPacket.magicNumber2 = MAGIC_NUMBER2;
	outPacket.packetVersion = PACKET_VERSION;
	QTime midnight(0,0);
    int time_ms = midnight.msecsTo(MainWindow::app()->getTimeBaseTime());
	uint32_t time_100us = 10*time_ms;
	outPacket.pcTime_100us = time_100us;
	
	// ALGE text
	memcpy(outPacket.algeText, algeText().toAscii().data(), ALGE_TEXT_LEN);
	
	genMatrixData(im1, 1, outPacket.matrixData1);
	genMatrixData(im2, 2, outPacket.matrixData2);
	
	outPacket.matrixDataValid=1;
	
	outPacket.cmdReceiver=COMMAND_INVALID_RECEIVER;
	outPacket.command=COMMAND_INVALID_CMD;
	
	outPacket.crc = CRC8_run((uint8_t*)(&outPacket), (uint16_t)(sizeof(PC2TB_PACKET)-1));

	QByteArray datagram;
	datagram.setRawData((char*)(&outPacket), sizeof(PC2TB_PACKET));
	
	emit sendDatagram(datagram);
}
Example #5
0
void mechanics::populate()
{
       int location[MAX_MAP_UNITS][2];
       QTime midnight(0, 0, 0);
       qsrand(midnight.secsTo(QTime::currentTime()));

       for(int i=0; i<MAX_MAP_UNITS; i++)
       {
           if( i<4)
            {
    location[i][0] = qrand() % glWidget->battleMap.cellsTall;
        location[i][1] = (qrand()% (glWidget->battleMap.cellsWide/2) );
            }
            else if (i>=4&&i<8)
            {
        location[i][0] = qrand() % glWidget->battleMap.cellsTall;
        location[i][1] = (qrand()% (glWidget->battleMap.cellsWide/2))+ (glWidget->battleMap.cellsWide/2);
               }
             else // in case we feel like populating a rock / tree
                   {
        location[i][0] = qrand() % glWidget->battleMap.cellsTall;
        location[i][1] = (qrand()% (glWidget->battleMap.cellsWide) );
                   }
               }
       glWidget->unit[0].vLocation = location[0][0];
       glWidget->unit[0].hLocation = location[0][1];


       glWidget->unit[1].vLocation = location[1][0];
       glWidget->unit[1].hLocation = location[1][1];


       glWidget->unit[2].vLocation = location[2][0];
       glWidget->unit[2].hLocation = location[2][1];


       glWidget->unit[3].vLocation = location[3][0];
       glWidget->unit[3].hLocation = location[3][1];

       glWidget->unit[4].vLocation = location[4][0];
       glWidget->unit[4].hLocation = location[4][1];


       glWidget->unit[5].vLocation = location[5][0];
       glWidget->unit[5].hLocation = location[5][1];


       glWidget->unit[6].vLocation = location[6][0];
       glWidget->unit[6].hLocation = location[6][1];


       glWidget->unit[7].vLocation = location[7][0];
       glWidget->unit[7].hLocation = location[7][1];

       glWidget->unit[8].vLocation = location[8][0];
       glWidget->unit[8].hLocation = location[8][1];

       glWidget->unit[9].vLocation = location[9][0];
       glWidget->unit[9].hLocation = location[9][1];
}
void LottoNumberPicker::on_chooseButton_clicked(void)
{
    QTime midnight(0, 0, 0);
    qsrand(randomSeedModifier + midnight.secsTo(QTime::currentTime()));

    QList <IntegerPair> numbers;

    for(int i = 1; i < 50; i++)
    {
        numbers << IntegerPair(i, qrand());
    }

    qSort(numbers);

    randomSeedModifier = numbers[0].getSortBy();

    QList <int> generatedNumbers;
    generatedNumbers << numbers[0].getNumber() << numbers[1].getNumber() << numbers[2].getNumber() <<
             numbers[3].getNumber() << numbers[4].getNumber() << numbers[5].getNumber();
    qSort(generatedNumbers);

    ui->firstNum->setText(QString::number(generatedNumbers[0]));
    ui->secondNum->setText(QString::number(generatedNumbers[1]));
    ui->thirdNum->setText(QString::number(generatedNumbers[2]));
    ui->fourthNum->setText(QString::number(generatedNumbers[3]));
    ui->fifthNum->setText(QString::number(generatedNumbers[4]));
    ui->sixthNum->setText(QString::number(generatedNumbers[5]));
}
Example #7
0
QString Serial::generateRandomCode(int lengthCode)
{
    QTime midnight(0, 0, 0);
    int seed = midnight.secsTo(QTime::currentTime());

    QString randomCode;

    QString random;

    double randNumber;

    srand(seed);
    while (randomCode.length() < lengthCode){

        randNumber = rand();

        random.setNum(randNumber);

        random = random.mid(random.length() - 1, 1);

        if (random != "0")
            randomCode += random;
    }

    return randomCode;
}
Example #8
0
bool Registry::exec(QObject *parent, QString prefix_name){

	//This function wrights regfile_image into file, then run regedit.exe and import this file.
	//Also, clean files before end

	QTime midnight(0, 0, 0);
	qsrand(midnight.secsTo(QTime::currentTime()));

	int file_name = qrand() % 10000;
	QString full_file_path = QString("%1/.config/%2/tmp/%3.reg").arg(QDir::homePath()).arg(APP_SHORT_NAME).arg(file_name);

	QFile file(full_file_path);
	file.open(QIODevice::WriteOnly);
	file.write(regfile_image.toAscii());        // write to stderr
	file.close();


    ExecObject execObj;
    execObj.cmdargs = full_file_path;
    execObj.execcmd = "regedit.exe";

    return CoreLib->runWineBinary(execObj, prefix_name, false);

	/*
	std::auto_ptr<WineBinLauncher> launcher (new WineBinLauncher(prefix_name));
	launcher->show();
	launcher->run_exec(parent, "regedit.exe", full_file_path, TRUE);

	if (launcher->exec()==QDialog::Accepted){
		return TRUE;
	} else {
		return FALSE;
	}*/

}
Example #9
0
Board::Board(int cb, QWidget*) : cube(cb)
{
	grid = new QGridLayout(this);
	grid->setHorizontalSpacing(1);
	grid->setVerticalSpacing(1);
	grid->setContentsMargins(2, 2, 2, 2);

	QTime midnight(0, 0, 0);
	srand(midnight.secsTo(QTime::currentTime()));

	bool oddBoard = (cube%2 == 1);

	int n;

	do
	{
		numbers.clear();

		for(int i = 0; i < size(); i++)
		{ // random numbers from
			do n = rand() % size() + 1; // add 1, mod returns in range (0, size()-1)
			while(numbers.contains(n));
			numbers << n;
		}

		n = 0;

		// check for which path-row is this random placement solvable
		for(int i = 2; i <= size(); i++)
		for(int j = 0; j < numbers.indexOf(i); j++)
		{
			if(numbers[j] < i)
			{
				++n;
			}
		}
	// if this is oddBoard, we need "n" to be even
	} while(oddBoard ? n%2 == 1 : false);

	/* generate a random even or odd row position of the initial path, depending on "n"
	if this is oddBoard, just skip the checks (it doesn't matter) */
	do path.setY(rand() % cube);
	while(oddBoard ? false : n%2 != path.y()%2);

	path.setX(rand() % cube);

	n = 0;

	for(int y = 0; y < cube; ++y) // row
	for(int x = 0; x < cube; ++x) // column
	{
		if(path.x() == x && path.y() == y)
			continue;

		createButton(NULL, numbers[n++], x, y);
	}

	setLayout(grid);
}
Example #10
0
QUrl FooPlaylist::getRandomTrack()
{
	QTime midnight(0, 0, 0);
	qsrand(midnight.secsTo(QTime::currentTime()));

	currentTrackIndex = qrand() % playlist.size();

	return playlist.at(currentTrackIndex).file();
}
Example #11
0
void Man::setInitialCoords()
{
    static bool first_time = true;
    if (first_time) {
        first_time = false;
        QTime midnight(0, 0, 0);
        qsrand(midnight.secsTo(QTime::currentTime()) );
    }
    dx = qrand() % int(scene()->width()-16);
    dy = -43;  //height of a man off the screen
}
Example #12
0
Table::Table(QWidget *parent): QDialog(parent) {
  b.x = width() / 2;
  b.y = height() / 2;
  b.rx = 20;
  b.ry = 20;
  QTime midnight(0, 0, 0);
  qsrand(midnight.secsTo(QTime::currentTime()));
  b.dx = qrand() % 16 - 8;
  b.dy = qrand() % 16 - 8;
  startTimer(25);
}
Example #13
0
void  CannonField::newTarget()
{
    static bool first_time = TRUE;
    if ( first_time ) {
	first_time = FALSE;
	QTime midnight( 0, 0, 0 );
	srand( midnight.secsTo(QTime::currentTime()) );
    }
    QRegion r( targetRect() );
    target = QPoint( 200 + rand() % 190,
		     10  + rand() % 255 );
    repaint( r.unite( targetRect() ) );
}
Example #14
0
void CannonField::newTarget()
{
  static bool firstTime = true;
  if (firstTime)
  {
    firstTime = false;
    QTime midnight(0, 0, 0);
    qsrand(midnight.secsTo(QTime::currentTime()));
  }
  target = QPoint(200 + qrand() % 190, 10 + qrand() % 255);
  update();
  return;
}
Example #15
0
int main(int argc, char* argv[])
{
    QApplication app(argc, argv);
    TopWindow window;

    QTime midnight(0, 0, 0);
    qsrand(midnight.secsTo(QTime::currentTime()));

    window.setAlgorithm(new Johnson());
    window.setWindowTitle(QString::fromUtf8("MPD - projekt 1"));
    window.setMinimumSize(640, 400);
    window.show();
    return app.exec();
}
Example #16
0
File: ruleset.cpp Project: KDE/kppp
bool RuleSet::parseTime(QTime &t1, QTime &t2, QString s) {
  if(s.isEmpty()) {
    t1 = midnight();
    t2 = beforeMidnight();
    return true;
  } else {
    int t1m, t1h, t2m, t2h;
    if(sscanf(s.toAscii(), "%d:%d..%d:%d", &t1h, &t1m, &t2h, &t2m) == 4) {
      t1.setHMS(t1h, t1m, 0);
      t2.setHMS(t2h, t2m, 0);
      return true;
    } else
      return false;
  }
}
Example #17
0
void MCWorld::random() {
	rides.clear();
	QTime midnight(0, 0, 0);
	//pd the rand function does not work on Windows, look on this later
	#ifdef Q_OS_WIN32
	//bla something here
	#else
		srand(midnight.secsTo(QTime::currentTime()));
		for(int i = 0; i < allObjects.size(); i++) {
			allObjects[i]->unsetDestination();
			Speed newSpeed(rand() % 600 - 300, rand() % 600 - 300, 0);
			allObjects[i]->setSpeed(newSpeed);
		}
	#endif
}
Example #18
0
time_t
addTimeToDate(time_t day, time_t hour)
{
    day = midnight(day);
    const struct tm* tms = clocaltime(&day);

    struct tm tmc;
    memcpy(&tmc, tms, sizeof(struct tm));

    tmc.tm_hour = hour / (60 * 60);
    tmc.tm_min = (hour / 60) % 60;
    tmc.tm_sec = hour % 60;

    tmc.tm_isdst = -1;
    return mktime(&tmc);
}
Example #19
0
void f(Date& d)
{
    Date Ivb_day(16, Month::dec, d.year());

    if (d.day == 29 && d.month() == Month::feb) {

    }

    if (midnight()) d.add_day(1);

    cout << "day after: " << d + 1 << '\n';

    Date dd;
    cin >> dd;
    if (dd==d) cout << "Hurray!\n";
}
Example #20
0
//==============================================================================
GameServer::GameServer()
  : levelMap_(64, 64)
{
  QTime midnight(0, 0, 0);
  qsrand(midnight.secsTo(QTime::currentTime()));

  timer_ = new QTimer(this);
  connect(timer_
          , &QTimer::timeout
          , this
          , &GameServer::tick);
  timer_->setInterval(1000.0f / static_cast<float>(ticksPerSecond_));

  GenRandSmoothMap(levelMap_);
  levelMap_.ExportToImage("generated-level-map.png");
  LoadLevelFromImage_("generated-level-map.png");
}
Example #21
0
void MainWindow::connect_clicked()
{
    ui->actionConnect->setEnabled(false);
    ui->actionDisconnect->setEnabled(true);
    m_connected_clicked = true;
    //TODO: Чтение из гуи
    m_server_address = QHostAddress::LocalHost;
    m_server_port = 10000;

    QTime midnight(0,0,0);
    qsrand(midnight.secsTo(QTime::currentTime()));
    QString nickname = "User" + QString::number(qrand() % 10000);

    set_nickname(nickname);
    try_to_connect(m_server_address, m_server_port);
    QTimer *timer = new QTimer(this);
    QObject::connect(timer, SIGNAL(timeout()), this, SLOT(repeat_connect()));
    timer->start(2000);
}
Example #22
0
void MainWindow::updateInform() {
    erase();
    libtorrent::torrent_status status = main->torrent->status();
    libtorrent::torrent_info info = main->torrent->get_torrent_info();
    printw("%s", standartText.constData());
    printw("%d of %d peers connected; %d of %d MB downloaded;\nprogress - %d%% d - %dKB/s; u - %dKB/s\n",
           status.num_connections, status.list_seeds + status.list_peers, int((info.total_size() / 1000000) * status.progress),
           info.total_size() / 1000000, int(status.progress * 100), status.download_rate / 1000, status.upload_rate / 1000);

    if (midnight())
        main->lastAskTime = NULL;
    if (main->lastAskTime != NULL)
        printw("Last ask - piece №%d, %ss ago\n", main->lastAsk, (QTime::currentTime() - *main->lastAskTime).toString("HH:mm:ss").toLocal8Bit().constData());
    std::vector<partial_piece_info> inf;
    main->torrent->get_download_queue(inf);
    if (inf.size() > 0)
        for (unsigned int i = 0; i < inf.size(); i++)
            printw("(%d, speed-%d) ", inf[i].piece_index, inf[i].piece_state);
    refresh();\
}
Example #23
0
/**
 * @brief DatabaseSendTask::validateTask
 * @param dateTime
 * @return
 */
bool DatabaseSendTask::validateTask(const QDateTime& dateTime)
{
    valid = false;

    if(false == busy)
    {
        QTime       midnight(0, 0, 0, 0);

        if(dateTime.time() == midnight)
        {
            if(HOURS_23 <= previousDateTime.secsTo(dateTime))
            {
                debugMessageThread("Task validated");
                valid = true;
                previousDateTime = dateTime;
            }
        }
    }

    return valid;
}
Example #24
0
GLWidget::GLWidget(QWidget *parent)
    : QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
{
    QTime midnight(0, 0, 0);
    qsrand(midnight.secsTo(QTime::currentTime()));

    object = 0;
    xRot = 0;
    yRot = 0;
    zRot = 0;
    scale = 0.1f;
    xTrans=yTrans=0.0;
    trolltechGreen = QColor::fromCmykF(0.40, 0.0, 1.0, 0.0);
    trolltechPurple = QColor::fromCmykF(0.39, 0.39, 0.0, 0.0);

    animationTimer.setSingleShot(false);
    connect(&animationTimer, SIGNAL(timeout()), this, SLOT(animate()));
    animationTimer.start(10);

    setAutoFillBackground(false);
}
Example #25
0
//! [0]
GLWidget::GLWidget(QWidget *parent)
    : QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
{
    QTime midnight(0, 0, 0);
    qsrand(midnight.secsTo(QTime::currentTime()));

    logo = 0;
    xRot = 0;
    yRot = 0;
    zRot = 0;

    qtGreen = QColor::fromCmykF(0.40, 0.0, 1.0, 0.0);
    qtPurple = QColor::fromCmykF(0.39, 0.39, 0.0, 0.0);

    animationTimer.setSingleShot(false);
    connect(&animationTimer, SIGNAL(timeout()), this, SLOT(animate()));
    animationTimer.start(25);

    setAutoFillBackground(false);
    setMinimumSize(200, 200);
    setWindowTitle(tr("Overpainting a Scene"));
}
Example #26
0
void compute_times()
{
	struct sched_entry *s;
	struct time_entry *t;
	time_count = 0;
	int i;
	time_t now = time();

	if (now < SANE_TIME) return;

	for (i = config.sched_count, s = config.scheds, t = times;
			i > 0;
			i--, s++)
	{
		time_t ontime = s->start;
		if (ontime == 0) ontime = now;
		ontime = midnight(ontime) + s->time;

		int failsafe = 0;
		while(ontime <= now || (dow(ontime) & s->dow) == 0 )
		{
			ontime += 86400 * s->repeat;
			failsafe++;
			if (failsafe > 100) break;
		}

		if (failsafe < 101)	if (ontime < s->end || s->end == 0)
		{
			t->ontime = ontime;
			t->duration = s->duration;
			t->zone = s->zone;
			os_printf("computed zone %d time %d (%d from now) duration %d\n",
					t->zone, t->ontime, (t->ontime - time()), t->duration);
			t++;
			time_count++;
		}
	}
}
void QMultipartHttpRequest::generateBoundary()
{
    bool binarySafe;
    QVector<requestElement>::iterator el;

    QTime midnight(0, 0, 0);
    qsrand(midnight.secsTo(QTime::currentTime()));

    do {
        boundary = QString::number(qrand());

        binarySafe = true;

        for(el = elements.begin(); el != elements.end(); el++)
        {
            if((*el).elementData.indexOf(boundary) >= 0)
            {
                binarySafe = false;
                break;
            }
        }
    } while (!binarySafe);
}
Example #28
0
static int
domonnoise(struct monst *mtmp)
{
    const char *pline_msg = 0,  /* Monnam(mtmp) will be prepended */
        *verbl_msg = 0; /* verbalize() */
    const struct permonst *ptr = mtmp->data;

    /* presumably nearness checks have already been made */
    if (!canhear())
        return 0;
    if (is_silent(ptr))
        return 0;

    /* Make sure its your role's quest quardian; adjust if not */
    if (ptr->msound == MS_GUARDIAN && ptr != &pm_guardian) {
        int mndx = monsndx(ptr);

        ptr = &mons[genus(mndx, 1)];
    }

    /* be sure to do this before talking; the monster might teleport away, in
       which case we want to check its pre-teleport position */
    if (!canspotmon(mtmp))
        map_invisible(mtmp->mx, mtmp->my);

    switch (ptr->msound) {
    case MS_ORACLE:
        return doconsult(mtmp);
    case MS_PRIEST:
        priest_talk(mtmp);
        break;
    case MS_LEADER:
    case MS_NEMESIS:
    case MS_GUARDIAN:
        quest_chat(mtmp);
        break;
    case MS_SELL:      /* pitch, pay, total */
        shk_chat(mtmp);
        break;
    case MS_VAMPIRE:
        {
            /* vampire messages are varied by tameness, peacefulness, and time
               of night */
            boolean isnight = night();
            boolean kindred = (Upolyd &&
                               (u.umonnum == PM_VAMPIRE ||
                                u.umonnum == PM_VAMPIRE_LORD));
            boolean nightchild = (Upolyd &&
                                  (u.umonnum == PM_WOLF ||
                                   u.umonnum == PM_WINTER_WOLF ||
                                   u.umonnum == PM_WINTER_WOLF_CUB));
            const char *racenoun = (u.ufemale &&
                                    urace.individual.f) ? urace.
                individual.f : (urace.individual.m) ? urace.individual.
                m : urace.noun;

            if (mtmp->mtame) {
                if (kindred)
                    verbl_msg = msgprintf("Good %s to you Master%s",
                                          isnight ? "evening" : "day",
                                          isnight ? "!" :
                                          ".  Why do we not rest?");
                else
                    verbl_msg = msgcat(
                        nightchild ? "Child of the night, " : "",
                        midnight()? "I can stand this craving no longer!" :
                        isnight ?
                        "I beg you, help me satisfy this growing craving!" :
                        "I find myself growing a little weary.");
            } else if (mtmp->mpeaceful) {
                if (kindred && isnight)
                    verbl_msg = msgprintf("Good feeding %s!",
                                          u.ufemale ? "sister" : "brother");
                else if (nightchild && isnight)
                    verbl_msg = "How nice to hear you, child of the night!";
                else
                    verbl_msg = "I only drink... potions.";
            } else {
                int vampindex;

                static const char *const vampmsg[] = {
                    /* These first two (0 and 1) are specially handled below */
                    "I vant to suck your %s!",
                    "I vill come after %s without regret!",
                    /* other famous vampire quotes can follow here if desired */
                };
                if (kindred)
                    verbl_msg =
                        "This is my hunting ground that you dare to prowl!";
                else if (youmonst.data == &mons[PM_SILVER_DRAGON] ||
                         youmonst.data == &mons[PM_BABY_SILVER_DRAGON]) {
                    /* Silver dragons are silver in color, not made of silver */
                    verbl_msg = msgprintf(
                        "%s! Your silver sheen does not frighten me!",
                        youmonst.data ==
                        &mons[PM_SILVER_DRAGON] ? "Fool" : "Young Fool");
                } else {
                    vampindex = rn2(SIZE(vampmsg));
                    if (vampindex == 0) {
                        verbl_msg = msgprintf(
                            vampmsg[vampindex], body_part(BLOOD));
                    } else if (vampindex == 1) {
                        verbl_msg = msgprintf(
                            vampmsg[vampindex],
                            Upolyd ? an(mons[u.umonnum].mname) : an(racenoun));
                    } else
                        verbl_msg = vampmsg[vampindex];
                }
            }
        }
        break;
    case MS_WERE:
        if (flags.moonphase == FULL_MOON && (night() ^ !rn2(13))) {
            pline("%s throws back %s head and lets out a blood curdling %s!",
                  Monnam(mtmp), mhis(mtmp),
                  ptr == &mons[PM_HUMAN_WERERAT] ? "shriek" : "howl");
            wake_nearto(mtmp->mx, mtmp->my, 11 * 11);
        } else
            pline_msg =
                "whispers inaudibly.  All you can make out is \"moon\".";
        break;
    case MS_BARK:
        if (flags.moonphase == FULL_MOON && night()) {
            pline_msg = "howls.";
        } else if (mtmp->mpeaceful) {
            if (mtmp->mtame &&
                (mtmp->mconf || mtmp->mflee || mtmp->mtrapped ||
                 moves > EDOG(mtmp)->hungrytime || mtmp->mtame < 5))
                pline_msg = "whines.";
            else if (mtmp->mtame && EDOG(mtmp)->hungrytime > moves + 1000)
                pline_msg = "yips.";
            else {
                if (mtmp->data == &mons[PM_FOX])
                    pline_msg = whatthefoxsays();
                else if (mtmp->data != &mons[PM_DINGO])  /* dingos do not
                                                           actually bark */
                    pline_msg = "barks.";
            }
        } else {
            if (mtmp->data == &mons[PM_FOX])
                pline_msg = whatthefoxsays();
            else
                pline_msg = "growls.";
        }
        break;
    case MS_MEW:
        if (mtmp->mtame) {
            if (mtmp->mconf || mtmp->mflee || mtmp->mtrapped || mtmp->mtame < 5)
                pline_msg = "yowls.";
            else if (moves > EDOG(mtmp)->hungrytime)
                pline_msg = "meows.";
            else if (EDOG(mtmp)->hungrytime > moves + 1000)
                pline_msg = "purrs.";
            else
                pline_msg = "mews.";
            break;
        }       /* else FALLTHRU */
    case MS_GROWL:
        pline_msg = mtmp->mpeaceful ? "snarls." : "growls!";
        break;
    case MS_ROAR:
        pline_msg = mtmp->mpeaceful ? "snarls." : "roars!";
        break;
    case MS_SQEEK:
        pline_msg = "squeaks.";
        break;
    case MS_SQAWK:
        if (ptr == &mons[PM_RAVEN] && !mtmp->mpeaceful)
            verbl_msg = "Nevermore!";
        else
            pline_msg = "squawks.";
        break;
    case MS_HISS:
        if (!mtmp->mpeaceful)
            pline_msg = "hisses!";
        else
            return 0;   /* no sound */
        break;
    case MS_BUZZ:
        pline_msg = mtmp->mpeaceful ? "drones." : "buzzes angrily.";
        break;
    case MS_GRUNT:
        pline_msg = "grunts.";
        break;
    case MS_NEIGH:
        if (mtmp->mtame < 5)
            pline_msg = "neighs.";
        else if (moves > EDOG(mtmp)->hungrytime)
            pline_msg = "whinnies.";
        else
            pline_msg = "whickers.";
        break;
    case MS_WAIL:
        pline_msg = "wails mournfully.";
        break;
    case MS_GURGLE:
        pline_msg = "gurgles.";
        break;
    case MS_BURBLE:
        pline_msg = "burbles.";
        break;
    case MS_SHRIEK:
        pline_msg = "shrieks.";
        aggravate();
        break;
    case MS_IMITATE:
        pline_msg = "imitates you.";
        break;
    case MS_BONES:
        pline("%s rattles noisily.", Monnam(mtmp));
        pline("You freeze for a moment.");
        helpless(2, hr_afraid, "scared by rattling", NULL);
        break;
    case MS_LAUGH:
        {
            static const char *const laugh_msg[4] = {
                "giggles.", "chuckles.", "snickers.", "laughs.",
            };
            pline_msg = laugh_msg[rn2(4)];
        }
        break;
    case MS_MUMBLE:
        pline_msg = "mumbles incomprehensibly.";
        break;
    case MS_WISHGIVER:
        if (mtmp->mtame) {
            verbl_msg = "Sorry, I'm all out of wishes.";
        } else if (mtmp->mpeaceful) {
            if (ptr == &mons[PM_WATER_DEMON])
                pline_msg = "gurgles.";
            else
                verbl_msg = "I'm free!";
        } else
            verbl_msg = "This will teach you not to disturb me!";
        break;
    case MS_BOAST:     /* giants */
        if (!mtmp->mpeaceful) {
            switch (rn2(4)) {
            case 0:
                pline("%s boasts about %s gem collection.", Monnam(mtmp),
                      mhis(mtmp));
                break;
            case 1:
                pline_msg = "complains about a diet of mutton.";
                break;
            default:
                pline_msg = "shouts \"Fee Fie Foe Foo!\" and guffaws.";
                wake_nearto(mtmp->mx, mtmp->my, 7 * 7);
                break;
            }
            break;
        }
        /* else FALLTHRU */
    case MS_HUMANOID:
        if (!mtmp->mpeaceful) {
            if (In_endgame(&u.uz) && is_mplayer(ptr)) {
                mplayer_talk(mtmp);
                break;
            } else
                return 0;       /* no sound */
        }
        /* Generic peaceful humanoid behaviour. */
        if (mtmp->mflee)
            pline_msg = "wants nothing to do with you.";
        else if (mtmp->mhp < mtmp->mhpmax / 4)
            pline_msg = "moans.";
        else if (mtmp->mconf || mtmp->mstun)
            verbl_msg = !rn2(3) ? "Huh?" : rn2(2) ? "What?" : "Eh?";
        else if (!mtmp->mcansee)
            verbl_msg = "I can't see!";
        else if (mtmp->mtrapped) {
            struct trap *t = t_at(level, mtmp->mx, mtmp->my);

            if (t)
                t->tseen = 1;
            verbl_msg = "I'm trapped!";
        } else if (mtmp->mhp < mtmp->mhpmax / 2)
            pline_msg = "asks for a potion of healing.";
        else if (mtmp->mtame && !mtmp->isminion &&
                 moves > EDOG(mtmp)->hungrytime)
            verbl_msg = "I'm hungry.";
        /* Specific monsters' interests */
        else if (is_elf(ptr))
            pline_msg = "curses orcs.";
        else if (is_dwarf(ptr))
            pline_msg = "talks about mining.";
        else if (likes_magic(ptr))
            pline_msg = "talks about spellcraft.";
        else if (ptr->mlet == S_CENTAUR)
            pline_msg = "discusses hunting.";
        else
            switch (monsndx(ptr)) {
            case PM_HOBBIT:
                pline_msg =
                    (mtmp->mhpmax - mtmp->mhp >=
                     10) ? "complains about unpleasant dungeon conditions." :
                    "asks you about the One Ring.";
                break;
            case PM_ARCHEOLOGIST:
                pline_msg =
                    "describes a recent article in \"Spelunker Today\" "
                    "magazine.";
                break;
            case PM_TOURIST:
                verbl_msg = "Aloha.";
                break;
            case PM_PRISONER:
                verbl_msg = "Thank you for freeing me!";
                break;
            default:
                pline_msg = "discusses dungeon exploration.";
                break;
            }
        break;
    case MS_SEDUCE:
        if (ptr->mlet != S_NYMPH && flags.seduce_enabled &&
            could_seduce(mtmp, &youmonst, NULL) == 1) {
            doseduce(mtmp);
            break;
        }

        switch ((poly_gender() != (int)mtmp->female) ? rn2(3) : 0) {
        case 2:
            verbl_msg = "Hello, sailor.";
            break;
        case 1:
            pline_msg = "comes on to you.";
            break;
        default:
            pline_msg = "cajoles you.";
        }
        break;
    case MS_ARREST:
        if (mtmp->mpeaceful)
            verbalize("Just the facts, %s.", u.ufemale ? "Ma'am" : "Sir");
        else {
            static const char *const arrest_msg[3] = {
                "Anything you say can be used against you.",
                "You're under arrest!",
                "Stop in the name of the Law!",
            };
            verbl_msg = arrest_msg[rn2(3)];
        }
        break;
    case MS_BRIBE:
        if (mtmp->mpeaceful && !mtmp->mtame) {
            demon_talk(mtmp);
            break;
        }
        /* fall through */
    case MS_CUSS:
        if (!mtmp->mpeaceful)
            cuss(mtmp);
        break;
    case MS_SPELL:
        /* deliberately vague, since it's not actually casting any spell */
        pline_msg = "seems to mutter a cantrip.";
        break;
    case MS_NURSE:
        if (uwep && (uwep->oclass == WEAPON_CLASS || is_weptool(uwep)))
            verbl_msg = "Put that weapon away before you hurt someone!";
        else if (uarmc || (uarm && !uskin()) ||
                 uarmh || uarms || uarmg || uarmf)
            verbl_msg =
                Role_if(PM_HEALER) ?
                "Doc, I can't help you unless you cooperate." :
                "Please undress so I can examine you.";
        else if (uarmu)
            verbl_msg = "Take off your shirt, please.";
        else
            verbl_msg = "Relax, this won't hurt a bit.";
        break;
    case MS_GUARD:
        if (money_cnt(invent))
            verbl_msg = "Please drop that gold and follow me.";
        else
            verbl_msg = "Please follow me.";
        break;
    case MS_SOLDIER:
        {
            static const char *const soldier_foe_msg[3] = {
                "Resistance is useless!",
                "You're dog meat!",
                "Surrender!",
            }, *const soldier_pax_msg[3] = {
                "What lousy pay we're getting here!",
                "The food's not fit for Orcs!",
                "My feet hurt, I've been on them all day!",
            };
            verbl_msg = mtmp->mpeaceful ? soldier_pax_msg[rn2(3)]
                : soldier_foe_msg[rn2(3)];
        }
        break;
    case MS_RIDER:
        if (ptr == &mons[PM_DEATH] && !rn2(10))
            pline_msg = "is busy reading a copy of Sandman #8.";
        else
            verbl_msg = "Who do you think you are, War?";
        break;
    }

    if (pline_msg)
        pline("%s %s", Monnam(mtmp), pline_msg);
    else if (verbl_msg)
        verbalize("%s", verbl_msg);
    return 1;
}
Example #29
0
int
inshop(void)
{
	int roomno = inroom(u.ux, u.uy);

	/* Did we just leave a shop? */
	if (u.uinshop &&
	    (u.uinshop != roomno + 1 || shlevel != dlevel || !shopkeeper)) {
		if (shopkeeper) {
			if (ESHK(shopkeeper)->billct) {
				if (inroom(shopkeeper->mx, shopkeeper->my)
				    == u.uinshop - 1)	/* ab@unido */
					pline("Somehow you escaped the shop without paying!");
				addupbill();
				pline("You stole for a total worth of %ld zorkmids.",
				    total);
				ESHK(shopkeeper)->robbed += total;
				setpaid();
				if ((rooms[ESHK(shopkeeper)->shoproom].rtype == GENERAL)
				    == (rn2(3) == 0))
					ESHK(shopkeeper)->following = 1;
			}
			shopkeeper = NULL;
			shlevel = 0;
		}
		u.uinshop = 0;
	}

	/* Did we just enter a zoo of some kind? */
	if (roomno >= 0) {
		int rt = rooms[roomno].rtype;
		struct monst *mtmp;
		if (rt == ZOO)
			pline("Welcome to David's treasure zoo!");
		else if (rt == SWAMP)
			pline("It looks rather muddy down here.");
		else if (rt == MORGUE) {
			if (midnight())
				pline("Go away! Go away!");
			else
				pline("You get an uncanny feeling ...");
		} else
			rt = 0;
		if (rt != 0) {
			rooms[roomno].rtype = 0;
			for (mtmp = fmon; mtmp; mtmp = mtmp->nmon)
				if (rt != ZOO || !rn2(3))
					mtmp->msleep = 0;
		}
	}

	/* Did we just enter a shop? */
	if (roomno >= 0 && rooms[roomno].rtype >= 8) {
		if (shlevel != dlevel || !shopkeeper
		    || ESHK(shopkeeper)->shoproom != roomno)
			findshk(roomno);
		if (!shopkeeper) {
			rooms[roomno].rtype = 0;
			u.uinshop = 0;
		} else if (!u.uinshop) {
			if (!ESHK(shopkeeper)->visitct ||
			    strncmp(ESHK(shopkeeper)->customer, plname, PL_NSIZ)) {
				/* He seems to be new here */
				ESHK(shopkeeper)->visitct = 0;
				ESHK(shopkeeper)->following = 0;
				strncpy(ESHK(shopkeeper)->customer, plname, PL_NSIZ);
				NOTANGRY(shopkeeper) = 1;
			}
			if (!ESHK(shopkeeper)->following) {
				boolean box, pick;

				pline("Hello %s! Welcome%s to %s's %s shop!",
				      plname,
				      ESHK(shopkeeper)->visitct++ ? " again" : "",
				      shkname(shopkeeper),
				      shopnam[rooms[ESHK(shopkeeper)->shoproom].rtype - 8]);
				box = carrying(ICE_BOX);
				pick = carrying(PICK_AXE);
				if (box || pick) {
					if (dochug(shopkeeper)) {
						u.uinshop = 0;	/* he died moving */
						return (0);
					}
					pline("Will you please leave your %s outside?",
					    (box && pick) ? "box and pick-axe" :
					    box ? "box" : "pick-axe");
				}
			}
			u.uinshop = roomno + 1;
		}
	}
	return (u.uinshop);
}
Example #30
0
int MainWindow::getFavoriteFwPort() {
    QTime midnight(0, 0, 0);
    qsrand(midnight.secsTo(QTime::currentTime()));

    return settings->value("pref/fw/port", qrand() % 917).toInt();
}