Looking for code...

Discussion of all aspects of the game engine, including development of new and existing features.

Moderator: Forum Moderators

SmokemJags
Posts: 580
Joined: February 14th, 2006, 3:24 am
Location: New Avalon
Contact:

Looking for code...

Post by SmokemJags »

I can't find the code for any of the special weapon attributes(poison, backstab, slow) in the wesnoth/data folder and I wanted to tweak the backstab code to make that dread ability.

You can take the backstab ability...
Remove all that malarky about needing a friendly unit on the other side of the enemy.
Change 'deal double damage' to 'receive half damage' et voila!
I'm pretty sure backstab never works when you're on the defensive even if you have an allied unit on the other side of the enemy as well, right?
Well that fits the dread ability perfectly.
If that isn't how it works, just borrow the code from marksmanship that says 'this only works when you're attacking'.

Or you can modify slow...
As soon as a unit with dread initiates combat (before blows are exchanged), the target becomes afflicted with slow (deals half damage) and then remove the slow afflication once the battle has concluded.
Though this might cause problems with the actual slow ability, I'm sure you can just borrow the slow code but rename it as dread so it doesn't override or interfere with normal slow.



toms was also looking for some help getting our campaign working, someone I don't think I'm the one to help him.
http://www.wesnoth.org/forum/viewtopic. ... 7&start=30
And unfortunately,
the computer still doesn´t read the campaign.
Help please, I´m stuck.
Code:

Code: Select all

#ifdef MULTIPLAYER 
{@campaigns/MP_Campaign/scenarios/} 
{@campaigns/MP_campaign/maps/} 
{@campaigns/MP_campaign/utils.cfg} 
#endif 
"A wise man speaks when he has something to say. A fool speaks when he has to say something."
User avatar
Ken_Oh
Moderator Emeritus
Posts: 2178
Joined: February 6th, 2006, 4:03 am
Location: Baltimore, Maryland, USA

Post by Ken_Oh »

Weapons specials are hard-coded and aren't in WML. They told me that when I wanted to tweak the code for the Slow special.
User avatar
Noyga
Inactive Developer
Posts: 1790
Joined: September 26th, 2005, 5:56 pm
Location: France

Post by Noyga »

For the attack * 2 you can do this using the attack/defense weights, using two attacks :
- one for attacking, with double damages and defense_weight = 0
- one for defending; with normal damages and attack_weight=0
For the other part it is probably more tricky.
SmokemJags
Posts: 580
Joined: February 14th, 2006, 3:24 am
Location: New Avalon
Contact:

Post by SmokemJags »

Okay let's try this a different way.

Where is the code that makes the ability backstab function the way that it does?

The game doesn't automatically know how 'backstab' works from the description in the game help files, so where it is?
Simple as that.
"A wise man speaks when he has something to say. A fool speaks when he has to say something."
User avatar
Noyga
Inactive Developer
Posts: 1790
Joined: September 26th, 2005, 5:56 pm
Location: France

Post by Noyga »

Mainly in the following C++ source files : src/action.cpp and src/ai_attack.cpp.
If doesn't really help for WML btw :roll:
SmokemJags
Posts: 580
Joined: February 14th, 2006, 3:24 am
Location: New Avalon
Contact:

Post by SmokemJags »

This is like pulling teeth...

Great, so that's where it is.
Now what's it look like, and how hard would it be to edit to reflect dread?
"A wise man speaks when he has something to say. A fool speaks when he has to say something."
toms
Posts: 1717
Joined: November 6th, 2005, 2:15 pm

Post by toms »

One thing...

Is it possible to have a script/plugin included in an user campaign? Seems like Jags would need such a thing when he is going to write this ability.
First read, then think. Read again, think again. And then post!
User avatar
Tomsik
Posts: 1401
Joined: February 7th, 2005, 7:04 am
Location: Poland

Post by Tomsik »

SmokemJags wrote:Now what's it look like, and how hard would it be to edit to reflect dread?
1.It looks like... this
2.Depends on your skills.
SmokemJags
Posts: 580
Joined: February 14th, 2006, 3:24 am
Location: New Avalon
Contact:

Post by SmokemJags »

It's been a long time since I was in college and worked with code but let's see...

Between backstab, slow, and steadfast... Backstab deals with increasing damage, slow deals with reducing damage, and steadfast increases resistances.

Dread's purpose is identical to slow, so let's borrow code from slow.

Code: Select all

