int main(int argc, char * argv[]) { double power = 1; int size = 1; double output = 0; double total = 0; if (argc != 2) { printf("Enter this size of memory to be allocated.\n"); return 0; } int mSize = atoi(argv[1]); //unsigned char mem[mSize]; unsigned char* pointer = malloc(mSize); if (pointer) { class_memory(pointer, mSize); while (class_malloc(size)) { size = (int)pow(2.0,power); power++; } } class_stats(); return 0; }
void *thread_func(void *arg) { int i; char *strings[10]; for (i = 0; i<10; i++) strings[i] = (char *)class_malloc(1024); //allocate from classmem library for (i = 9; i>=0; i--) class_free(strings[i]); class_stats(); }
void PlayerInst::gain_xp(GameState* gs, int xp) { int levels_gained = stats().gain_xp(xp); if (levels_gained > 0) { char level_gain_str[128]; snprintf(level_gain_str, 128, "%s reached level %d!", is_local_player() ? "You have" : "Your ally has", class_stats().xplevel); gs->game_chat().add_message(level_gain_str, Colour(50, 205, 50)); } }
int main(int argc, char * argv[]) { int i; char *strings[10]; class_memory(mem,MSIZE); // give it memory allocator for (i = 0; i<10; i++) strings[i] = (char *)class_malloc(1024); //allocate from classmem library for (i = 9; i>=0; i--) class_free(strings[i]); class_stats(); }
int main(int argc, char * argv[]) { printf("%s Version %d.%d\n",argv[0], Cma_VERSION_MAJOR, Cma_VERSION_MINOR); printf("Usage: %s\n",argv[0]); int i; char *strings[10]; class_memory(mem,MSIZE); // give it memory allocator for (i = 0; i<10; i++) strings[i] = (char *)class_malloc(1024); //allocate from classmem library for (i = 9; i>=0; i--) class_free(strings[i]); class_stats(); }
int main(int argc, char * argv[]) { int MSIZE; MSIZE = atoi(argv[1]); char * mem; mem = malloc(MSIZE); class_memory(mem,MSIZE); // give it memory allocator int n = 1; while (mem) { mem = class_malloc(n); n *= 2; } class_free(mem); class_stats(); return 0; }
int main(int argc, char * argv[]) { int i; double *arrays[ARRAYNUM]; class_memory(mymemory,MSIZE); // give it memory allocator for (i = 0; i<ARRAYNUM; i++) arrays[i] = (double *)class_malloc(ARRAYSIZE); //allocate from classmem library for (i = 0; i<ARRAYNUM; i++) arrays[i][0] = i; for (i = 0; i<ARRAYNUM; i++) printf("%0.2d",arrays[i][0]);//print out the first element for (i = ARRAYNUM-1; i>=0; i--) class_free(arrays[i]); class_stats(); return 0; }
int main (int argc, char* argv[]) { int i; char *alph[LIMIT]; // character array to allocate class_memory(m,SIZE2); // pass char array of size SIZE2 // to class_memory for allocation for (i = 0; i<LIMIT; i++) alph[i] = (int *)class_malloc(SIZE1); // allocate using classmem lib for (i = 0; i<LIMIT; i++) { alph[i] = i%26+'a'; // set member value printf("%c", (int) alph[i]); // immediately print said value } puts("\n"); // end line for (i = LIMIT; i>0; i--) class_free(alph[i]); // release allocated memory used by alph array class_stats(); // pop stats up to see what's happened }
void PlayerInst::use_weapon(GameState* gs, const GameAction& action) { WeaponEntry& wentry = weapon().weapon_entry(); MTwist& mt = gs->rng(); const int MAX_MELEE_HITS = 10; EffectiveStats& estats = effective_stats(); if (!cooldowns().can_doaction()) { return; } Pos start(x, y); Pos actpos(action.action_x, action.action_y); if (wentry.uses_projectile && !equipment().has_projectile()) { return; } int cooldown = 0; if (equipment().has_projectile()) { const Projectile& projectile = equipment().projectile; ProjectileEntry& pentry = projectile.projectile_entry(); item_id item = get_item_by_name(pentry.name.c_str()); int weaprange = std::max(wentry.range, pentry.range); AttackStats weaponattack(weapon()); bool wallbounce = false; int nbounces = 0; float movespeed = pentry.speed; cooldown = std::max(wentry.cooldown, pentry.cooldown); //XXX: Horrible hack REMOVE THIS LATER if (class_stats().class_type().name == "Archer" && pentry.weapon_class == "bows") { int xplevel = class_stats().xplevel; float movebonus = class_stats().xplevel / 4.0f; if (movebonus > 2) { movebonus = 2; } float cooldown_mult = 1.0f - (class_stats().xplevel - 1) / 20.0f; if (cooldown_mult <= 0.85) { cooldown_mult = 0.85; } cooldown *= cooldown_mult; movespeed += movebonus; if (xplevel >= 3 && core_stats().mp >= 5) { nbounces = 2; core_stats().mp -= 5; } } GameInst* bullet = new ProjectileInst(projectile, effective_atk_stats(mt, weaponattack), id, start, actpos, movespeed, weaprange, NONE, wallbounce, nbounces); gs->add_instance(bullet); equipment().use_ammo(); } else { int weaprange = wentry.range + this->radius + TILE_SIZE / 2; float mag = distance_between(actpos, Pos(x, y)); if (mag > weaprange) { float dx = actpos.x - x, dy = actpos.y - y; actpos = Pos(x + dx / mag * weaprange, y + dy / mag * weaprange); } GameInst* enemies[MAX_MELEE_HITS]; int max_targets = std::min(MAX_MELEE_HITS, wentry.max_targets); int numhit = get_targets(gs, this, actpos.x, actpos.y, wentry.dmgradius, enemies, max_targets); if (numhit == 0) { return; } for (int i = 0; i < numhit; i++) { EnemyInst* e = (EnemyInst*)enemies[i]; lua_hit_callback(gs->get_luastate(), wentry.on_hit_func, this, e); if (attack(gs, e, AttackStats(equipment().weapon))) { PlayerData& pc = gs->player_data(); signal_killed_enemy(); char buffstr[32]; int amnt = round( double(e->xpworth()) / pc.all_players().size()); players_gain_xp(gs, amnt); snprintf(buffstr, 32, "%d XP", amnt); gs->add_instance( new AnimatedInst(Pos(e->x - 5, e->y - 5), -1, 25, Posf(), Posf(), AnimatedInst::DEPTH, buffstr, Colour(255, 215, 11))); } } cooldown = wentry.cooldown; } cooldowns().reset_action_cooldown(cooldown * estats.cooldown_mult); reset_rest_cooldown(); }
void draw_stats(char* dirname) { params_stats = get_stats(dirname); params_bonus = get_bonus(dirname); params_main = class_stats(params_chara.main); params_sub = class_stats(params_chara.sub); int i; attron(COLOR_PAIR(2)); for(i = 0; i < 7; ++i) mvaddch(1 + i, 18, '|'); attroff(COLOR_PAIR(2)); int strba = params_stats.str; int dexba = params_stats.dex; int agiba = params_stats.agi; int inlba = params_stats.inl; int senba = params_stats.sen; int spiba = params_stats.spi; int lukba = params_stats.luk; int strbo = strba / 3; int dexbo = dexba / 3; int agibo = agiba / 3; int inlbo = inlba / 3; int senbo = senba / 3; int spibo = spiba / 3; int lukbo = lukba / 3; int strcm = params_main.str; int dexcm = params_main.dex; int agicm = params_main.agi; int inlcm = params_main.inl; int sencm = params_main.sen; int spicm = params_main.spi; int lukcm = params_main.luk; int strcs = params_sub.str; int dexcs = params_sub.dex; int agics = params_sub.agi; int inlcs = params_sub.inl; int sencs = params_sub.sen; int spics = params_sub.spi; int lukcs = params_sub.luk; int strsk = params_bonus.str; int dexsk = params_bonus.dex; int agisk = params_bonus.agi; int inlsk = params_bonus.inl; int sensk = params_bonus.sen; int spisk = params_bonus.spi; int luksk = params_bonus.luk; int str = strbo + strcm + strcs + strsk; int dex = dexbo + dexcm + dexcs + dexsk; int agi = agibo + agicm + agics + agisk; int inl = inlbo + inlcm + inlcs + inlsk; int sen = senbo + sencm + sencs + sensk; int spi = spibo + spicm + spics + spisk; int luk = lukbo + lukcm + lukcs + luksk; attron(COLOR_PAIR(1)); for(i = 18; i < COLS; ++i) mvprintw(0, i, " "); mvprintw(0, 18, "Stats:"); attroff(COLOR_PAIR(1)); mvprintw(1, 20, "Str |% 3d |% 3d | +%d |% 3d |% 3d", strba, strbo, strcm + strcs, strsk, str); mvprintw(2, 20, "Dex |% 3d |% 3d | +%d |% 3d |% 3d", dexba, dexbo, dexcm + dexcs, dexsk, dex); mvprintw(3, 20, "Agi |% 3d |% 3d | +%d |% 3d |% 3d", agiba, agibo, agicm + agics, agisk, agi); mvprintw(4, 20, "Int |% 3d |% 3d | +%d |% 3d |% 3d", inlba, inlbo, inlcm + inlcs, inlsk, inl); mvprintw(5, 20, "Sen |% 3d |% 3d | +%d |% 3d |% 3d", senba, senbo, sencm + sencs, sensk, sen); mvprintw(6, 20, "Spi |% 3d |% 3d | +%d |% 3d |% 3d", spiba, spibo, spicm + spics, spisk, spi); mvprintw(7, 20, "Luk |% 3d |% 3d | +%d |% 3d |% 3d", lukba, lukbo, lukcm + lukcs, luksk, luk); attron(COLOR_PAIR(2)); for(i = 0; i < 7; ++i) mvaddch(1 + i, 49, '|'); attroff(COLOR_PAIR(2)); int acuba = dex; int atkba = 0; int avoba = agi; int defba = 0; int durba = spi; int spdba = agi + sen; int mobba = str + 5; int acubo = 0; int atkbo = 0; int avobo = 0; int defbo = 0; int durbo = 0; int spdbo = 0; int mobbo = 0; int acusk = 0; int atksk = 0; int avosk = 0; int defsk = 0; int dursk = 0; int spdsk = 0; int mobsk = 0; int acu = acuba + acubo + acusk; int atk = atkba + atkbo + atksk; int avo = avoba + avobo + avosk; int def = defba + defbo + defsk; int dur = durba + durbo + dursk; int spd = spdba + spdbo + spdsk; int mob = mobba + mobbo + mobsk; int acudr = 0; int atkdr = 0; int avodr = 0; int defdr = 0; int durdr = 0; int spddr = 0; int mobdr = 0; mvprintw(1, 51, "Acu |% 3d |% 3d |% 3d |% 3d (%d)", acuba, acubo, acusk, acu, acudr); mvprintw(2, 51, "Atk |% 3d |% 3d |% 3d |% 3d (%d)", atkba, atkbo, atksk, atk, atkdr); mvprintw(3, 51, "Avo |% 3d |% 3d |% 3d |% 3d (%d)", avoba, avobo, avosk, avo, avodr); mvprintw(4, 51, "Def |% 3d |% 3d |% 3d |% 3d (%d)", defba, defbo, defsk, def, defdr); mvprintw(5, 51, "Dur |% 3d |% 3d |% 3d |% 3d (%d)", durba, durbo, dursk, dur, durdr); mvprintw(6, 51, "Spd |% 3d |% 3d |% 3d |% 3d (%d)", spdba, spdbo, spdsk, spd, spddr); mvprintw(7, 51, "Mob |% 3d |% 3d |% 3d |% 3d (%d)", mobba, mobbo, mobsk, mob, mobdr); attron(COLOR_PAIR(2)); for(i = 0; i < 7; ++i) mvaddch(1 + i, 79, '|'); attroff(COLOR_PAIR(2)); return; }