Defensive Structure Experience
-
EvgenijM86
- Rookie

- Posts: 16
- Joined: 30 Apr 2010, 22:39
Re: Defensive Structure Experience
Actually, I already added the same mechanic from droids to structures when it comes to experience (except for recycling and bonuses from commanders). They do gain experience and receive all bonuses from it, with a visible icon. If anyone on dev team is interested I can submit a diff file for current trunk. All code added code have a comment that starts with my nickname for easy searching.
Edit: thinking of adding range increase bonus instead of bonus to avoidance. Avoidance bonus does not make much sense for turrets, because they are usually behind walls or clustered closely to each other. Even if projectile miss - it will still hit a wall or other structure. What bonuses would you like to see?
Edit: thinking of adding range increase bonus instead of bonus to avoidance. Avoidance bonus does not make much sense for turrets, because they are usually behind walls or clustered closely to each other. Even if projectile miss - it will still hit a wall or other structure. What bonuses would you like to see?
-
Emdek
- Regular

- Posts: 1329
- Joined: 24 Jan 2010, 13:14
- Location: Poland
Re: Defensive Structure Experience
You can attach diff to at least give chance to test it by others. 
Nadszedł już czas, najwyższy czas, nienawiść zniszczyć w sobie.
The time has come, the high time, to destroy hatred in oneself.
Beware! Mad Qt Evangelist.
The time has come, the high time, to destroy hatred in oneself.
Beware! Mad Qt Evangelist.
-
KukY
- Regular

- Posts: 1859
- Joined: 20 Mar 2009, 21:56
Re: Defensive Structure Experience
Yeah, please attach it. Bonuses? Well, only damage and HP bonuses are enough.
-
EvgenijM86
- Rookie

