09 Feb, 2013, Xrakisis wrote in the 1st comment:
Votes: 0
i wrote an army system and its not calculating and dealing damage correctly.
anyone know what i have to do to this to have it check light_cavs first,
kill them off if the damage is more than their added unit hp, then move to next unit?

[Your army might: 1487500][Their army might:1487500]

[Your army of: 170000][Their army of:170000]

[Round: 1]
You attack with: 10000 Trebuchets, 10000 Scorpions, 10000 Archers, 10000 Archer Infanty, 10000 Chariots, 10000 Militia, 10000 Phalanx, 10000 Legionnaire, 10000 Heavy Infantry, 10000 Axemen, 10000 Light Cavalry, 10000 Medium Cavalry, 10000 Heavy Cavalry, 10000 Knights, 10000 Battle Rams
[Your Army damage: 3910000]

You kill 10000 light cavalry, 10000 medium cavalry, 10000 heavy cavalry, 10000 Knights, 10000 chariots, 10000 pikemen, 10000 militia, 10000 heavy infantry, 10000 swordsmen, 10000 axemen, 10000 archer-infantry, 10000 archers, 10000 Battle Rams, 10000 scorpions, 10000 ballistas, 10000 catapults, 10000 trebuchets You are attacked by:
[Your army is attacked and takes :-140710900 damage]

You lose 10000 light cavalry, 10000 medium cavalry, 10000 heavy cavalry, 10000 Knights, 10000 chariots, 10000 pikemen, 10000 militia, 10000 heavy infantry, 10000 swordsmen, 10000 axemen, 10000 archer-infantry, 10000 archers, 10000 Battle Rams, 10000 scorpions, 10000 ballistas, 10000 catapults, 10000 trebuchets


#define MILITIA_ATTACK 1
#define PIKEMAN_ATTACK 5
#define AXEMAN_ATTACK 6
#define SWORDSMAN_ATTACK 6
#define HINF_ATTACK 10
#define ARCHER_ATTACK 6
#define ARCHERINF_ATTACK 8
#define SCORPION_ATTACK 15
#define CHARIOT_ATTACK 20
#define LCAV_ATTACK 15
#define MCAV_ATTACK 20
#define HCAV_ATTACK 30
#define KNIGHT_ATTACK 40
#define RAM_ATTACK 100
#define BALLISTA_ATTACK 200
#define CATAPULT_ATTACK 400
#define TREBUCHET_ATTACK 500


#define MILITIA_HP 10000
#define PIKEMAN_HP 45000
#define AXEMAN_HP 20000
#define SWORDSMAN_HP 20000
#define HINF_HP 25000
#define ARCHER_HP 10000
#define ARCHERINF_HP 20000
#define SCORPION_HP 25000
#define CHARIOT_HP 200000
#define LCAV_HP 80000
#define MCAV_HP 150000
#define HCAV_HP 160000
#define KNIGHT_HP 220000
#define RAM_HP 500000
#define BALLISTA_HP 370000
#define CATAPULT_HP 460000
#define TREBUCHET_HP 500000


void battle_update( void )
{
CHAR_DATA *ch;
CHAR_DATA *ch_next;
CHAR_DATA *victim;
DESCRIPTOR_DATA *d;
char buf[MAX_STRING_LENGTH];
int chance;
int armymight = 0;
int varmymight = 0;
int roundtime;
int totalfighting = 0;
int vtotalfighting = 0;
int chfighting = 0;
int vfighting = 0;
int distance = 1000;
chance = number_percent();
int x, y, dam;
int chdam = 0;





for ( d = descriptor_list; d != NULL; d = d->next )
{

// for (ch = first_fight; ch != NULL; ch = ch_next)
// {
// ch_next = ch->next_fight;

if ( ( ch = d->character) == NULL )
continue;

victim=ch->fighting;



if (victim != NULL)
{
if (victim->in_room != ch->in_room)
{
stc("Their army is not here.\n\r",ch);
return;
}

if (!IS_NPC(ch))
{
totalfighting += ch->militia;
totalfighting += ch->pikemen;
totalfighting += ch->swordsmen;
totalfighting += ch->heavy_infantry;
totalfighting += ch->axemen;
totalfighting += ch->archers;
totalfighting += ch->archerinfantry;
totalfighting += ch->chariots;
totalfighting += ch->light_cavalry;
totalfighting += ch->medium_cavalry;
totalfighting += ch->heavy_cavalry;
totalfighting += ch->knights;
totalfighting += ch->ballistas;
totalfighting += ch->catapults;
totalfighting += ch->rams;
totalfighting += ch->scorpions;
totalfighting += ch->trebuchets;

vtotalfighting += victim->militia;
vtotalfighting += victim->pikemen;
vtotalfighting += victim->swordsmen;
vtotalfighting += victim->heavy_infantry;
vtotalfighting += victim->axemen;
vtotalfighting += victim->archers;
vtotalfighting += victim->archerinfantry;
vtotalfighting += victim->chariots;
vtotalfighting += victim->light_cavalry;
vtotalfighting += victim->medium_cavalry;
vtotalfighting += victim->heavy_cavalry;
vtotalfighting += victim->knights;
vtotalfighting += victim->ballistas;
vtotalfighting += victim->catapults;
vtotalfighting += victim->rams;
vtotalfighting += victim->scorpions;
vtotalfighting += victim->trebuchets;


armymight += ch->militia;
armymight += ch->pikemen * 1.5;
armymight += ch->swordsmen * 1.5;
armymight += ch->heavy_infantry * 2;
armymight += ch->axemen * 1.5;
armymight += ch->archers * 3;
armymight += ch->archerinfantry * 3.25;
armymight += ch->chariots * 5;
armymight += ch->light_cavalry * 3;
armymight += ch->medium_cavalry * 5;
armymight += ch->heavy_cavalry * 7;
armymight += ch->knights * 10;
armymight += ch->ballistas * 20;
armymight += ch->catapults * 25;
armymight += ch->rams * 22;
armymight += ch->scorpions * 8;
armymight += ch->trebuchets * 30;

varmymight += victim->militia;
varmymight += victim->pikemen * 1.5;
varmymight += victim->swordsmen * 1.5;
varmymight += victim->heavy_infantry * 2;
varmymight += victim->axemen * 1.5;
varmymight += victim->archers * 3;
varmymight += victim->archerinfantry * 3.25;
varmymight += victim->chariots * 5;
varmymight += victim->light_cavalry * 3;
varmymight += victim->medium_cavalry * 5;
varmymight += victim->heavy_cavalry * 7;
varmymight += victim->knights * 10;
varmymight += victim->ballistas * 20;
varmymight += victim->catapults * 25;
varmymight += victim->rams * 22;
varmymight += victim->scorpions * 8;
varmymight += victim->trebuchets * 30;

//if (totalfighting <= 100) chfighting = totalfighting;
//if (totalfighting > 100)
chfighting = totalfighting;
//if (vtotalfighting <= 100) vfighting = vtotalfighting;
//if (vtotalfighting > 100)
vfighting = vtotalfighting;

if (armymight <= 0) return;
if (ch->roundtime <= 5) ch->roundtime++;
if (ch->army_distance > 10) ch->army_distance -= 10;
roundtime = ch->roundtime;
distance = ch->army_distance;

sprintf(buf,"\n\r[#YYour army might: #R%d#n][#YTheir army might:#R%d]\n\r",armymight,varmymight);
stc(buf,ch);
sprintf(buf,"\n\r[#YYour army of: #R%d#n][#YTheir army of:#R%d]\n\r",totalfighting, vtotalfighting);
stc(buf,ch);
//sprintf(buf, "… #R%d #Yof your men are engaged in melee, #R%d #Yof the enemy are engaged.#n\n\r",chfighting,vfighting);
//stc(buf,ch);
sprintf(buf,"\n\r[#YRound: #R%d#n]\n\r",ch->roundtime);
stc(buf,ch);

stc("#RYou are attacked by: #n",victim);
stc("#RYou attack with: #n",ch);
if (ch->trebuchets >= 1 && roundtime == 1)
{
chfighting = ch->trebuchets ; //- (ch->trebuchets / 90));
sprintf(buf,"%d Trebuchets, ",chfighting);
stc(buf,victim);
sprintf(buf,"%d Trebuchets, ",chfighting);
stc(buf,ch);
chdam += chfighting * TREBUCHET_ATTACK;
}
if ((ch->scorpions >= 1 && distance <= 400)
&& (roundtime == 1 || roundtime == 3 || roundtime == 5))
{
chfighting = ch->scorpions/ 50; // (ch->scorpions / 90));
sprintf(buf,"%d Scorpions, ",chfighting);
stc(buf,victim);
sprintf(buf,"%d Scorpions, ",chfighting);
stc(buf,ch);

chdam += chfighting * SCORPION_ATTACK;
}
if( (ch->ballistas >= 1 && distance <= 20) && (roundtime == 2 || roundtime == 4))

{
chfighting = ch->ballistas/ 50; // - (ch->ballistas / 90));
sprintf(buf,"%d Ballistae, ",chfighting);
stc(buf,victim);
sprintf(buf,"%d Ballistae, ",chfighting);
stc(buf,ch);
chdam += chfighting * BALLISTA_ATTACK;
}
if ((ch->catapults >= 1 && distance <= 600) && (roundtime == 3 || roundtime == 5))
{
chfighting = ch->catapults/ 50;// (ch->catapults / 90));
sprintf(buf,"%d Catapult, ",chfighting);
stc(buf,victim);
sprintf(buf,"%d Catapult, ",chfighting);
stc(buf,ch);
chdam += chfighting * CATAPULT_ATTACK;
}
if (ch->archers >= 1 && distance <= 400)
{
chfighting = ch->archers/ 50; // (ch->archers / 90));
sprintf(buf,"%d Archers, ",chfighting);
stc(buf,victim);
sprintf(buf,"%d Archers, ",chfighting);
stc(buf,ch);
chdam += chfighting * ARCHER_ATTACK;
}
if (ch->archerinfantry >= 1 && distance <= 350)
{
chfighting = ch->archerinfantry/ 50; // (ch->archerinfantry / 90));
sprintf(buf,"%d Archer Infanty, ",chfighting);
stc(buf,victim);
sprintf(buf,"%d Archer Infanty, ",chfighting);
stc(buf,ch);
chdam += chfighting * ARCHERINF_ATTACK;
}

if (ch->chariots >= 1 && distance <= 300)
{
chfighting = ch->chariots/ 50;// (ch->chariots / 90));
sprintf(buf,"%d Chariots, ",chfighting);
stc(buf,victim);
sprintf(buf,"%d Chariots, ",chfighting);
stc(buf,ch);
chdam += chfighting * CHARIOT_ATTACK;
}

if (ch->militia >= 1 && distance == 0)
{
chfighting = ch->militia/ 50; //(ch->militia / 90));
sprintf(buf,"%d Militia, ",chfighting);
stc(buf,victim);
sprintf(buf,"%d Militia, ",chfighting);
stc(buf,ch);
chdam += chfighting * MILITIA_ATTACK;
}

if (ch->pikemen >= 1 && distance == 0)
{
chfighting = ch->pikemen/ 50; //(ch->pikemen / 90));
sprintf(buf, "%d Phalanx, ",chfighting);
stc(buf,victim);
sprintf(buf, "%d Phalanx, ",chfighting);
stc(buf,ch);
chdam += chfighting * PIKEMAN_ATTACK;
}
if (ch->swordsmen >= 1 && distance == 0)
{
chfighting = ch->swordsmen/ 50; //(ch->swordsmen / 90));
sprintf(buf, "%d Legionnaire, ",chfighting);
stc(buf,victim);
sprintf(buf, "%d Legionnaire, ",chfighting);
stc(buf,ch);
chdam += chfighting * SWORDSMAN_ATTACK;
}
if (ch->heavy_infantry >= 1 && distance == 0)
{
chfighting = ch->heavy_infantry/ 50; //- (ch->heavy_infantry / 90));
sprintf(buf, "%d Heavy Infantry, ",chfighting);
stc(buf,victim);
sprintf(buf, "%d Heavy Infantry, ",chfighting);
stc(buf,ch);
chdam += chfighting * HINF_ATTACK;
}
if (ch->axemen >= 1 && distance == 0)
{
chfighting = ch->axemen/ 50;// (ch->axemen / 90));
sprintf(buf, "%d Axemen, ",chfighting);
stc(buf,victim);
sprintf(buf, "%d Axemen, ",chfighting);
stc(buf,ch);
chdam += chfighting * AXEMAN_ATTACK;
}
if (ch->light_cavalry >= 1 && distance == 0)
{
chfighting = ch->light_cavalry/ 50; //- (ch->light_cavalry / 90));
sprintf(buf, "%d Light Cavalry, ",chfighting);
stc(buf,victim);
sprintf(buf, "%d Light Cavalry, ",chfighting);
stc(buf,ch);
chdam += chfighting * LCAV_ATTACK;
}
if (ch->medium_cavalry >= 1 && distance == 0)
{
chfighting = ch->medium_cavalry/ 50;// (ch->medium_cavalry / 90));
sprintf(buf, "%d Medium Cavalry, ",chfighting);
stc(buf,victim);
sprintf(buf, "%d Medium Cavalry, ",chfighting);
stc(buf,ch);
chdam += chfighting * MCAV_ATTACK;
}
if (ch->heavy_cavalry >= 1 && distance == 0)
{
chfighting = ch->heavy_cavalry/ 50;// (ch->heavy_cavalry / 90));
sprintf(buf, "%d Heavy Cavalry, ",chfighting);
stc(buf,victim);
sprintf(buf, "%d Heavy Cavalry, ",chfighting);
stc(buf,ch);
chdam += chfighting * HCAV_ATTACK;
}
if (ch->knights >= 1 && distance == 0)
{
chfighting = ch->knights/ 50; //- (ch->knights / 90));
sprintf(buf, "%d Knights, ",chfighting);
stc(buf,victim);
sprintf(buf, "%d Knights, ",chfighting);
stc(buf,ch);
chdam += chfighting * KNIGHT_ATTACK;
}
if (ch->rams >= 1 && distance == 0)
{
chfighting = ch->rams/ 50;// (ch->rams / 90));
sprintf(buf, "%d Battle Rams",chfighting);
stc(buf,victim);
sprintf(buf, "%d Battle Rams",chfighting);
stc(buf,ch);
chdam += chfighting * RAM_ATTACK;
}
//stc(".\n\r",victim);
//stc(".\n\r",ch);
if (roundtime >= 5) roundtime = 1;

dam = chdam / 2;
chdam -= dam;

sprintf(buf,"\n\r[#YYour Army damage: #R%d#n]\n\r",chdam);
stc(buf,ch);

sprintf(buf,"\n\r[#YYour army is attacked and takes :#R%d#Y damage#n]\n\r",chdam);
stc(buf,victim);

sprintf(buf,"[#YYour Army damages the Hero for: #R%d#n]\n\r",dam);
stc(buf,ch);

sprintf(buf,"[#YYou are attacked and take :#R%d#Y damage#n]\n\r",dam);
stc(buf,victim);
hurt_person(ch, victim, dam, 0);

chdam /= 50;
if ((chdam >= 100000) || (chdam < 0)) chdam = 100000;

if (!IS_NPC(ch) && !IS_NPC(victim))
{
stc("\n\r#RYou kill #n",ch);
stc("\n\r#RYou lose #n",victim);


if (victim->light_cavalry >= 1 && (chdam > LCAV_HP));
{
x = victim->light_cavalry * LCAV_HP; // total hp of all this troop type.
y = x / LCAV_HP; // how many die
if (y >= 1)
{
sprintf(buf, "%d light cavalry, ",y);
stc(buf,ch);
stc(buf,victim);
victim->light_cavalry -= y;
chdam -= LCAV_HP * y;
} }
if (victim->medium_cavalry >= 1 && (chdam > MCAV_HP));
{
x = victim->medium_cavalry * MCAV_HP; // total hp of all this troop type.
y = x / MCAV_HP; // how many die
if (y >= 1)
{
sprintf(buf, " %d medium cavalry,#n ",y);
stc(buf,ch);
stc(buf,victim);
victim->medium_cavalry -= y;
chdam -= MCAV_HP * y;
} }
if (victim->heavy_cavalry >= 1 && (chdam > HCAV_HP));
{
x = victim->heavy_cavalry * HCAV_HP; // total hp of all this troop type.
y = x / HCAV_HP; // how many die

if (y >= 1)
{
sprintf(buf, "%d heavy cavalry,#n ",y);
stc(buf,ch);
stc(buf,victim);
victim->heavy_cavalry -= y;
chdam -= HCAV_HP * y;
} }
if (victim->knights >= 1 && (chdam > KNIGHT_HP));
{
x = victim->knights * KNIGHT_HP; // total hp of all this troop type.
y = x / KNIGHT_HP; // how many die
if (y >= 1)
{
sprintf(buf, "%d Knights,#n ",y);
stc(buf,ch);
stc(buf,victim);
victim->knights -= y;
chdam -= KNIGHT_HP * y;
} }
if (victim->chariots >= 1 && (chdam > CHARIOT_HP));
{
x = victim->chariots * CHARIOT_HP; // total hp of all this troop type.
y = x / CHARIOT_HP; // how many die
if (y >= 1)
{
sprintf(buf, "%d chariots,#n ",y);
stc(buf,ch);
stc(buf,victim);
victim->chariots -= y;
chdam -= CHARIOT_HP * y;
} }
if (victim->pikemen >= 1 && (chdam > PIKEMAN_HP));
{
x = victim->pikemen * PIKEMAN_HP; // total hp of all this troop type.
y = x / PIKEMAN_HP; // how many die
if (y >= 1)
{
sprintf(buf, "%d pikemen,#n ",y);
stc(buf,ch);
stc(buf,victim);
victim->pikemen -= y;
chdam -= PIKEMAN_HP * y;
} }
if (victim->militia >= 1 && (chdam > MILITIA_HP));
{
x = victim->militia * MILITIA_HP; // total hp of all this troop type.
y = x / MILITIA_HP; // how many die
if (y >= 1)
{
sprintf(buf, "%d militia,#n ",y);
stc(buf,ch);
stc(buf,victim);
victim->militia -= y;
chdam -= MILITIA_HP * y;
} }
if (victim->heavy_infantry >= 1 && (chdam > HINF_HP));
{
x = victim->heavy_infantry * HINF_HP; // total hp of all this troop type.
y = x / HINF_HP; // how many die
if (y >= 1)
{
sprintf(buf, "%d heavy infantry,#n ",y);
stc(buf,ch);
stc(buf,victim);
victim->heavy_infantry -= y;
chdam -= HINF_HP * y;
} }
if (victim->swordsmen >= 1 && (chdam > SWORDSMAN_HP));
{
x = victim->swordsmen * SWORDSMAN_HP; // total hp of all this troop type.
y = x / SWORDSMAN_HP; // how many die
if (y >= 1)
{
sprintf(buf, "%d swordsmen,#n ",y);
stc(buf,ch);
stc(buf,victim);
victim->swordsmen -= y;
chdam -= SWORDSMAN_HP * y;
} }
if (victim->axemen >= 1 && (chdam > AXEMAN_HP));
{
x = victim->axemen * AXEMAN_HP; // total hp of all this troop type.
y = x / AXEMAN_HP; // how many die
if (y >= 1)
{
sprintf(buf, "%d axemen,#n ",y);
stc(buf,ch);
stc(buf,victim);
victim->axemen -= y;
chdam -= AXEMAN_HP * y;
} }
if (victim->archerinfantry >= 1 && (chdam > ARCHERINF_HP));
{
x = victim->archerinfantry * ARCHERINF_HP; // total hp of all this troop type.
y = x / ARCHERINF_HP; // how many die
if (y >= 1)
{
sprintf(buf, "%d archer-infantry,#n ",y);
stc(buf,ch);
stc(buf,victim);
victim->archerinfantry -= y;
chdam -= ARCHERINF_HP * y;
} }
if (victim->archers >= 1 && (chdam > ARCHER_HP));
{
x = victim->archers * ARCHER_HP; // total hp of all this troop type.
y = x / ARCHER_HP; // how many die
if (y >= 1)
{
sprintf(buf, "%d archers,#n ",y);
stc(buf,ch);
stc(buf,victim);
victim->archers -= y;
chdam -= ARCHER_HP * y;
} }
if (victim->rams >= 1 && (chdam > RAM_HP));
{
x = victim->rams * RAM_HP; // total hp of all this troop type.
y = x / RAM_HP; // how many die
if (y >= 1)
{
sprintf(buf, "%d Battle Rams,#n ",y);
stc(buf,ch);
stc(buf,victim);
victim->rams -= y;
chdam -= RAM_HP * y;
} }
if (victim->scorpions >= 1 && (chdam > SCORPION_HP));
{
x = victim->scorpions * SCORPION_HP; // total hp of all this troop type.
y = x / SCORPION_HP; // how many die
if (y >= 1)
{
sprintf(buf, "%d scorpions,#n ",y);
stc(buf,ch);
stc(buf,victim);
victim->scorpions -= y;
chdam -= SCORPION_HP * y;
} }
if (victim->ballistas >= 1 && (chdam > BALLISTA_HP));
{
x = victim->ballistas * BALLISTA_HP; // total hp of all this troop type.
y = x / BALLISTA_HP; // how many die
if (y >= 1)
{
sprintf(buf, "%d ballistas,#n ",y);
stc(buf,ch);
stc(buf,victim);
victim->ballistas -= y;
chdam -= BALLISTA_HP * y;
} }
if (victim->catapults >= 1 && (chdam > CATAPULT_HP));
{
x = victim->catapults * CATAPULT_HP; // total hp of all this troop type.
y = x / CATAPULT_HP; // how many die
if (y >= 1)
{
sprintf(buf, "%d catapults,#n ",y);
stc(buf,ch);
stc(buf,victim);
victim->catapults -= y;
chdam -= CATAPULT_HP * y;
} }
if (victim->trebuchets >= 1 && (chdam > TREBUCHET_HP));
{
x = victim->trebuchets * TREBUCHET_HP; // total hp of all this troop type.
y = x / TREBUCHET_HP; // how many die
if (y >= 1)
{
sprintf(buf, "%d trebuchets#n ",y);
stc(buf,ch);
stc(buf,victim);
victim->trebuchets -= y;
chdam -= TREBUCHET_HP * y;
} }

// stc("\n\r",ch);

}
if (ch->roundtime >= 5) ch->roundtime = 0;
}
}
}
return;
}
09 Feb, 2013, Idealiad wrote in the 2nd comment:
Votes: 0
I guess this sounds a little dick-ish, but you should figure out how to rewrite that without repeating yourself 10,000 times, then re-ask this question.
10 Feb, 2013, Xrakisis wrote in the 3rd comment:
Votes: 0
I thought i would post the whole function so it would be easier to diagnose..
10 Feb, 2013, Idealiad wrote in the 4th comment:
Votes: 0
No that's fine, and I apologize for my post, I replied without giving it much thought. What I was trying to say is that your function repeats itself many times, and if you can figure out how to rewrite it, it will be much easier to see where the flaw in the logic is.
10 Feb, 2013, Rarva.Riendf wrote in the 5th comment:
Votes: 0
void dam_calc(int *army,  int armyHp, int *dam, int x, int y) {
if (*army >= 1 && (dam> armyHp)); {
x =*army * armyHp; // total hp of all this troop type.
y = x / armyHp; // how many die
if (y >= 1)
{
sprintf(buf, "%d ballistas,#n ",y);
stc(buf,ch);
stc(buf,victim);
*army -= y;
dam -= armyHp * y;
}
}
}


Something like that.

Btw if something is wrong in calculation check your numeric type. it is easy to go past int limits
10 Feb, 2013, Xrakisis wrote in the 6th comment:
Votes: 0
im not sure how to condense it… the first half figures out how many troops are fighting and how much damage they should do.
the second half subtracts troops but its killing the entire enemy army in one round.. the defending army should take damage
by unit speed and strategy.

so the first part figures out by unit attack and how many fighting the damage.
and the second part kills off the fastest units first. So it should wipe all the light cavs then medium cavs then heavy cavs but
phalanx before a lot of others for strategy reasons. defending units subtracted in second part.
10 Feb, 2013, Xrakisis wrote in the 7th comment:
Votes: 0
It worked the way originally written once i used a variable bigger than int.. int was too small and going negative..
10 Feb, 2013, Rarva.Riendf wrote in the 8th comment:
Votes: 0
Quote
im not sure how to condense it

The code I wrote is close enough to what you should do.
10 Feb, 2013, Tijer wrote in the 9th comment:
Votes: 0
may have been better to post it in code tags too…. :)
10 Feb, 2013, Tijer wrote in the 10th comment:
Votes: 0
why not try changing chdam to a long int to see of that works? as you said it worked before you went over the max_int, max int is 2.141 billion i think…. are you really taking that much damage though?
10 Feb, 2013, quixadhal wrote in the 11th comment:
Votes: 0
Or you could try scaling the damage and hit points to sane values, since there's no real reason to have things that large except to satisfy players desire to see BIG NUMBERS RAWR!