static const std::string slow_string("slow");
	res.attacker_slows = res.attacker_special == slow_string;
would probably turn into

Code: Select all

static const std::string dread_string("dread");
	res.attacker_dreads= res.attacker_special == dread_string;
Simply exchanging the word 'slow' with 'dread' because we basically want the same effect so why not borrow from slow...

Code: Select all

if (a->second.slowed()) {
		divisor *= 2;

		if (strings) {
			std::stringstream str;
			str << _("slowed") << EMPTY_COLUMN << _("Halved");
			strings->attack_calculations.push_back(str.str());
		}
Again to convert to dread, just replace 'slow' with 'dread' everywhere it is listed in this block of code. We still want the exact same effect, what we need to change is the 'how is it applied' timing.

Looks like the code for how 'slow' causes unit damaged to be 'halved'.
Looks like it invokes a lot of other functions too...
Hmm..
I didn't see where the code determines how a unit becomes labeled with 'slow'.
This second bit of code explains what to do with a unit's attack power if it is slowed (halve it), but doesn't seem to deal with afflicting said unit with 'slow', if I'm reading it right.

Where is the code for how an attacking unit attaches the 'slow' effect unto another unit?
Actually... that first bit of code I cut and pasted looks like it might be it...
Is there a way to tell the game to apply this 'slow' (half damage) effect simply by initiating combat instead of applying it after the attacker with the 'slow' ability lands a blow?
We don't need to change slow's affect, we want the damage to be halved, but we need to change the timing of it's application and would also need to remove it at the conclusion of the round of combat.

Would have to modify that code to fit dread...
Instead of the defender needing to be hit with slow, dread would be applied before the first blow is landed, and it would also need to be removed after the defenders last attack.

One question... should it stack with slow? I say why not, but this could be an issue.
"A wise man speaks when he has something to say. A fool speaks when he has to say something."
SmokemJags
Posts: 580
Joined: February 14th, 2006, 3:24 am
Location: New Avalon
Contact:

Post by SmokemJags »

Writing it out in 'psuedo' code...

Code: Select all

static const std::string slow_string("slow"); 
   res.attacker_slows = res.attacker_special == slow_string;
Says:
Attacker afflicts target with slow (attacker_slows) is (=) attacker special is the same as (==) slow spell (slow_string)
I think...

Dread code would need to say...

If
Attacker special is dread
Then apply 'dread' [half damage] to defender's retaliation[attack]

Hmm...
Specials like slow and poison rely on a target being struck to apply.
But charge doesn't, it double an attackers (and defenders) damage simply if the attacker is initiating combat.
So let's look at charge code...

Code: Select all

if (charge) {
			bonus *= 2;

			if (strings) {
				std::stringstream str;
				str << _("charge") << EMPTY_COLUMN << _("Doubled");
				strings->defend_calculations.push_back(str.str());
			}
		}

		if (d->second.slowed()) {
			divisor *= 2;
			if (strings) {
				std::stringstream str;
				str << _("slowed") << EMPTY_COLUMN << _("Halved");
				strings->defend_calculations.push_back(str.str());
			}

Actually, looking at charge right next to slow makes a lot of sense. Let's see if I can't make dread out of the two of them...
Last edited by SmokemJags on March 11th, 2006, 12:05 pm, edited 1 time in total.
"A wise man speaks when he has something to say. A fool speaks when he has to say something."
SmokemJags
Posts: 580
Joined: February 14th, 2006, 3:24 am
Location: New Avalon
Contact:

Post by SmokemJags »

I noticed the charge code doesn't have the 'a' or 'd' notation that slow carries. It simply is 'if charge'
A and D must be Attacker and Defender, and since charge has neither it must automatically apply to both, not needing seperate definitions... (when an attacker has 'charge' both attacker and defender deal double damage. When an attacker has 'slow' the attacker and defender do NOT both deal half damage. Makes sense.)

Keeping this in mind...

Code: Select all

if (a->second.slowed()) {
		divisor *= 2;

		if (strings) {
			std::stringstream str;
			str << _("slowed") << EMPTY_COLUMN << _("Halved");
			strings->attack_calculations.push_back(str.str());
		}
Says attacker is slowed, attacker deals half damage.

Code: Select all

if (d->second.slowed()) {
			divisor *= 2;
			if (strings) {
				std::stringstream str;
				str << _("slowed") << EMPTY_COLUMN << _("Halved");
				strings->defend_calculations.push_back(str.str());
Says defender is slowed, defender deals half damage.

Is it possible to...

Code: Select all

if (a->second.dread()) { 
         divisor *= 2; 
         if (strings) { 
            std::stringstream str; 
            str << _("dreadful") << EMPTY_COLUMN << _("Halved"); 
            strings->defend_calculations.push_back(str.str()); 
         }
Now that code reads:
If attacker is afflicted with dread... defender will deal half damage!

Think of the shadow's ability for... what's it called... nightstalk. Whatever makes him invisible.
Dread would be just like that.
The shadow's invisibility is always on... during the night and if he doesn't attack.
Dread would be always on period. It wouldn't ever go away.
And it's effect?
'D' defender would always deal half damage when in combat with a unit possessing/afflicted by 'dread'.
Sounds perfect, in theory. Unfortunately I don't know how to write that code... :P

Question... :?: if that code could be made to work... would a unit attacking a Draug label the Draug as 'D' (defender) and halve his damage?
If that's the case... the unit would need a string exception that checks...
If 'D' Defender == Unit Draug, do not halve damage.

But that raises the question... what if a draug attacks another draug?
My answer? Undead should be immune to 'dread' just like they are immune to 'poison'. It just makes sense. A skeleton... afraid? Nope.
So this works in a code sense and a gameplay explanation of why draugs attacking draugs don't have any halving damage applied.
"A wise man speaks when he has something to say. A fool speaks when he has to say something."
SmokemJags
Posts: 580
Joined: February 14th, 2006, 3:24 am
Location: New Avalon
Contact:

Post by SmokemJags »

The first three posts are my train of thought and some brainstorming, this fourth one is the conclusion of those thoughts.

The code that says:
Attacker has ability/is afflicted by dread.
Defender deal half damage.

Code: Select all

if (a->second.dread()) { 
         divisor *= 2; 
         if (strings) { 
            std::stringstream str; 
            str << _("dreadful") << EMPTY_COLUMN << _("Halved"); 
            strings->defend_calculations.push_back(str.str()); 
         }
I think this is the code that is needed to 'define' dread.

Code: Select all

static const std::string dread_string("dread");
	res.attacker_dreadful = res.attacker_special == dread_string;
Some problems I need help with:
A. Those two pieces of code deal with 'dread' as a weapon 'special' like charge or slow or backstab.
B. I need the code for the ability 'nightstalk'... I think 'dread' should be an ability not a weapon special... though I suppose it could work as either.
Change nightstalk from saying:
The unit becomes invisible during night....
To:
When this unit attacks, the defending unit deals half damage.
And rewrite the nightstalk code to reflect that change.
C. Apply the tweaks seen in the first block of code in this post (attacker has dread, defender deals half damage) to the ability of dread, not the weapon special dread.

Or maybe it would simply work as a weapon special if I designed it like charge... charge certainly is a weapon special that deals with altering damage yet doesn't require units to be afflicted by it...
I dunno, could use a little help and suggestions at this point.
"A wise man speaks when he has something to say. A fool speaks when he has to say something."
User avatar
Tomsik
Posts: 1401
Joined: February 7th, 2005, 7:04 am
Location: Poland

Post by Tomsik »

Here's little patch with dread weapon special(if you don't count compiling it took me around 2 minutes). Why weapon special? Because i don't think somebody would fear to shoot fireball at him if he would somehow get ranged attack. I think it needs better name, but here it is:
Attachments
dread.patch.txt
remove .txt
(1007 Bytes) Downloaded 945 times
User avatar
Noyga
Inactive Developer
Posts: 1790
Joined: September 26th, 2005, 5:56 pm
Location: France

Post by Noyga »

Since it's more C++ oriented than WML oriented, i moved the thread in IMO a more appropriate forum.

Well about nightstalk, it is in fact the "hides" ability (common to nightstalk & ambush).
Some abilities use terrain/ToD filters defined in unit_type.cpp. Not all filter are wired yet, btw the entire unit classes are being entirely rewritten by Xan, so this stuff should probably change soon.
SmokemJags
Posts: 580
Joined: February 14th, 2006, 3:24 am
Location: New Avalon
Contact:

Post by SmokemJags »

Still pulling teeth, but at least progress is being made. :roll:

Okay so it's a patch to give the draug this weapon special.
How exactly do you apply this patch?
Somehow removing .txt isn't helpful enough.
Knowing what to do with dread.patch and where to put it might be helpful.
"A wise man speaks when he has something to say. A fool speaks when he has to say something."
Post Reply