- Posts: 16
- Joined: 30 Apr 2010, 22:39
Re: Defensive Structure Experience
ok - here is the diff file (for 10853 version of current trunk):
Code: Select all
Index: src/projectile.c
===================================================================
--- src/projectile.c (revision 10855)
+++ src/projectile.c (working copy)
@@ -59,6 +59,7 @@
#include "multistat.h"
#include "mapgrid.h"
#include "random.h"
+#include "structuredef.h" //EvgenijM86 structure experience mod
#define VTOL_HITBOX_MODIFICATOR 100
@@ -316,6 +317,9 @@
{
psDroid->experience += experienceInc;
}Droid
+
+ //EvgenijM86 structure experience mod
+ ((STRUCTURE *)psObj->psSource)->experience += experienceInc;
}
}
Index: src/combat.c
===================================================================
--- src/combat.c (revision 10855)
+++ src/combat.c (working copy)
@@ -35,6 +35,7 @@
#include "mapgrid.h"
#include "projectile.h"
#include "random.h"
+#include "structure.h"
// maximum random pause for firing
#define RANDOM_PAUSE 500
@@ -237,6 +238,11 @@
// increase total accuracy by EXP_ACCURACY_BONUS % for each experience level
resultHitChance += EXP_ACCURACY_BONUS * level * baseHitChance / 100;
}
+ else //EvgenijM86 structure experience mod
+ {
+ SDWORD level = getStructureLevel((STRUCTURE *) psAttacker);
+ resultHitChance += EXP_ACCURACY_BONUS * level * baseHitChance / 100;
+ }
// subtract the defender's experience
if (psTarget->type == OBJ_DROID)
@@ -245,8 +251,12 @@
// decrease weapon accuracy by EXP_ACCURACY_BONUS % for each experience level
resultHitChance -= EXP_ACCURACY_BONUS * level * baseHitChance / 100;
-
}
+ else //EvgenijM86 structure experience mod
+ {
+ SDWORD level = getStructureLevel((STRUCTURE *) psTarget);
+ resultHitChance -= EXP_ACCURACY_BONUS * level * baseHitChance / 100;
+ }
// fire while moving modifiers
if (psAttacker->type == OBJ_DROID &&
@@ -579,6 +589,11 @@
// Retrieve highest, applicable, experience level
level = getDroidEffectiveLevel(psDroid);
}
+ else //EvgenijM86 structure experience mod
+ {
+ STRUCTURE *psStructure = (STRUCTURE *)psTarget;
+ level = getStructureLevel(psStructure);
+ }
// Reduce damage taken by EXP_REDUCE_DAMAGE % for each experience level
actualDamage = (damage * (100 - EXP_REDUCE_DAMAGE * level)) / 100;
Index: src/display3d.h
===================================================================
--- src/display3d.h (revision 10855)
+++ src/display3d.h (working copy)
@@ -130,6 +130,9 @@
/* Visualize radius at position */
extern void showRangeAtPos(SDWORD centerX, SDWORD centerY, SDWORD radius);
+//EvgenijM86 structure experience mod
+extern UDWORD getStructureRankGraphic(STRUCTURE *psStructure);
+
#define BASE_MUZZLE_FLASH_DURATION (GAME_TICKS_PER_SEC/10)
#define EFFECT_MUZZLE_ADDITIVE 128
Index: src/display3d.c
===================================================================
--- src/display3d.c (revision 10855)
+++ src/display3d.c (working copy)
@@ -133,6 +133,10 @@
static void NetworkDisplayPlainForm(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, WZ_DECL_UNUSED PIELIGHT *pColours);
static void NetworkDisplayImage(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, WZ_DECL_UNUSED PIELIGHT *pColours);
+
+//EvgenijM86 structure experience mod
+static void drawStructureRank(STRUCTURE *psStructure);
+
/******************** Variables ********************/
// Should be cleaned up properly and be put in structures.
@@ -2915,6 +2919,12 @@
pie_BoxFill(scrX-scrR-1, scrY-1, scrX+scrR+1, scrY+3, WZCOL_RELOAD_BACKGROUND);
pie_BoxFill(scrX-scrR, scrY, scrX-scrR+health, scrY+1, powerCol);
pie_BoxFill(scrX-scrR, scrY+1, scrX-scrR+health, scrY+2, powerColShadow);
+
+ //EvgenijM86 structure experience mod
+ if((scrX+scrR)>0 && (scrY+scrR)>0 && (scrX-scrR) < pie_GetVideoBufferWidth() && (scrY-scrR) < pie_GetVideoBufferHeight())
+ {
+ drawStructureRank(psStruct);
+ }
}
/// draw the construction bar for the specified structure
@@ -4296,3 +4306,59 @@
pie_TransColouredTriangle(pts, colour);
}
+
+//EvgenijM86 structure experience mod
+UDWORD getStructureRankGraphic(STRUCTURE *psStructure)
+{
+ UDWORD gfxId;
+ /* Not found yet */
+ gfxId = UDWORD_MAX;
+
+ /* Establish the numerical value of the structure's rank */
+ switch(getStructureLevel(psStructure))
+ {
+ case 0:
+ break;
+ case 1:
+ gfxId = IMAGE_LEV_0;
+ break;
+ case 2:
+ gfxId = IMAGE_LEV_1;
+ break;
+ case 3:
+ gfxId = IMAGE_LEV_2;
+ break;
+ case 4:
+ gfxId = IMAGE_LEV_3;
+ break;
+ case 5:
+ gfxId = IMAGE_LEV_4;
+ break;
+ case 6:
+ gfxId = IMAGE_LEV_5;
+ break;
+ case 7:
+ gfxId = IMAGE_LEV_6;
+ break;
+ case 8:
+ gfxId = IMAGE_LEV_7;
+ break;
+ default:
+ ASSERT(!"out of range structure rank", "Weird structure level in drawDroidRank");
+ break;
+ }
+
+ return gfxId;
+}
+
+static void drawStructureRank(STRUCTURE *psStructure)
+{
+ UDWORD gfxId = getStructureRankGraphic(psStructure);
+
+ /* Did we get one? - We should have... */
+ if(gfxId!=UDWORD_MAX)
+ {
+ /* Render the rank graphic at the correct location */ // remove hardcoded numbers?!
+ iV_DrawImage(IntImages,(UWORD)gfxId,psStructure->sDisplay.screenX+20,psStructure->sDisplay.screenY+8);
+ }
+}
Index: src/structure.h
===================================================================
--- src/structure.h (revision 10855)
+++ src/structure.h (working copy)
@@ -413,6 +413,9 @@
BOOL structureCheckReferences(STRUCTURE *psVictimStruct);
+//EvgenijM86 structure experience mod
+extern UDWORD getStructureLevel(STRUCTURE *psStructure);
+
static inline int structSensorRange(const STRUCTURE* psObj)
{
return objSensorRange((const BASE_OBJECT*)psObj);
Index: src/structuredef.h
===================================================================
--- src/structuredef.h (revision 10855)
+++ src/structuredef.h (working copy)
@@ -310,6 +310,9 @@
STRUCT_ANIM_STATES state;
UDWORD lastStateTime;
+
+ //EvgenijM86 structure experience mod
+ float experience;
} WZ_DECL_MAY_ALIAS STRUCTURE;
#define LOTS_OF 255 /*highest number the limit can be set to */
Index: src/structure.c
===================================================================
--- src/structure.c (revision 10855)
+++ src/structure.c (working copy)
@@ -1860,6 +1860,8 @@
psBuilding->body = (UWORD)structureBody(psBuilding);
psBuilding->expectedDamage = 0; // Begin life optimistically.
+ psBuilding->experience = 0; //EvgenijM86 structure experience mod
+
//add the structure to the list - this enables it to be drawn whilst being built
addStructure(psBuilding);
@@ -8113,3 +8115,43 @@
}
}
}
+
+//EvgenijM86 structure experience mod
+struct rankMap
+{
+ unsigned int kills; // required minimum amount of kills to reach this rank
+ const char* name; // name of this rank
+};
+
+static const struct rankMap arrRank[] =
+{
+ {0, N_("Rookie")},
+ {4, NP_("rank", "Green")},
+ {8, N_("Trained")},
+ {16, N_("Regular")},
+ {32, N_("Professional")},
+ {64, N_("Veteran")},
+ {128, N_("Elite")},
+ {256, N_("Special")},
+ {512, N_("Hero")}
+};
+
+UDWORD getStructureLevel(STRUCTURE *psStructure)
+{
+ unsigned int numKills = psStructure->experience;
+ unsigned int i;
+
+ // Search through the array of ranks until one is found
+ // which requires more kills than the droid has.
+ // Then fall back to the previous rank.
+ for (i = 1; i < ARRAY_SIZE(arrRank); ++i)
+ {
+ if (numKills < arrRank[i].kills)
+ {
+ return i - 1;
+ }
+ }
+
+ // If the criteria of the last rank are met, then select the last one
+ return ARRAY_SIZE(arrRank) - 1;
+}
You do not have the required permissions to view the files attached to this post.
-
KukY
- Regular