When you're dealing with armies, there's little added value in tracking things down to each individual unit. Resolve battles at the company level, calculate losses, and scale the company to have that many "units" left.
10 Feb, 2013, Lyanic wrote in the 12th comment:
Votes: 0
Xrakisis said:
im not sure how to condense it…

Take all those blocks of code that are virtually identical, and refactor them to modularize and encapsulate the same functionality into more generic and reusable functions/methods. Idealiad was definitely right - there's no way you should've asked this question and copy/pasted that monstrosity (sans code tags!!) without rewriting it first. This is a good lesson, because writing code like that is just asking for the sorts of problems you're experiencing. Sorry, but it had to be said.

Addendum: I'd say it's a fair bet you're getting integer overflow. Note the negative sign in the damage amount —> [Your army is attacked and takes :-140710900 damage]
10 Feb, 2013, Rarva.Riendf wrote in the 13th comment:
Votes: 0
It is also a good idea to use unsigned type, if you dont need to have negative value. It doubles the max you can have for free.
10 Feb, 2013, Tijer wrote in the 14th comment:
Votes: 0
Lyanic said:
Xrakisis said:
im not sure how to condense it…

Take all those blocks of code that are virtually identical, and refactor them to modularize and encapsulate the same functionality into more generic and reusable functions/methods. Idealiad was definitely right - there's no way you should've asked this question and copy/pasted that monstrosity (sans code tags!!) without rewriting it first. This is a good lesson, because writing code like that is just asking for the sorts of problems you're experiencing. Sorry, but it had to be said.

