Exemplo n.º 1
0
static void test_minmax(void) {

    const char *llmax;
    const char *llmin;
    long long llmaxnum;
    long long llminnum;
    char *x;
    long long numlen = sizeof(long long);

    if (numlen == 16) {
        llmax   = "170141183460469231731687303715884105727";
        llmin   = "-170141183460469231731687303715884105728";
        llmaxnum = int128max();
        llminnum = -llmaxnum - 1LL;
    }
    else if (numlen == 8) {
        llmax   = "9223372036854775807";
        llmin   = "-9223372036854775808";
        llmaxnum = 9223372036854775807LL;
        llminnum = -llmaxnum - 1LL;
    }
    else {
        fail("unsupported size for 'num'");
    }

    x = numtostr(0, llmaxnum);
    if (strcmp(x, llmax)) fail("numtostr() failure");

    x = numtostr(0, llminnum);
    if (strcmp(x, llmin)) fail("numtostr() failure");
}
Exemplo n.º 2
0
static void test_bufferoverflow(void) {

    char buf[NUMTOSTR_LEN + 16];
    long long i, j;
    char ch[2] = {0x00, (char)0xff };
    long long  llmaxnum;
    long long llminnum;
    long long numlen = sizeof(long long);

    if (numlen == 16) {
        llmaxnum = int128max();
        llminnum = -llmaxnum - 1LL;
    }
    else if (numlen == 8) {
        llmaxnum = 9223372036854775807LL;
        llminnum = -llmaxnum - 1LL;
    }
    else {
        fail("unsupported size for 'num'");
    }

    if ((NUMTOSTR_LEN) < sizeof("-170141183460469231731687303715884105728")) fail("NUMTOSTR_LEN too small");

    for (j = 0; j < 2; ++j) {
        for (i = 0; i < sizeof buf; ++i) buf[i] = ch[j];
        numtostr(buf + 8, llminnum);
        for (i = 0; i < 8; ++i) if (buf[i] != ch[j]) fail("numtostr() writes before output");
        for (i = 0; i < 8; ++i) if (buf[i + NUMTOSTR_LEN + 8] != ch[j]) fail("numtostr() writes after output");
        for (i = 0; i < sizeof buf; ++i) buf[i] = ch[j];
        numtostr(buf + 8, llmaxnum);
        for (i = 0; i < 8; ++i) if (buf[i] != ch[j]) fail("numtostr() writes before output");
        for (i = 0; i < 8; ++i) if (buf[i + NUMTOSTR_LEN + 8] != ch[j]) fail("numtostr() writes after output");
    }
}
Exemplo n.º 3
0
char			*ft_itoa(int n)
{
	char		*str;
	int			size;
	long int	temp;

	size = 0;
	temp = n;
	if (n < 0)
	{
		size++;
		temp = temp * -1;
	}
	while (temp > 0)
	{
		temp = temp / 10;
		size++;
	}
	if (n == 0)
		size = 1;
	str = (char*)malloc(sizeof(char) * size + 1);
	if (!str)
		return (NULL);
	numtostr(&str, n, size);
	return (str);
}
Exemplo n.º 4
0
static void redraw_top_info(void)
{
	char buf[8];

	update_current_instrument();

	draw_text_len(song_get_basename(), 18, 12, 4, 5, 0);
	draw_text_len(current_song->title, 25, 12, 3, 5, 0);

	if ((status.flags & (CLASSIC_MODE | SONG_NEEDS_SAVE)) == SONG_NEEDS_SAVE)
		draw_char('+', 29, 4, 4, 0);

	update_current_order();
	update_current_pattern();
	update_current_row();

	draw_text(numtostr(3, song_get_current_speed(), buf), 50, 4, 5, 0);
	draw_text(numtostr(3, song_get_current_tempo(), buf), 54, 4, 5, 0);
	draw_char('0' + kbd_get_current_octave(), 50, 5, 5, 0);
}
Exemplo n.º 5
0
/** leftClick() will fire certain player abilities */
void MainWindow::leftClick()
{
	leftclickcounter++;
	if(leftclickcounter%5==0)
	{
		leftclickcounter=0;
		objects.push_back(new MysticShot(*mystic,objects.first()->getX(),objects.first()->getY(),1,0,view->getpoint().rx(),view->getpoint().ry()));
			objects.last()->setPos(objects.first()->getX(),objects.first()->getY());
			scene->addItem(objects.last());
		dispmana=numtostr(objects.first()->getMana());
		mana->setText(dispmana);
	}
	else
	{
		objects.push_back(new BasicAttack(*basic,objects.first()->getX(),objects.first()->getY(),1,0,view->getpoint().rx(),view->getpoint().ry()));
			objects.last()->setPos(objects.first()->getX(),objects.first()->getY());
			scene->addItem(objects.last());
		dispmana=numtostr(objects.first()->getMana());
		mana->setText(dispmana);
	}
}
Exemplo n.º 6
0
string sertojson(serial ser, catalog* scanlog1) {
  string ans = "", flag[5] = {"json", "array", "text", "int", "bool"};
    ans += "{";

      for (int i = 0; i < ser.count; i++) {
        catalog* scanlog = scanlog1;
        int id = ser.aid[i];

        ans += "\"";
            ans += scanlog->key_name[id-1];
          ans += "\"";
          ans += ": ";
      if ((scanlog->key_type[id-1]) == flag[0]) {
          for (int j = ser.offset[i]; j < ser.offset[i] + ser.len[i]; j++) {
              ans += ser.data[j];
          }
      }
      if ((scanlog->key_type[id-1]) == flag[1]) {
          for (int j = ser.offset[i]; j < ser.offset[i] + ser.len[i]; j++) {
              ans += ser.data[j];
        }
      }

        if ((scanlog->key_type[id-1]) == flag[2]) {
          ans += "\"";
          for (int j = ser.offset[i]; j < ser.offset[i] + ser.len[i]; j++) {
              ans += ser.data[j];
          }
          ans += "\"";
      }

      if ((scanlog->key_type[id-1]) == flag[3]) {
          for (int j = ser.offset[i]; j < ser.offset[i] + ser.len[i]; j++) {
              //ans += ser.data[j];
          int tmp = ser.data[j];
          ans += numtostr(tmp);
          }
      }
        if ((scanlog->key_type[id-1]) == flag[4]) {
          for (int j = ser.offset[i]; j < ser.offset[i] + ser.len[i]; j++) {
              if (ser.data[j] == 't') ans += "true";
              if (ser.data[j] == 'f') ans += "false";
          }
      }

          if (i != ser.count - 1) ans += ", ";

      }
    ans += "}";
    return ans;
}
Exemplo n.º 7
0
int okstatus(const char *warning, const char *what, int childstatus, struct dnszone *zone) {

    if (!WIFEXITED(childstatus)) {
        if (zone) {
            warn_7(warning, what, " for zone ", zone->fqdn2, " killed by signal ", numtostr(0, WTERMSIG(childstatus)), "\n");
        }
        else {
            warn_5(warning, what, " killed by signal ", numtostr(0, WTERMSIG(childstatus)), "\n");
        }
        return 0;
    }

    if (WEXITSTATUS(childstatus) != 0) {
        if (zone) {
            warn_7(warning, what, " for zone ", zone->fqdn2, " exited with status ", numtostr(0, WEXITSTATUS(childstatus)), "\n");
        }
        else {
            warn_5(warning, what, " exited with status ", numtostr(0, WEXITSTATUS(childstatus)), "\n");
        }
        return 0;
    }
    return 1;
}
Exemplo n.º 8
0
int main(int argc, char **argv) {

    char *x;
    long long xlen;

    if (argv[0])
        if (argv[1])
            if (str_equal(argv[1], "-h"))
                die_usage();

    x = numtostr(0, seconds());
    xlen = str_len(x);
    x[xlen] = '\n';

    if (writeall(1, x, xlen + 1) == -1) die_fatal("unable to write output", 0);
    if (fsyncfd(1) == -1) die_fatal("unable to write output", 0);
    _exit(0);
}
Exemplo n.º 9
0
int
cmd_bp(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
{
	char *opt_c = NULL;
	uint_t opt_i = FALSE;
	uint_t opt_l = FALSE;
	uint64_t opt_L = 0;
	uintptr_t opt_n = 0;
	uint_t opt_o = FALSE;
	uint_t opt_p = FALSE;
	uint_t opt_rwx = 0;
	int status = DCMD_OK;
	int id;

	if ((argv = ev_getopts(addr, flags, argc, argv, &flags, &opt_c, &opt_i,
	    &opt_l, &opt_L, &opt_n, &opt_o, &opt_p, &opt_rwx)) == NULL ||
	    opt_i || opt_o || opt_rwx != 0 || opt_l || opt_L != 0 || opt_p)
		return (DCMD_USAGE);

	while (argv->a_type != MDB_TYPE_STRING || argv->a_un.a_str != NULL) {
		if (argv->a_type == MDB_TYPE_STRING) {
			id = mdb_tgt_add_sbrkpt(mdb.m_target, argv->a_un.a_str,
			    flags, cmd_event, NULL);
		} else {
			id = mdb_tgt_add_vbrkpt(mdb.m_target, argv->a_un.a_val,
			    flags, cmd_event, NULL);
		}

		if (id == 0) {
			mdb_warn("failed to add breakpoint at %s",
			    argv->a_type == MDB_TYPE_STRING ? argv->a_un.a_str :
			    numtostr(argv->a_un.a_val, mdb.m_radix,
			    NTOS_UNSIGNED | NTOS_SHOWBASE));
			status = DCMD_ERR;

		} else if (opt_c || opt_n)
			ev_setopts(mdb.m_target, id, opt_c, opt_n);

		argv++;
	}

	return (status);
}
Exemplo n.º 10
0
char			*ft_uitoa(uintmax_t n)
{
	char		*str;
	uintmax_t	size;
	uintmax_t	temp;

	size = 0;
	temp = n;
	while (temp > 0)
	{
		temp = temp / 10;
		size++;
	}
	if (n == 0)
		size = 1;
	str = (char*)malloc(sizeof(char) * size + 1);
	if (!str)
		return (NULL);
	numtostr(&str, n, size);
	return (str);
}
Exemplo n.º 11
0
/*
 * Post-processing routine for econvert and qeconvert.  This function is
 * called by both doubletos() and longdoubletos() below.
 */
static const char *
fptos(const char *p, char *buf, size_t buflen, int decpt, int sign, char expchr)
{
	char *q = buf;

	*q++ = sign ? '-' : '+';

	/*
	 * If the initial character is not a digit, the result is a special
	 * identifier such as "NaN" or "Inf"; just copy it verbatim.
	 */
	if (*p < '0' || *p > '9') {
		(void) strncpy(q, p, buflen);
		buf[buflen - 1] = '\0';
		return (buf);
	}

	*q++ = *p++;
	*q++ = '.';

	(void) strcpy(q, p);
	q += strlen(q);
	*q++ = expchr;

	if (--decpt < 0) {
		decpt = -decpt;
		*q++ = '-';
	} else
		*q++ = '+';

	if (decpt < 10)
		*q++ = '0';

	(void) strcpy(q, numtostr((uint_t)decpt, 10, 0));
	return (buf);
}
Exemplo n.º 12
0
static void file_list_draw(void)
{
	int n, pos, fg, bg, i;
	char buf[8];
	char sbuf[32];
	dmoz_file_t *file;

	/* there's no need to have if (files) { ... } like in the load-module page,
	   because there will always be at least "/" in the list */
	if (top_file < 0) top_file = 0;
	if (current_file < 0) current_file = 0;
	for (n = top_file, pos = 13; n < flist.num_files && pos < 48; n++, pos++) {
		file = flist.files[n];

		if (n == current_file && ACTIVE_PAGE.selected_widget == 0) {
			fg = 0;
			bg = 3;
		} else {
			fg = get_type_color(file->type);
			bg = 0;
		}

		draw_text(numtostr(3, n, buf), 2, pos, 0, 2);
		draw_text_len((file->title ? file->title : ""),
						25, 6, pos, fg, bg);
		draw_char(168, 31, pos, 2, bg);
		draw_text_len((file->base ? file->base : ""),
						18, 32, pos, fg, bg);

		if (file->base && slash_search_mode > -1) {
			if (strncasecmp(file->base,slash_search_str,slash_search_mode) == 0) {
				for (i = 0 ; i < slash_search_mode; i++) {
					if (tolower(((unsigned)file->base[i]))
					!= tolower(((unsigned)slash_search_str[i]))) break;
					draw_char(file->base[i], 32+i, pos, 3,1);
				}
			}
		}

		if (file->sampsize > 1) {
			sprintf(sbuf, "%u Samples", file->sampsize);
			draw_text_len(sbuf, 10, 51, pos, fg, bg);
		} else if (file->sampsize == 1) {
			draw_text("1 Sample  ", 51, pos, fg, bg);
		} else if (file->type & TYPE_MODULE_MASK) {
			draw_text("\x9a\x9a""Module\x9a\x9a", 51, pos, fg, bg);
		} else {
			draw_text("          ", 51, pos, fg, bg);
		}
		if (file->filesize > 1048576) {
			sprintf(sbuf, "%lum", (unsigned long)(file->filesize / 1048576));
		} else if (file->filesize > 1024) {
			sprintf(sbuf, "%luk", (unsigned long)(file->filesize / 1024));
		} else if (file->filesize > 0) {
			sprintf(sbuf, "%lu", (unsigned long)(file->filesize));
		} else {
			*sbuf = 0;
		}
		draw_text_len(sbuf, 6, 62, pos, fg, bg);
	}

	/* draw the info for the current file (or directory...) */

	while (pos < 48)
		draw_char(168, 31, pos++, 2, 0);
}
Exemplo n.º 13
0
signed char cBooks::make_new_book_file(char *fileName, P_ITEM pBook)
{
	FILE *file;
	
	file = fopen( fileName, "w+b"); // create new file
	int i,maxpages;
	char ch;
	char author[33];
	char title[63];
	char line[35];
	char num[5];
	
	if (file == NULL) 
	{
		LogError("cant create new book file\n");
		return-1;
	}
	
	author[0]='.';author[1]=0;author[31]='\n';
	title[0]='.';title[1]=0;title[61]='\n';
	line[0]='.';line[1]=0;line[33]='\n';
	
	for (i=2;i<=60;i++) title[i]=32;
	for (i=2;i<=30;i++) author[i]=32;
	for (i=2;i<=32;i++) line[i]=32;
	
	if ( fwrite(&title, sizeof(char), 62, file) != 62 ) 
	{
		LogError("coudnt write to book file\n");
		return -1;
	}
	
	if ( fwrite(&author, sizeof(char), 32, file) != 32 ) 
	{
		LogError("coudnt write to book file\n");
		return -1;
	}
	
	maxpages=pBook->morey; // morey=maxpages
	if (maxpages<1 || maxpages>255) maxpages=16; // default = 16 pages
	
	numtostr(maxpages,num); // danger,danger, didnt this cause probs under LINUX ???
	// sorry, i cant test ???
	
	num[4]='\n';
	
	if ( fwrite(num, sizeof(char), 5, file) != 5 )  // writens number
	{
		LogError("coudnt write to book file\n");
		return -1;
	}
	
	for (int j=0;j<maxpages;j++) // page loop
	{
		ch='\n'; // each page gets a cr
		if ( fwrite(&ch, sizeof(char), 1, file) != 1 ) 
		{
			LogError("coudnt write to book file\n");
			return -1;
		}
		
		for (int l=0;l<8;l++) // each page has 8 lines
		{	         
			line[0]=0;
			if ( fwrite(&line, sizeof(char), 34, file) != 34 ) 
			{
				LogError("coudnt write to book file\n");
				return -1;
			}			
		}
		
	}
	
	fclose(file);
	return 0;
}
Exemplo n.º 14
0
void cChar::Serialize(ISerialization &archive)
{
	if (archive.isReading())
	{
		archive.read("name",			orgname);
		archive.read("title",			title);
		archive.read("account",			account);
		archive.read("creationday",		creationday);
		archive.read("gmmoveeff",		gmMoveEff);
		archive.read("guildtype",		GuildType);
		archive.read("guildtraitor",	GuildTraitor);
		archive.read("dispz",			dispz);
		archive.read("cell",			cell);
		archive.read("dir",				dir);
		archive.read("race",			race);
		archive.read("body",			xid);	setId(xid);
		archive.read("xbody",			xid);
		archive.read("skin",			skin);	
		archive.read("xskin",           xskin);
		archive.read("priv",			priv);
		
		archive.read("priv3a",			priv3[0]);
		archive.read("priv3b",			priv3[1]);
		archive.read("priv3c",			priv3[2]);
		archive.read("priv3d",			priv3[3]);
		archive.read("priv3e",			priv3[4]);
		archive.read("priv3f",			priv3[5]);
		archive.read("priv3g",			priv3[6]);
		// end of meta-gm save
		
		archive.read("stablemaster",	stablemaster_serial);
		archive.read("npctype",			npc_type);
		archive.read("time_unused",		time_unused);
		
		archive.read("allmove",			priv2);
		archive.read("font",			fonttype);
		archive.read("say",				saycolor);
		archive.read("emote",			emotecolor);
		archive.read("strength",		st);
		archive.read("strength2",		st2);
		archive.read("dexterity",		dx);
		archive.read("dexterity2",		dx2);
		archive.read("intelligence",	in);
		archive.read("intelligence2",	in2);
		archive.read("hitpoints",		hp);
		archive.read("spawnregion",		spawnregion);
		archive.read("stamina",			stm);
		archive.read("mana",			mn);
		archive.read("npc",				npc);
		archive.read("holdgold",		holdg);
		archive.read("shop",			shop);
		archive.read("own",				ownserial);
		archive.read("robe",			robe);
		archive.read("karma",			karma);
		archive.read("fame",			fame);
		archive.read("kills",			kills);
		archive.read("deaths",			deaths);
		archive.read("dead",			dead);
		archive.read("packitem",		packitem);
		archive.read("fixedlight",		fixedlight);
		archive.read("speech",			speech);
		archive.read("trigger",			trigger);
		archive.read("trigword",		trigword);
		archive.read("disablemsg",		disabledmsg);
		unsigned int j;
		for (j=0;j<TRUESKILLS;j++)
		{
			char t[256] = {0,};
			numtostr(j, t);
			string temp = string("skill") + string(t);
			archive.read(temp.c_str(), baseskill[j]);
			temp = string("skl") + string(t);
			archive.read(temp.c_str(), lockSkill[j] );
		}
		archive.read("cantrain", cantrain);
		
		archive.read("att",				att);
		archive.read("def",				def);
		archive.read("lodamage",		lodamage);
		archive.read("hidamage",		hidamage);
		archive.read("war",				war);
		archive.read("npcwander",		npcWander);
		archive.read("oldnpcwander",	oldnpcWander);
		archive.read("carve",			carve);
		archive.read("fx1",				fx1);
		archive.read("fy1",				fy1);
		archive.read("fz1",				fz1);
		archive.read("fx2",				fx2);
		archive.read("fy2",				fy2);
		archive.read("spawn",			spawnserial);
		archive.read("hidden",			hidden);
		archive.read("hunger",			hunger);
		archive.read("npcaitype",		npcaitype);
		archive.read("spattack",		spattack);
		archive.read("spadelay",		spadelay);
		archive.read("taming",			taming);
		archive.read("summontimer",		summontimer);
		if (summontimer != 0)
			summontimer += uiCurrentTime;
		archive.read("advobj",			advobj);
		archive.read("poison",			poison);
		archive.read("poisoned",		poisoned);
		archive.read("fleeat",			fleeat);
		archive.read("reattackat",		reattackat);
		archive.read("split",			split);
		archive.read("splitchance",		splitchnc);
		// Begin of Guild related things (DasRaetsel)
		archive.read("guildtoggle",		guildtoggle);  
		archive.read("guildstone",		guildstone);  
		archive.read("guildtitle",		guildtitle);  
		archive.read("guildfealty",		guildfealty);  
		archive.read("murderrate",		murderrate);
		archive.read("menupriv",		menupriv);  
		archive.read("questtype",		questType);  
		archive.read("questdestregion",	questDestRegion);  
		archive.read("questorigregion",	questOrigRegion);  
		archive.read("questbountypostserial", questBountyPostSerial);  
		archive.read("questbountyreward", questBountyReward);  
		archive.read("jailtimer",		jailtimer);
		if (jailtimer != 0)
			jailtimer += uiCurrentTime;
		archive.read("jailsecs",		jailsecs); 
		archive.read("gmrestrict",		gmrestrict); 
		SetOwnSerial(ownserial);
		SetSpawnSerial(spawnserial);
	}
	else if ( archive.isWritting())
	{
		if(incognito)
		{//save original name
			archive.write("name", orgname);
		} 
		else
		{
			archive.write("name", name);
		}
		
		archive.write("title",			title);
		archive.write("account",		account);
		archive.write("creationday",	creationday);
		archive.write("gmmoveeff",		gmMoveEff);
		archive.write("guildtype",		GuildType);
		archive.write("guildtraitor",	GuildTraitor);
		archive.write("dispz",			dispz);
		archive.write("cell",			cell);
		archive.write("dir",			dir);
		archive.write("race",			race);
		//AntiChrist - incognito and polymorph spell special stuff - 12/99
		if(incognito || polymorph)
		{//if under incognito spell, don't save BODY but the original XBODY
			archive.write("body", xid);
		} 
		else
		{//else backup body normally
			archive.write("body", id());
		}
		archive.write("xbody", xid);
		//AntiChrist - incognito spell special stuff - 12/99
		if(incognito)
		{//if under incognito spell, don't save SKIN but the original XSKIN
			archive.write("skin", xskin);
		} 
		else
		{//else backup skin normally
			archive.write("skin", skin);
		}
		
		archive.write("xskin",			xskin);
		archive.write("priv",			priv);
		
		archive.write("priv3a",			priv3[0]);
		archive.write("priv3b",			priv3[1]);
		archive.write("priv3c",			priv3[2]);
		archive.write("priv3d",			priv3[3]);
		archive.write("priv3e",			priv3[4]);
		archive.write("priv3f",			priv3[5]);
		archive.write("priv3g",			priv3[6]);
		// end of meta-gm save
		
		archive.write("stablemaster",	stablemaster_serial);
		archive.write("npctype",		npc_type);
		archive.write("time_unused",	time_unused);
		
		archive.write("allmove",		priv2);
		archive.write("font",			fonttype);
		archive.write("say",			saycolor);
		archive.write("emote",			emotecolor);
		archive.write("strength",		st);
		archive.write("strength2",		st2);
		archive.write("dexterity",		dx);
		archive.write("dexterity2",		dx2);
		archive.write("intelligence",	in);
		archive.write("intelligence2",	in2);
		archive.write("hitpoints",		hp);
		archive.write("spawnregion",	spawnregion);
		archive.write("stamina",		stm);
		archive.write("mana",			mn);
		archive.write("npc",			npc);
		archive.write("holdgold",		holdg);
		archive.write("shop",			shop);
		archive.write("own",			ownserial);
		archive.write("robe",			robe);
		archive.write("karma",			karma);
		archive.write("fame",			fame);
		archive.write("kills",			kills);
		archive.write("deaths",			deaths);
		archive.write("dead",			dead);
		archive.write("packitem",		packitem);
		archive.write("fixedlight",		fixedlight);
		archive.write("speech",			speech);
		archive.write("trigger",		trigger);
		archive.write("trigword",		trigword);
		archive.write("disablemsg",		disabledmsg);
		unsigned int j;
		for (j = 0; j < TRUESKILLS; ++j)
		{
			QString temp = QString("skill") + QString::number(j);
			archive.write(temp.latin1(), baseskill[j]);
			temp = QString("skl") + QString::number(j);
			archive.write(temp.latin1(), lockSkill[j] );
		}
		archive.write("cantrain", cantrain);
		
		archive.write("att",			att);
		archive.write("def",			def);
		archive.write("lodamage",		lodamage);
		archive.write("hidamage",		hidamage);
		archive.write("war",			war);
		archive.write("npcwander",		npcWander);
		archive.write("oldnpcwander",	oldnpcWander);
		archive.write("carve",			carve);
		archive.write("fx1",			fx1);
		archive.write("fy1",			fy1);
		archive.write("fz1",			fz1);
		archive.write("fx2",			fx2);
		archive.write("fy2",			fy2);
		archive.write("spawn",			spawnserial);
		archive.write("hidden",			hidden);
		archive.write("hunger",			hunger);
		archive.write("npcaitype",		npcaitype);
		archive.write("spattack",		spattack);
		archive.write("spadelay",		spadelay);
		archive.write("taming",			taming);
		archive.write("summonremainingseconds", summontimer/MY_CLOCKS_PER_SEC);
		
		archive.write("advobj",			advobj);
		archive.write("poison",			poison);
		archive.write("poisoned",		poisoned);
		archive.write("fleeat",			fleeat);
		archive.write("reattackat",		reattackat);
		archive.write("split",			split);
		archive.write("splitchance",	splitchnc);
		// Begin of Guild related things (DasRaetsel)
		archive.write("guildtoggle",	guildtoggle);  
		archive.write("guildnumber",	guildstone);  
		archive.write("guildtitle",		guildtitle);  
		archive.write("guildfealty",	guildfealty);  
		archive.write("murderrate",		murderrate);
		archive.write("menupriv",		menupriv);  
		archive.write("questtype",		questType);  
		archive.write("questdestregion",questDestRegion);  
		archive.write("questorigregion",questOrigRegion);  
		archive.write("questbountypostserial", questBountyPostSerial);  
		archive.write("questbountyreward", questBountyReward);  
		archive.write("jailtimer",		jailtimer/MY_CLOCKS_PER_SEC); 
		archive.write("jailsecs",		jailsecs); 
		archive.write("gmrestrict",		gmrestrict); 
	}
	cUObject::Serialize(archive);
}
Exemplo n.º 15
0
/** handleTimer() reacts to the signal sent off by the timer*/
void MainWindow::handleTimer()
{
  if(inGame && !gamePaused && playerAlive)
  {
/*TRUESHOT*/
	if(trueshotfiring)
	{
		leftclickholdcounter++;
		if(leftclickholdcounter%25==0){
			objects.push_back(new TrueShot(*trueshot,objects.first()->getX(),objects.first()->getY(),1000,0,view->getpoint().rx(),view->getpoint().ry()));
			objects.last()->setPos(objects.first()->getX(),objects.first()->getY());
			scene->addItem(objects.last());
			dispmana=numtostr(objects.first()->getMana());
			mana->setText(dispmana);
			trueshotfiring=false;
			leftclickholdcounter=0;
		}
	}
/* MOVING EZ*/
	if(up)
	{
		objects.first()->movetile(objects.first()->getX(),objects.first()->getY()-20);
	}
	else if(down)
	{
		objects.first()->movetile(objects.first()->getX(),objects.first()->getY()+20);
	}
	if(left)
	{
		objects.first()->movetile(objects.first()->getX()-20,objects.first()->getY());
	}
	else if(right)
	{
		objects.first()->movetile(objects.first()->getX()+20,objects.first()->getY());
	}
/* Spawn Icon*/
	iconspawn++;
	if(iconspawn%200==0)
	{
		int temp=rand()%3;
		if(temp==0)
		{
			int objectx,objecty;
			objectx=rand()%1175;objecty=rand()%575;
			objects.push_back(new Heal(*heal,objectx,objecty,1,0));
			objects.last()->setPos(objectx,objecty);
			scene->addItem(objects.last());
			iconspawn=0;
		}
		else if(temp==1)
		{
			int objectx,objecty;
			objectx=rand()%1175;objecty=rand()%575;
			objects.push_back(new Clarity(*clarity,objectx,objecty,1,0));
			objects.last()->setPos(objectx,objecty);
			scene->addItem(objects.last());
			iconspawn=0;
		}
		else if(temp==2)
		{
			int objectx,objecty;
			objectx=rand()%1175;objecty=rand()%575;
			objects.push_back(new Ignite(*ignite,objectx,objecty,1,0));
			objects.last()->setPos(objectx,objecty);
			scene->addItem(objects.last());
			iconspawn=0;
		}
	}
/* Spawning melee*/
	spawnmelee++;
	if(spawnmelee%50==0)
	{
		int objectx,objecty;
		objectx=rand()%1175;objecty=rand()%575;
		objects.push_back(new MeleeMinion(*melee,objectx,objecty,75,50));
		objects.last()->setPos(objectx,objecty);
		scene->addItem(objects.last());
		spawnmelee=0;
	}
	for( int i=0;i<objects.size();i++)
	{
		if(objects[i]->getType()==8)
			objects[i]->movetile();
	}
/* Spawning Siege*/
	spawnsiege++;
	if(spawnsiege%700==0)
	{
		int objectx,objecty;
		objectx=rand()%1175;objecty=rand()%575;
		objects.push_back(new SiegeMinion(*siege,objectx,objecty,150,0));
		objects.last()->setPos(objectx,objecty);
		scene->addItem(objects.last());
		spawnsiege=0;
	}
	for( int i=0;i<objects.size();i++)
	{
		if(objects[i]->getType()==10)
		{
			objects[i]->movetile(objects.first()->getX(),objects.first()->getY());
		/*Can he shoot*/
			int curplayx=sqrt(pow(objects.first()->getX()+75/2,2));
			int curplayy=sqrt(pow(objects.first()->getY()+75/2+25,2));
			int curx=sqrt(pow(objects[i]->getX()+65/2,2));
			int cury=sqrt(pow(objects[i]->getY()+65/2,2));
			if(120 >= sqrt(pow((curplayx-curx),2) + pow((curplayy-cury),2)))
			{
				countcannon++;
				if(countcannon%10==0)
				{
				objects.push_back(new CannonShot(*cannon,objects[i]->getX(),objects[i]->getY(),1,0,objects.first()->getX(),objects.first()->getY()));
				objects.last()->setPos(objects.first()->getX(),objects.first()->getY());
				scene->addItem(objects.last());
				}
			}
		}
	}
/* Spawning caster*/
	spawncaster++;
	if(spawncaster%500==0)
	{
		int objectx,objecty;
		objectx=rand()%1175;objecty=rand()%575;
		objects.push_back(new CasterMinion(*caster,objectx,objecty,50,0));
		objects.last()->setPos(objectx,objecty);
		scene->addItem(objects.last());
		spawncaster=0;
	}
	for( int i=0;i<objects.size();i++)
	{
		if(objects[i]->getType()==2)
		{
			objects[i]->movetile(objects.first()->getX(),objects.first()->getY());
		/*Can he shoot*/
			int curplayx=sqrt(pow(objects.first()->getX()+75/2,2));
			int curplayy=sqrt(pow(objects.first()->getY()+75/2+25,2));
			int curx=sqrt(pow(objects[i]->getX()+65/2,2));
			int cury=sqrt(pow(objects[i]->getY()+65/2,2));
			if(120 >= sqrt(pow((curplayx-curx),2) + pow((curplayy-cury),2)))
			{
				countbolt++;
				if(countbolt%10==0)
				{
				objects.push_back(new EnergyBolt(*energy,objects[i]->getX(),objects[i]->getY(),1,0,objects.first()->getX(),objects.first()->getY()));
				objects.last()->setPos(objects.last()->getX(),objects.last()->getY());
				scene->addItem(objects.last());
				}
			}
		}
	}
/* Move all shots */
	for( int i=0;i<objects.size();i++)
	{
		if(objects[i]->getType()== 0 || objects[i]->getType()== 1 ||objects[i]->getType()== 4 ||objects[i]->getType()== 9 ||objects[i]->getType()== 11)
		{
				objects[i]->movetile();
		}
	}
/* Removes cases for the shots*/
	for( int i=0;i<objects.size();i++)
	{
		if(objects[i]->getType()== 0 || objects[i]->getType()== 1 ||objects[i]->getType()== 4 ||objects[i]->getType()== 9 ||objects[i]->getType()== 11)
		{
			if(objects[i]->getHealth()<=0 || objects[i]->isGone())
				died(objects[i]);
		}
	}
/* Check for collision and do damage*/
	for( int i=0;i<objects.size();i++)
	{
		SceneObject* itemA=objects[i];
		for(int j=0;j<objects.size();j++)
		{
			SceneObject* itemB=objects[j];
			if(i==j)
				continue;
			if(itemA->collidesWithItem(itemB))
			{
				// ezreal hits a monster or attack
				if(itemA->getType()==5 && (itemB->getType()== 1 || itemB->getType()== 2 || itemB->getType()==4 || itemB->getType()== 8 || itemB->getType()==10))
				{
					ezhurt++;
					if(ezhurt%4==0)
					{
						itemA->setHealth(itemA->getHealth()-itemB->getDamage());
						itemB->setHealth(itemB->getHealth()-itemA->getDamage());
						//cout << "Ez was hurt: " <<objects.first()->getHealth()<< endl;
						//cout << "Monster was hurt: " << itemB->getHealth() << endl;
						disphealth=numtostr(objects.first()->getHealth());
						health->setText(disphealth);
						cout << "HEALTH: " << objects.first()->getHealth() << "  MANA: " << objects.first()->getMana() << "  LEVEL: " << levelff << "  SCORE: " << points*50 << endl;
						ezhurt=0;
					}
				}
				// monsters are hit by an attack
				if((itemA->getType()==2 || itemA->getType()==8 || itemA->getType()==10) && (itemB->getType()== 0 || itemB->getType()== 9 || itemB->getType()== 11))
				{
					itemA->setHealth(itemA->getHealth()-itemB->getDamage());
				}
				// Ez's attack's hit a monster
				if((itemA->getType()==0 || itemA->getType()==9 || itemA->getType()==11) && (itemB->getType()== 2 || itemB->getType()== 8 || itemB->getType()== 10))
				{
					itemA->setHealth(itemA->getHealth()-itemB->getDamage());
				}
				// monster attack's hit ez
				if((itemA->getType()==1 || itemA->getType()==4) && (itemB->getType()== 5))
				{
					ezhurt++;
					if(ezhurt%10==0)
					{
						itemA->setHealth(itemA->getHealth()-itemB->getDamage());
						//cout << "Ez was hurt: " << objects.first()->getHealth() << endl;
						disphealth=numtostr(objects.first()->getHealth());
						health->setText(disphealth);
						cout << "HEALTH: " << objects.first()->getHealth() << "  MANA: " << objects.first()->getMana() << "  LEVEL: " << levelff << "  SCORE: " << points*50 << endl;
						ezhurt=0;
					}
				}
				// powerups touched by Ez
				if((itemA->getType()==3 || itemA->getType()==6 || itemA->getType()==7) && (itemB->getType()== 5))
				{
					itemA->setHealth(itemA->getHealth()-itemB->getDamage());
				}
				// Ez touched Heal
				if( itemA->getType()== 5 && itemB->getType()==6 )
				{
					itemA->setHealth(itemA->getHealth()+itemB->getDamage());
					itemB->setHealth(itemB->getHealth()-itemA->getDamage());
				}
				// Ez touched Clarity
				if( itemA->getType()== 5 && itemB->getType()==3 )
				{
					itemA->setMana(itemA->getMana()+itemB->getDamage());
					itemB->setHealth(itemB->getHealth()-itemA->getDamage());
				}
				// Ez touched Ignite
				if( itemA->getType()== 5 && itemB->getType()==7 )
				{
					grabbedignite=true;
				}
			}
		}
	}  
	// for loop checking if ignite was grabbed
	if(grabbedignite)
	{
		for(int i=1;i<objects.size()/4;i++)
		{
			died(objects[i]);
		}
		grabbedignite=false;
	}
	// for loop checking if anythings health is 0 or below
	for(int i=0;i<objects.size();i++)
	{
		if(objects[i]->getHealth()<=0)
		{
			if(objects[i]->getType()==5)
			{
				playerAlive=false;
				inGame=false;
				lostgame=true;
				// write out to file for score
				ofstream fout;
				fout.open("scores.txt");
				bool printscore=false;
				if(scorenames.empty())
				{
				    fout << (name->toPlainText()).toStdString() << "|" << points*50<< endl;
				}
				else
				{
					for(int i=0; i<scorenames.size();i++){
						if(scores[i]<points*50 && !printscore)
						{
							fout << (name->toPlainText()).toStdString() << "|" << points*50<< endl;
							cout << (name->toPlainText()).toStdString() << "|" << points*50<< endl;
							printscore=true;
						}
						fout << scorenames[i] << "|" << scores[i] << endl;
						cout << scorenames[i] << "|" << scores[i] << endl;
					}
				}
				fout.close();
			}
			//cout << "Someone DIED!" << endl;
			if((objects[i]->getType()==2 || objects[i]->getType()==8 || objects[i]->getType()==10) && objects[i]->getHealth()<=0)
				points++;
			if(points>20)
			{
				view->setBackgroundBrush(Qt::red);
				timer->stop();
				timer->start(20);
				levelff=4;
				level->setText("LEVEL: 0"+numtostr(levelff));
				cout << "HEALTH: " << objects.first()->getHealth() << "  MANA: " << objects.first()->getMana() << "  LEVEL: " << levelff << "  SCORE: " << points*50 << endl;
			}
			else if(points>15)
			{
				view->setBackgroundBrush(Qt::yellow);
				timer->stop();
				timer->start(30);
				levelff=3;
				level->setText("LEVEL: 0"+numtostr(levelff));
				cout << "HEALTH: " << objects.first()->getHealth() << "  MANA: " << objects.first()->getMana() << "  LEVEL: " << levelff << "  SCORE: " << points*50 << endl;
			}
			else if(points>10)
			{
				view->setBackgroundBrush(Qt::blue);
				timer->stop();
				timer->start(50);
				levelff=2;
				level->setText("LEVEL: 0"+numtostr(levelff));
				cout << "HEALTH: " << objects.first()->getHealth() << "  MANA: " << objects.first()->getMana() << "  LEVEL: " << levelff << "  SCORE: " << points*50 << endl;
			}
			QString temp("SCORE: "+numtostr(points*50));
			score->setText(temp);
			score->show();
			cout << "HEALTH: " << objects.first()->getHealth() << "  MANA: " << objects.first()->getMana() << "  LEVEL: " << levelff << "  SCORE: " << points*50 << endl;
			died(objects[i]);
		}
	}
	update();
  }
}
Exemplo n.º 16
0
Arquivo: log.c Projeto: akerl/tinyssh
static void outnum(unsigned long long n) {
    char b[NUMTOSTR_LEN];
    outs(numtostr(b, n));
}