- Posts: 1859
- Joined: 20 Mar 2009, 21:56
Re: Defensive Structure Experience
Thanks, wiill test.
-
Zarel
- Elite

- Posts: 5770
- Joined: 03 Jan 2008, 23:35
- Location: Minnesota, USA
Re: Defensive Structure Experience
For future reference, please do not do this. We have SVN commit logs and SVN annotation to figure out where code comes from. Adding your name just clutters up the code.EvgenijM86 wrote:All code added code have a comment that starts with my nickname for easy searching.
-
EvgenijM86
- Rookie

- Posts: 16
- Joined: 30 Apr 2010, 22:39
Re: Defensive Structure Experience
Thank you, did not know this.Zarel wrote:For future reference, please do not do this. We have SVN commit logs and SVN annotation to figure out where code comes from. Adding your name just clutters up the code.EvgenijM86 wrote:All code added code have a comment that starts with my nickname for easy searching.
-
EvgenijM86
- Rookie

- Posts: 16
- Joined: 30 Apr 2010, 22:39
Re: Defensive Structure Experience
I want to implement range increase bonus. It seems that most functions related to acquiring targets use this function, instead of directly accessing weapon stats for range:
SDWORD proj_GetLongRange(const WEAPON_STATS* psStats)
{
return psStats->longRange;
}
Is it ok for me to modify this function to pass pointer to the one who shoots, so I can get his experience? Previously I only tried to add my own code without modifying any function headers, because that changes interface and I don't really know if it's a good thing.
Another idea is to add another function - proj_getEffectiveLongRange and replace all calls to the one above with it. Inside of it we can get range by using proj_GetLongRange and apply bonuses after.
SDWORD proj_GetLongRange(const WEAPON_STATS* psStats)
{
return psStats->longRange;
}
Is it ok for me to modify this function to pass pointer to the one who shoots, so I can get his experience? Previously I only tried to add my own code without modifying any function headers, because that changes interface and I don't really know if it's a good thing.
Another idea is to add another function - proj_getEffectiveLongRange and replace all calls to the one above with it. Inside of it we can get range by using proj_GetLongRange and apply bonuses after.
-
stiv
- Warzone 2100 Team Member

- Posts: 876
- Joined: 18 Jul 2008, 04:41
- Location: 45N 86W
Re: Defensive Structure Experience
This is probably a better approach since you are adding new functionality beyond a simple accessor function.Another idea is to add another function - proj_getEffectiveLongRange and replace all calls to the one above with it.
-
KukY
- Regular

- Posts: 1859
- Joined: 20 Mar 2009, 21:56
Re: Defensive Structure Experience
This won't work for me. 
-
Zarel
- Elite

- Posts: 5770
- Joined: 03 Jan 2008, 23:35
- Location: Minnesota, USA
Re: Defensive Structure Experience
...I thought the whole point of an accessor function was that you could add new functionality to it?stiv wrote:This is probably a better approach since you are adding new functionality beyond a simple accessor function.
-
EvgenijM86
- Rookie

- Posts: 16
- Joined: 30 Apr 2010, 22:39
Re: Defensive Structure Experience
Can you be more specific, please? Is it a compilation error? If so - what it says? Or it compiles and nothing changes?KukY wrote:This won't work for me.
Please note: the root directory for my patch is not src, but the directory "above" it.
I just did the following: backed up my work as patch file, did complete synchro with rep overwriting local changes, downloaded patch from website and applied it, launched game for test. And result is in image.
http://img441.imageshack.us/img441/6088/expmod.jpg
-
KukY
- Regular

- Posts: 1859
- Joined: 20 Mar 2009, 21:56
Re: Defensive Structure Experience
I did it all correctly, compile went wiithout errors, but in-game, nothing was noticable, accept game slowdown.
No icons showed, altough I am sure that my single hardpoint killed more then 40 units...
No icons showed, altough I am sure that my single hardpoint killed more then 40 units...
-
EvgenijM86
- Rookie

- Posts: 16
- Joined: 30 Apr 2010, 22:39
Re: Defensive Structure Experience
Can you make a diff file between current svn trunk and what you have (after using my patch)? They should be identical.KukY wrote:I did it all correctly, compile went wiithout errors, but in-game, nothing was noticable, accept game slowdown.
No icons showed, altough I am sure that my single hardpoint killed more then 40 units...
-
KukY
- Regular

- Posts: 1859
- Joined: 20 Mar 2009, 21:56
Re: Defensive Structure Experience
Wait...EvgenijM86 wrote:Can you make a diff file between current svn trunk and what you have (after using my patch)? They should be identical.
EDIT: Actually, I didn't apply the patch at all by mistake. Sorry.