Addendum: I'd say it's a fair bet you're getting integer overflow. Note the negative sign in the damage amount —> [Your army is attacked and takes :-140710900 damage]


if you have seen the CoTN codebase that he released here you will see that theres a lot of stuff JUST like the first post in there…. Xrakisis has GOOD ideas, but bad implementation skills…
10 Feb, 2013, Lyanic wrote in the 15th comment:
Votes: 0
Tijer said:
if you have seen the CoTN codebase that he released here you will see that theres a lot of stuff JUST like the first post in there….

To be honest, it has been many years since I looked at any Diku code, aside from the few scraps of legacy code remaining in my own codebase. I just assume most of it looks like that - horrifying.
10 Feb, 2013, Rarva.Riendf wrote in the 16th comment:
Votes: 0
Lyanic said:
Tijer said:
if you have seen the CoTN codebase that he released here you will see that theres a lot of stuff JUST like the first post in there….

To be honest, it has been many years since I looked at any Diku code, aside from the few scraps of legacy code remaining in my own codebase. I just assume most of it looks like that - horrifying.


Copy pasting code is indeed a plague, but not tied to Diku at all :)
10 Feb, 2013, Lyanic wrote in the 17th comment:
Votes: 0
Rarva.Riendf said:
Copy pasting code is indeed a plague, but not tied to Diku at all :)

I assume by 'tied' you mean 'restricted'. If so, no, it is not - there are no poor programming practices that are restricted exclusively to Diku code. However, I was responding directly to Tijer's comment in which a Diku derived codebase was specifically being discussed. I merely expanded the scope to include nearly all of them as examples of horrifying code.
10 Feb, 2013, Rarva.Riendf wrote in the 18th comment:
Votes: 0
Quote
I merely expanded the scope to include nearly all of them as examples of horrifying code.

I was just saying you were not expanding the scope enough :)
10 Feb, 2013, Lyanic wrote in the 19th comment:
Votes: 0
Rarva.Riendf said:
Quote
I merely expanded the scope to include nearly all of them as examples of horrifying code.

I was just saying you were not expanding the scope enough :)

Fair enough.
11 Feb, 2013, Tyche wrote in the 20th comment:
Votes: 0
You appear to be looping through the entire set of characters connected to the game.
And adding the totals up in that loop in a fashion that would always increment your local variables.
> totalfighting += ch->militia;
> totalfighting += ch->pikemen;
> totalfighting += ch->swordsmen;
Maybe this…
> totalfighting = ch->militia;
> totalfighting += ch->pikemen;
> totalfighting += ch->swordsmen;

The code is hard enough to read unformatted.
0.0/42