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
=== modified file 'src/include/unittype.h'
--- src/include/unittype.h 2013-05-08 12:10:35 +0000
+++ src/include/unittype.h 2013-06-05 09:54:39 +0000
@@ -408,6 +408,7 @@
408 int Distance; /// distance to build (circle)408 int Distance; /// distance to build (circle)
409 DistanceTypeType DistanceType;409 DistanceTypeType DistanceType;
410 std::string RestrictTypeName;410 std::string RestrictTypeName;
411 std::string RestrictTypeOwner;
411 CUnitType *RestrictType;412 CUnitType *RestrictType;
412};413};
413414
414415
=== modified file 'src/unit/build.cpp'
--- src/unit/build.cpp 2013-04-26 13:04:33 +0000
+++ src/unit/build.cpp 2013-06-05 09:54:39 +0000
@@ -134,43 +134,45 @@
134 std::vector<CUnit *> table;134 std::vector<CUnit *> table;
135 Select(pos1, pos2, table);135 Select(pos1, pos2, table);
136136
137 switch (this->DistanceType) {137 for (size_t i = 0; i != table.size(); ++i) {
138 case GreaterThan :138 if (builder != table[i] &&
139 case GreaterThanEqual :139 // unit has RestrictType or no RestrictType was set, but a RestrictTypeOwner
140 for (size_t i = 0; i != table.size(); ++i) {140 (this->RestrictType == table[i]->Type || !this->RestrictType && this->RestrictTypeOwner.size() > 0) &&
141 if (builder != table[i] && this->RestrictType == table[i]->Type &&141 // RestrictTypeOwner is not set or unit belongs to a suitable player
142 MapDistanceBetweenTypes(type, pos, *table[i]->Type, table[i]->tilePos) <= distance) {142 (this->RestrictTypeOwner.size() == 0 ||
143 return false;143 !this->RestrictTypeOwner.compare("self") && ThisPlayer == table[i]->Player ||
144 }144 !this->RestrictTypeOwner.compare("allied") && (ThisPlayer == table[i]->Player || ThisPlayer->IsAllied(*table[i]->Player)) ||
145 }145 !this->RestrictTypeOwner.compare("enemy") && ThisPlayer->IsEnemy(*table[i]->Player))) {
146 return true;146
147 case LessThan :147 switch (this->DistanceType) {
148 case LessThanEqual :148 case GreaterThan :
149 for (size_t i = 0; i != table.size(); ++i) {149 case GreaterThanEqual :
150 if (builder != table[i] && this->RestrictType == table[i]->Type &&150 if (MapDistanceBetweenTypes(type, pos, *table[i]->Type, table[i]->tilePos) <= distance) {
151 MapDistanceBetweenTypes(type, pos, *table[i]->Type, table[i]->tilePos) <= distance) {151 return false;
152 return true;152 }
153 }153 break;
154 }154 case LessThan :
155 return false;155 case LessThanEqual :
156 case Equal :156 if (MapDistanceBetweenTypes(type, pos, *table[i]->Type, table[i]->tilePos) <= distance) {
157 for (size_t i = 0; i != table.size(); ++i) {157 return true;
158 if (builder != table[i] && this->RestrictType == table[i]->Type &&158 }
159 MapDistanceBetweenTypes(type, pos, *table[i]->Type, table[i]->tilePos) == distance) {159 break;
160 return true;160 case Equal :
161 }161 if (MapDistanceBetweenTypes(type, pos, *table[i]->Type, table[i]->tilePos) == distance) {
162 }162 return true;
163 return false;163 }
164 case NotEqual :164 break;
165 for (size_t i = 0; i != table.size(); ++i) {165 case NotEqual :
166 if (builder != table[i] && this->RestrictType == table[i]->Type &&166 if (MapDistanceBetweenTypes(type, pos, *table[i]->Type, table[i]->tilePos) == distance) {
167 MapDistanceBetweenTypes(type, pos, *table[i]->Type, table[i]->tilePos) == distance) {167 return false;
168 return false;168 }
169 }169 break;
170 }170 }
171 return true;171 }
172 }172 }
173 return false;173 return (this->DistanceType == GreaterThan ||
174 this->DistanceType == GreaterThanEqual ||
175 this->DistanceType == NotEqual);
174}176}
175177
176inline bool CBuildRestrictionAddOn::functor::operator()(const CUnit *const unit) const178inline bool CBuildRestrictionAddOn::functor::operator()(const CUnit *const unit) const
177179
=== modified file 'src/unit/script_unittype.cpp'
--- src/unit/script_unittype.cpp 2013-05-08 12:10:35 +0000
+++ src/unit/script_unittype.cpp 2013-06-05 09:54:39 +0000
@@ -254,6 +254,8 @@
254 }254 }
255 } else if (!strcmp(value, "Type")) {255 } else if (!strcmp(value, "Type")) {
256 b->RestrictTypeName = LuaToString(l, -1);256 b->RestrictTypeName = LuaToString(l, -1);
257 } else if (!strcmp(value, "Owner")) {
258 b->RestrictTypeOwner = LuaToString(l, -1);
257 } else {259 } else {
258 LuaError(l, "Unsupported BuildingRules distance tag: %s" _C_ value);260 LuaError(l, "Unsupported BuildingRules distance tag: %s" _C_ value);
259 }261 }

Subscribers

People subscribed via source and target branches

to status/vote changes: