Merge lp:~timfelgentreff/stratagus/distance-owner-rules into lp:stratagus

Proposed by timfelgentreff
Status: Merged
Merged at revision: 8747
Proposed branch: lp:~timfelgentreff/stratagus/distance-owner-rules
Merge into: lp:stratagus
Diff against target: 110 lines (+41/-36)
3 files modified
src/include/unittype.h (+1/-0)
src/unit/build.cpp (+38/-36)
src/unit/script_unittype.cpp (+2/-0)
To merge this branch: bzr merge lp:~timfelgentreff/stratagus/distance-owner-rules
Reviewer Review Type Date Requested Status
Kyran Jackson Approve
Review via email: mp+167492@code.launchpad.net

Description of the change

This extends distance rules for buildings so I can specify which owners the buildings to which I specify a distance can have. In WC1, this allows me to specify that all buildings can be next to my own buildings, walls can be at most 3 fields from allied buildings and so on.

To post a comment you must log in.
Revision history for this message
Kyran Jackson (erstmap) wrote :

Will existing scripts need to be modified?

Revision history for this message
timfelgentreff (timfelgentreff) wrote :

No, existing scripts continue to work. This is an additional option. If it isn't specified, the old behavior is used.

Revision history for this message
Kyran Jackson (erstmap) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/include/unittype.h'
2--- src/include/unittype.h 2013-05-08 12:10:35 +0000
3+++ src/include/unittype.h 2013-06-05 09:54:39 +0000
4@@ -408,6 +408,7 @@
5 int Distance; /// distance to build (circle)
6 DistanceTypeType DistanceType;
7 std::string RestrictTypeName;
8+ std::string RestrictTypeOwner;
9 CUnitType *RestrictType;
10 };
11
12
13=== modified file 'src/unit/build.cpp'
14--- src/unit/build.cpp 2013-04-26 13:04:33 +0000
15+++ src/unit/build.cpp 2013-06-05 09:54:39 +0000
16@@ -134,43 +134,45 @@
17 std::vector<CUnit *> table;
18 Select(pos1, pos2, table);
19
20- switch (this->DistanceType) {
21- case GreaterThan :
22- case GreaterThanEqual :
23- for (size_t i = 0; i != table.size(); ++i) {
24- if (builder != table[i] && this->RestrictType == table[i]->Type &&
25- MapDistanceBetweenTypes(type, pos, *table[i]->Type, table[i]->tilePos) <= distance) {
26- return false;
27- }
28- }
29- return true;
30- case LessThan :
31- case LessThanEqual :
32- for (size_t i = 0; i != table.size(); ++i) {
33- if (builder != table[i] && this->RestrictType == table[i]->Type &&
34- MapDistanceBetweenTypes(type, pos, *table[i]->Type, table[i]->tilePos) <= distance) {
35- return true;
36- }
37- }
38- return false;
39- case Equal :
40- for (size_t i = 0; i != table.size(); ++i) {
41- if (builder != table[i] && this->RestrictType == table[i]->Type &&
42- MapDistanceBetweenTypes(type, pos, *table[i]->Type, table[i]->tilePos) == distance) {
43- return true;
44- }
45- }
46- return false;
47- case NotEqual :
48- for (size_t i = 0; i != table.size(); ++i) {
49- if (builder != table[i] && this->RestrictType == table[i]->Type &&
50- MapDistanceBetweenTypes(type, pos, *table[i]->Type, table[i]->tilePos) == distance) {
51- return false;
52- }
53- }
54- return true;
55+ for (size_t i = 0; i != table.size(); ++i) {
56+ if (builder != table[i] &&
57+ // unit has RestrictType or no RestrictType was set, but a RestrictTypeOwner
58+ (this->RestrictType == table[i]->Type || !this->RestrictType && this->RestrictTypeOwner.size() > 0) &&
59+ // RestrictTypeOwner is not set or unit belongs to a suitable player
60+ (this->RestrictTypeOwner.size() == 0 ||
61+ !this->RestrictTypeOwner.compare("self") && ThisPlayer == table[i]->Player ||
62+ !this->RestrictTypeOwner.compare("allied") && (ThisPlayer == table[i]->Player || ThisPlayer->IsAllied(*table[i]->Player)) ||
63+ !this->RestrictTypeOwner.compare("enemy") && ThisPlayer->IsEnemy(*table[i]->Player))) {
64+
65+ switch (this->DistanceType) {
66+ case GreaterThan :
67+ case GreaterThanEqual :
68+ if (MapDistanceBetweenTypes(type, pos, *table[i]->Type, table[i]->tilePos) <= distance) {
69+ return false;
70+ }
71+ break;
72+ case LessThan :
73+ case LessThanEqual :
74+ if (MapDistanceBetweenTypes(type, pos, *table[i]->Type, table[i]->tilePos) <= distance) {
75+ return true;
76+ }
77+ break;
78+ case Equal :
79+ if (MapDistanceBetweenTypes(type, pos, *table[i]->Type, table[i]->tilePos) == distance) {
80+ return true;
81+ }
82+ break;
83+ case NotEqual :
84+ if (MapDistanceBetweenTypes(type, pos, *table[i]->Type, table[i]->tilePos) == distance) {
85+ return false;
86+ }
87+ break;
88+ }
89+ }
90 }
91- return false;
92+ return (this->DistanceType == GreaterThan ||
93+ this->DistanceType == GreaterThanEqual ||
94+ this->DistanceType == NotEqual);
95 }
96
97 inline bool CBuildRestrictionAddOn::functor::operator()(const CUnit *const unit) const
98
99=== modified file 'src/unit/script_unittype.cpp'
100--- src/unit/script_unittype.cpp 2013-05-08 12:10:35 +0000
101+++ src/unit/script_unittype.cpp 2013-06-05 09:54:39 +0000
102@@ -254,6 +254,8 @@
103 }
104 } else if (!strcmp(value, "Type")) {
105 b->RestrictTypeName = LuaToString(l, -1);
106+ } else if (!strcmp(value, "Owner")) {
107+ b->RestrictTypeOwner = LuaToString(l, -1);
108 } else {
109 LuaError(l, "Unsupported BuildingRules distance tag: %s" _C_ value);
110 }

Subscribers

People subscribed via source and target branches

to status/vote changes: