Advanced Strategic Command
resourcenet.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  resourcenet.cpp - description
3  -------------------
4  begin : Tue Jan 28 2001
5  copyright : (C) 2001 by Martin Bickel
6  email : bickel@asc-hq.org
7  ***************************************************************************/
8 
13 /***************************************************************************
14  * *
15  * This program is free software; you can redistribute it and/or modify *
16  * it under the terms of the GNU General Public License as published by *
17  * the Free Software Foundation; either version 2 of the License, or *
18  * (at your option) any later version. *
19  * *
20  ***************************************************************************/
21 
22 #include "typen.h"
23 #include "vehicletype.h"
24 #include "buildingtype.h"
25 #include "spfst.h"
26 #include "resourcenet.h"
27 #include "mapalgorithms.h"
28 #include "dlg_box.h"
29 #include "dialog.h"
30 #include "cannedmessages.h"
31 
32 sigc::signal<void> tributeTransferred;
33 
34 void MapNetwork :: searchfield ( int x, int y, int dir )
35 {
36  int s;
37 
38  MapField* fld = actmap->getField ( x, y );
39  if ( !fld )
40  return;
41 
42  int arr[sidenum];
43 
44  do {
45 
46  if ( fld->getaTemp() )
47  return;
48 
49  #ifdef netdebug
50  cursor.gotoxy ( a, b );
51  displaymap();
52  #endif
53 
54  if ( fld->building ) {
55  searchbuilding ( x, y );
56  return;
57  }
58 
59  fld->setaTemp(1);
60 
61  int d = fieldavail( x, y );
62  if ( d <= 0 )
63  return;
64 
65  searchvehicle ( x, y );
66 
67  int olddir = dir + sidenum/2;
68  while (olddir >= sidenum )
69  olddir -= sidenum;
70 
71  int r = 0;
72  for (s = 0; s < sidenum; s++) {
73  if ( (d & (1 << s)) && ( s != olddir )) {
74  arr[ r ] = s;
75  r++;
76  }
77  }
78 
79 
80  if (r > 1) { // Kreuzungsstelle
81  for ( s = 0; s < r; s++) {
82  int nx = x;
83  int ny = y;
84  int direc = arr[s];
85  nx += getnextdx ( direc, ny );
86  ny += getnextdy ( direc );
87  searchfield( nx, ny, direc );
88  if ( searchfinished() )
89  return ;
90  }
91  return;
92  } else
93  if ( r == 1 ) {
94  dir = arr[0];
95  x += getnextdx ( dir, y );
96  y += getnextdy ( dir );
97  fld = actmap->getField( x, y );
98  if ( !fld )
99  return;
100  } else
101  return;
102  } while ( 1 );
103 
104 }
105 
106 void MapNetwork :: searchvehicle ( int x, int y )
107 {
108  if ( pass == 2 ) {
109  MapField* newfield = actmap->getField ( x, y );
110  if ( newfield )
111  if ( !newfield->getaTemp2() )
112  if ( newfield->vehicle ) {
113  checkvehicle ( newfield->vehicle );
114  newfield->setaTemp2(1);
115  }
116  }
117 }
118 
119 
120 void MapNetwork :: searchbuilding ( int x, int y )
121 {
122  Building* bld = actmap->getField( x, y )->building;
123  if ( !bld )
124  return;
125 
126  MapField* entry = bld->getEntryField();
127  if ( entry->getaTemp() )
128  return;
129 
130  if ( pass == 1 )
131  checkbuilding( bld );
132 
133  entry->setaTemp(1);
134 
135  if ( !searchfinished() )
136  for( int i = 0; i < 4; i++ )
137  for ( int j = 0; j < 6; j++ ) {
139  MapField* fld2 = actmap->getField ( mc );
140  if ( fld2 && fld2->building == bld )
141  for ( int d = 0; d < sidenum; d++ ) {
142  int xp2 = mc.x;
143  int yp2 = mc.y;
144  xp2 += getnextdx ( d, yp2 );
145  yp2 += getnextdy ( d );
146  MapField* newfield = actmap->getField ( xp2, yp2 );
147  if ( newfield && newfield->building != bld && !newfield->getaTemp() )
148  searchfield ( xp2, yp2, d );
149 
150  searchvehicle ( xp2, yp2 );
151 
152  } /* endfor */
153  }
154 }
155 
156 
157 int MapNetwork :: instancesrunning = 0;
158 
159 MapNetwork :: MapNetwork ( GameMap* gamemap, int checkInstances ) : actmap ( gamemap )
160 {
161  if ( checkInstances ) {
162  if ( instancesrunning )
163  displaymessage(" fatal error at MapNetwork; there are other running instances ", 2 );
164  }
165  // else displaymessage("warning: Mapnetwork instance check disabled !", 1 );
166 // this could be resolved by using the different bits of field->a.temp
167 
168  instancesrunning++;
169  pass = 1;
170 }
171 
172 
174 {
175  instancesrunning--;
176 }
177 
178 
179 
181 {
182  pass++;
183  for ( Player::VehicleList::iterator j = actmap->player[player].vehicleList.begin(); j != actmap->player[player].vehicleList.end(); j++ ) {
184  MapCoordinate3D mc = (*j)->getPosition();
185  for ( int s = 0; s < sidenum; s++ ) {
187  if ( fld ) {
188  Building* bld = fld->building;
189  if ( bld && bld->color == (*j)->color ) {
190  MapField* fld2 = actmap->getField( (*j)->getPosition());
191  if ( !fld2->getaTemp2() ) {
192  fld2->setaTemp2(1);
193  checkvehicle ( *j );
194  }
195  }
196  }
197  }
198  }
199 }
200 
201 void MapNetwork :: start ( int x, int y )
202 {
203  if ( globalsearch() == 2 ) {
204  for ( int i = 0; i < 8; i++ )
205  if ( actmap->player[i].exist() ) {
206 
207  for ( Player::BuildingList::iterator j = actmap->player[i].buildingList.begin(); j != actmap->player[i].buildingList.end(); j++ )
208  checkbuilding(*j);
209 
210  // if ( !searchfinished() )
211  actmap->cleartemps(7);
213  actmap->cleartemps(7);
214 
215  }
216  } else
217  if ( globalsearch() == 1 ) {
218  actmap->cleartemps(7);
219  startposition.x = x;
220  startposition.y = y;
221  searchfield ( x, y, -1 );
222  actmap->cleartemps(7);
223  if ( !searchfinished() ) {
224  pass++;
225  startposition.x = x;
226  startposition.y = y;
227  searchfield ( x, y, -1 );
228  actmap->cleartemps(7);
229  }
230  } else
231  if ( globalsearch() == 0 ) {
232  MapField* fld = actmap->getField ( x, y );
233  if ( fld ) {
234  if ( fld->building ) {
235  if ( pass == 1 )
236  checkbuilding( fld->building );
237  } else
238  if ( fld->vehicle )
239 
240  if ( pass == 2 )
241  checkvehicle ( fld->vehicle );
242  }
243  }
244 }
245 
246 
247 
248 int ResourceNet :: fieldavail ( int x, int y )
249 {
250  MapField* fld = actmap->getField ( x, y );
251 /* Object* o = fld->checkforobject ( pipelineobject ) ;
252  if ( o )
253  return o->dir;
254  else */
255 
256  if ( fld ) {
258  assert( resourcetype >= 0 );
259 
260  if ( resourcetype == 0)
262 
263  if ( (fld->bdt & tb).any() ) {
264  int d = 0;
265  for ( int i = 0; i < sidenum; i++ ) {
266  int xp = x;
267  int yp = y;
268  xp += getnextdx ( i, yp );
269  yp += getnextdy ( i );
270  MapField* fld2 = actmap->getField ( xp, yp );
271  if ( fld2 )
272  if ( (fld2->bdt & tb).any() || fld2->building )
273  d |= ( 1 << i );
274  }
275  return d;
276 
277  } else
278  return 0;
279  }
280  return 0;
281 
282 }
283 
284 
285 int StaticResourceNet :: getresource ( int x, int y, int resource, int _need, int _queryonly, int _player, int _scope )
286 {
287  if ( actmap->isResourceGlobal ( resource ))
288  scope = 3;
289  else
290  scope = _scope;
291 
292  player = _player;
293  resourcetype = resource;
294  got = 0;
295  need = _need;
296  queryonly = _queryonly;
297 
298  if (scope == 3 && player == 8 ) // neutral player has no map-wide pool
299  scope = 0;
300 
301  start ( x , y );
302  return got;
303 }
304 
305 
307 {
308  return got >= need;
309 }
310 
311 
312 
313 
314 
315 GetResource :: GetResource ( GameMap* gamemap, int scope )
316  : StaticResourceNet ( gamemap, scope )
317 {
318  memset ( tributegot, 0, sizeof ( tributegot ));
319 }
320 
321 
323 {
324  if ( v->color/8 == player && resourcetype == 0 )
326 }
327 
328 
330 {
331  if ( b->color/8 == player ) {
332  if ((b->netcontrol & (cnet_stopenergyoutput << resourcetype)) == 0) {
333  int toget = need-got;
334  if ( b->actstorage.resource( resourcetype ) < 0 ) {
335  displaymessage("map corruption detected; building %s storage for %d/%d is negative!",1,resourceNames[resourcetype],b->getEntry().x, b->getEntry().y );
336  b->actstorage.resource( resourcetype ) = 0;
337  }
338 
339 
340  if ( b->actstorage.resource( resourcetype ) < toget )
341  toget = b->actstorage.resource( resourcetype );
342 
343  if ( !queryonly )
344  b->actstorage.resource( resourcetype ) -= toget;
345  got += toget;
346  }
347  } else
348  if ( b->color/8 < 8 ) { // no neutral buildings
349 
350  // Codeguard reports "Pointer arithmetic in invalid memory". Whats wrong here ?
351  // Resources tttt = actmap->tribute.avail[ b->color / 8 ][ player ];
352  int gettable = actmap->tribute.avail[ b->color / 8 ][ player ].resource(resourcetype) - tributegot[ resourcetype ][ b->color / 8];
353  if ( gettable > 0 ) {
354  int toget = need-got;
355  if ( toget > gettable )
356  toget = gettable;
357 
358  // int found = b->getResource( toget, resourcetype, queryonly );
359  int found = b->actstorage.resource(resourcetype);
360  if ( toget < found )
361  found = toget;
362 
363  if ( !queryonly )
364  b->actstorage.resource(resourcetype) -= found;
365 
366  tributegot[ resourcetype ][ b->color / 8] += found;
367 
368  if ( !queryonly ) {
369  actmap->tribute.avail[ b->color / 8 ][ player ].resource( resourcetype ) -= found;
370  actmap->tribute.paid [ player ][ b->color / 8 ].resource( resourcetype ) += found;
371  if ( found )
373  }
374 
375  got += found;
376  }
377  }
378 }
379 
380 void GetResource :: start ( int x, int y )
381 {
382  if ( scope == 3 ) {
383  got = need;
386 
387  if ( !queryonly )
389 
390  if ( resourcetype == 0 )
392 
393  } else
394  MapNetwork :: start ( x, y );
395 }
396 
397 
398 
399 
400 
401 
402 
403 
405 {
406  if ( b->color/8 == player ) {
407  if ((b->netcontrol & (cnet_stopenergyinput << resourcetype)) == 0) {
408  int tostore = need-got;
409 
410  if ( b->actstorage.resource( resourcetype ) < 0 ) {
411  displaymessage("map corruption detected; building %s storage for %d/%d is negative!",1,resourceNames[resourcetype],b->getEntry().x, b->getEntry().y );
412  b->actstorage.resource( resourcetype ) = 0;
413  }
414 
417 
418  if ( !queryonly )
419  b->actstorage.resource( resourcetype ) += tostore;
420  got += tostore;
421  }
422  }
423 }
424 
425 
426 void PutResource :: start ( int x, int y )
427 {
428  if ( scope == 3 ) {
429 
430  got = need;
433 
434  if ( !queryonly )
436 
437  } else
438  MapNetwork :: start ( x, y );
439 }
440 
441 
442 
443 
444 
446 {
447  if ( b->color/8 == targplayer ) {
448  if ((b->netcontrol & (cnet_stopenergyinput << resourcetype)) == 0) {
449  int tostore = need-got;
452 
453  if ( !queryonly ) {
454  b->actstorage.resource( resourcetype ) += tostore;
456  actmap->tribute.paid [ targplayer ][ player ].resource( resourcetype ) += tostore;
457  }
458  got += tostore;
459  }
460  }
461 }
462 
463 
464 void PutTribute :: start ( int x, int y )
465 {
466  int pl = targplayer;
467  if ( pl == -1 )
468  targplayer = 0;
469 
470  do {
471  if ( targplayer != player )
472  if ( actmap->player[targplayer].exist() ) {
474  if ( need > 0 ) {
475  if ( scope == 3 ) {
476 
477  got = need;
480 
483 
484  if ( !queryonly ) {
487 
490  }
491 
492  } else {
493  int avail = startbuilding->getResource ( need, resourcetype, 1, 0 );
494  if ( need > avail )
495  need = avail;
496  MapNetwork :: start ( x, y );
497  if ( !queryonly ) {
499  // printf(" building at %d/%d had %d, pushed %d\n", x, y, avail, got );
500  }
501 
502  }
503  }
504  }
505  targplayer++;
506  } while ( targplayer < 8 && pl == -1 );
507 }
508 
509 int PutTribute :: puttribute ( Building* start, int resource, int _queryonly, int _forplayer, int _fromplayer, int _scope )
510 {
512  targplayer = _forplayer;
513  return getresource ( startbuilding->getEntry().x, startbuilding->getEntry().y, resource, 0, _queryonly, _fromplayer, _scope );
514 }
515 
516 
518 {
519 
520  int targplayer = player.getPosition();
521  GameMap* actmap = player.getParentMap();
522 
523  if ( actmap->player[targplayer].exist() ) {
524  ASCString text;
525 
526  for ( int player = 0; player < 8; player++ ) {
527  if ( targplayer != player )
528  if ( actmap->player[player].exist() ) {
529  int topay[3];
530  int got[3];
531  for ( int resourcetype = 0; resourcetype < 3; resourcetype++ ) {
532  got[ resourcetype ] = actmap->tribute.paid[ targplayer ][ player ].resource( resourcetype ) - actmap->tribute.payStatusLastTurn[ targplayer ][ player ].resource( resourcetype );
533  topay[ resourcetype ] = actmap->tribute.avail[ player ][ targplayer ].resource( resourcetype ) + got[ resourcetype ];
534 
535  if ( !actmap->isResourceGlobal (resourcetype) ) {
536  for ( Player::BuildingList::iterator j = actmap->player[player].buildingList.begin(); j != actmap->player[player].buildingList.end() && topay[resourcetype] > got[resourcetype] ; j++ ) {
537  PutTribute pt ( actmap );
538  got[resourcetype] += pt.puttribute ( *j, resourcetype, 0, targplayer, player, 1 );
539  }
540  } else {
541  int i;
542  if ( actmap->bi_resource[ player ].resource(resourcetype) < topay[resourcetype] )
543  i = actmap->bi_resource[ player ].resource(resourcetype);
544  else
545  i = topay[resourcetype];
546  got [resourcetype ] += i;
547  actmap->bi_resource[ player ].resource(resourcetype) -= i;
548  actmap->bi_resource[ targplayer ].resource(resourcetype) += i;
549 
550  actmap->tribute.avail[ player ][ targplayer ].resource( resourcetype ) -= got[resourcetype];
551  actmap->tribute.paid[ targplayer ][ player ].resource( resourcetype ) += got[resourcetype];
552  }
553  }
554  actmap->tribute.payStatusLastTurn[ targplayer ][ player ] = actmap->tribute.paid[ targplayer ][ player ];
555  if ( topay[0] || topay[1] || topay[2] || got[0] || got[1] || got[2]) {
556  Resources tp ( topay[0], topay[1], topay[2] );
557  Resources gt ( got[0], got[1], got[2] );
558 
559  ASCString topayStr = tp.toString();
560 
561  ASCString gotStr;
562  if ( gt == tp )
563  gotStr = "all";
564  else {
565  gotStr = gt.toString();
566  if ( gotStr.empty() )
567  gotStr = "nothing";
568  }
569 
570  ASCString msg;
571  msg.format ( getmessage( 10020 ) , actmap->player[player].getName().c_str(), topayStr.c_str(), gotStr.c_str() );
572 
573  text += msg;
574 
575 
576  // next message, this time for the providing player
577 
578  if ( got[0] || got[1] || got[2] ) {
579  msg = "";
580  gotStr = gt.toString();
581  msg.format ( getmessage( 10021 ) , gotStr.c_str(), actmap->player[targplayer].getName().c_str());
582  new Message ( msg, actmap, 1 << player );
583  }
584 
585 
586  }
587 
588  if ( got[0] || got[1] || got[2] )
590 
591  }
592  }
593  if ( !text.empty() )
594  new Message ( text, actmap, 1 << targplayer );
595 
596  }
597 }
598 
599 
601 {
602  if ( b->color/8 == player ) {
603  if ((b->netcontrol & (cnet_stopenergyinput << resourcetype)) == 0) {
604  int t = b->getStorageCapacity().resource( resourcetype );
605  if ( t > maxint - got )
606  got = maxint;
607  else
608  got += t;
609  }
610  }
611 }
612 
613 
614 void GetResourceCapacity :: start ( int x, int y )
615 {
616  if ( scope == 3 ) {
617  got = maxint;
618  } else
619  MapNetwork :: start ( x, y );
620 }
621 
622 
623 
624 
625 
626 
627 
628 
629 
630 
631 int ResourceChangeNet :: getresource ( int x, int y, int resource, int _player, int _scope )
632 {
633  if ( (_scope > 0) && (actmap->isResourceGlobal ( resource )) )
634  scope = 2;
635  else
636  scope = _scope;
637 
638  player = _player;
639  resourcetype = resource;
640  got = 0;
641  start ( x , y );
642  return got;
643 }
644 
645 
646 
647 
649 {/*
650  if ( resourcetype == 0 )
651  if ( v->getGeneratorStatus() )
652  got += v->typ->tank.energy;
653  */
654 }
655 
656 
658 {
659  if ( bld->color/8 == player )
661 }
662 
663 
664 
665 
666 
668 {
669  if ( b->color/8 == player )
671 }
672 
673 
674 
675 bool compareMapResources( GameMap* currentMap, GameMap* replaymap, int player, ASCString* log )
676 {
677  ASCString s;
678  bool diff = false;
679  for ( int r = 0; r < 3; ++r ) {
680  if ( currentMap->isResourceGlobal( r )) {
681  if ( currentMap->bi_resource[player].resource(r) != replaymap->bi_resource[player].resource(r) ) {
682  diff = true;
683  if ( log ) {
684  s.format ( "Global resource mismatch: %d %s available after replay, but %d available in actual map\n", replaymap-> bi_resource[player].resource(r), resourceNames[r], currentMap->bi_resource[player].resource(r) );
685  *log += s;
686  }
687  }
688  } else {
690  for ( Player::BuildingList::iterator b = currentMap->player[player].buildingList.begin(); b != currentMap->player[player].buildingList.end(); ++b ) {
691  Building* b1 = *b;
692  ContainerBase* b2 = replaymap->getContainer( b1->getIdentification() );
693  if ( !b1 || !b2 ) {
694  if ( log ) {
695  s.format ( "Building missing! \n");
696  *log += s;
697  }
698  } else {
699  if ( find ( cb.begin(), cb.end(), b1 ) == cb.end()) {
700  int ab1 = b1->getResource( maxint, r, true, 1, player );
701  int ab2 = b2->getResource( maxint, r, true, 1, player);
702  if ( ab1 != ab2 ) {
703  diff = true;
704  if ( log ) {
705  s.format ( "Building (%d,%d) resource mismatch: %d %s available after replay, but %d available in actual map\n", b1->getPosition().x, b1->getPosition().y, ab1, resourceNames[r], ab2 );
706  *log += s;
707  }
708  }
709  cb.push_back ( b1 );
711  GetConnectedBuildings gcb ( cbl, b1->getMap(), r );
712  gcb.start ( b1->getPosition().x, b1->getPosition().y );
713  cb.insert ( cb.end(), cbl.begin(), cbl.end() );
714  }
715  }
716  }
717  }
718  }
719  for ( Player::VehicleList::iterator v = currentMap->player[player].vehicleList.begin(); v != currentMap->player[player].vehicleList.end(); ++v ) {
720  Vehicle* v1 = *v;
721  Vehicle* v2 = replaymap->getUnit( v1->networkid );
722  if ( !v1 || !v2 ) {
723  if ( log ) {
724  s.format ( "Vehicle missing! \n");
725  *log += s;
726  }
727  } else {
728  if ( v1->typ != v2->typ ) {
729  diff = true;
730  if ( log ) {
731  s.format ( "Vehicles with NWID %d don't have matching type, probably production inconsistency. (%s <-> %s)\n", v1->networkid, v1->typ->getName().c_str(), v2->typ->getName().c_str() );
732  *log += s;
733  }
734  } else {
735  for ( int r = 0; r < 3; ++r ) {
736  int av1 = v1->getResource( maxint, r, true, 1, player );
737  int av2 = v2->getResource( maxint, r, true, 1, player );
738  if ( av1 != av2 ) {
739  diff = true;
740  if ( log ) {
741  s.format ( "Vehicle %s (%d,%d) resource mismatch: %d %s available after replay, but %d available in actual map\n", v1->typ->getName().c_str(), v1->getPosition().x, v1->getPosition().y, av2, resourceNames[r], av1 );
742  *log += s;
743  }
744  }
745  }
746 
747  if ( v1->damage != v2->damage ) {
748  diff = true;
749  if ( log ) {
750  s.format ( "Vehicle (%d,%d) damage mismatch: %d after replay, but %d in actual map\n", v1->getPosition().x, v1->getPosition().y, v2->damage, v1->damage );
751  *log += s;
752  }
753  }
754  if ( v1->getPosition().x != v2->getPosition().x || v1->getPosition().y != v2->getPosition().y ) {
755  diff = true;
756  if ( log ) {
757  s.format ( "Vehicle (%d,%d) position mismatch\n", v1->getPosition().x, v1->getPosition().y );
758  *log += s;
759  }
760  }
761 
762  }
763  }
764  }
765 
766  if ( currentMap->player[player].vehicleList.size() != replaymap->player[player].vehicleList.size() ) {
767  diff = true;
768  if ( log ) {
769  s.format ( "The number of units differ. Replay: %d ; actual map: %d", replaymap->player[player].vehicleList.size(), currentMap->player[player].vehicleList.size());
770  *log += s;
771 
772  GameMap* more;
773  GameMap* less;
774  if ( currentMap->player[player].vehicleList.size() > replaymap->player[player].vehicleList.size() ) {
775  more = currentMap;
776  less = replaymap;
777  } else {
778  more = replaymap;
779  less = currentMap;
780  }
781 
782  for ( Player::VehicleList::iterator i = more->player[player].vehicleList.begin(); i != more->player[player].vehicleList.end(); ++i )
783  if ( !less->getUnit( (*i)->networkid )) {
784  s.format( "\nType: %s at %d/%d, nwid: %d", (*i)->getName().c_str(), (*i)->getPosition().x, (*i)->getPosition().y, (*i)->networkid );
785  *log += s;
786  }
787  }
788  }
789 
790  if ( currentMap->player[player].buildingList.size() != replaymap->player[player].buildingList.size() ) {
791  diff = true;
792  if ( log ) {
793  s.format ( "The number of buildings differ. Replay: %d ; actual map: %d", replaymap->player[player].buildingList.size(), currentMap->player[player].buildingList.size());
794  *log += s;
795  }
796  }
797 
798  if ( currentMap->player[player].research.progress != replaymap->player[player].research.progress ) {
799  diff = true;
800  if ( log ) {
801  s.format ( "Research points mismatch! Replay: %d ; actual map: %d", replaymap->player[player].research.progress, currentMap->player[player].research.progress);
802  *log += s;
803  }
804  }
805 
806  sort ( currentMap->player[player].research.developedTechnologies.begin(), currentMap->player[player].research.developedTechnologies.end() );
807  sort ( replaymap->player[player].research.developedTechnologies.begin(), replaymap->player[player].research.developedTechnologies.end() );
808  if ( replaymap->player[player].research.developedTechnologies.size() != currentMap->player[player].research.developedTechnologies.size() ) {
809  diff = true;
810  if ( log ) {
811  s.format ( "Number of developed technologies differ !\n" );
812  *log += s;
813  }
814  } else {
815  for ( int i = 0; i < replaymap->player[player].research.developedTechnologies.size(); ++i )
816  if ( replaymap->player[player].research.developedTechnologies[i] != currentMap->player[player].research.developedTechnologies[i] ) {
817  diff = true;
818  if ( log ) {
819  s.format ( "Different technologies developed !\n" );
820  *log += s;
821  }
822  }
823  }
824 
825  for ( Player::BuildingList::iterator b = currentMap->player[player].buildingList.begin(); b != currentMap->player[player].buildingList.end(); ++b ) {
826  Building* b1 = *b;
827  Building* b2 = dynamic_cast<Building*>(replaymap->getContainer( b1->getIdentification() ));
828  if ( !b1 || !b2 ) {
829  if ( log ) {
830  s.format ( "Building missing! \n");
831  *log += s;
832  }
833  } else {
834  bool mismatch = false;
835  for ( int i = 0; i < b1->getProduction().size(); ++i )
836  if ( b1->getProduction()[i] ) {
837  bool found = false;
838  for ( int j = 0; j < b2->getProduction().size(); ++j)
839  if ( b2->getProduction()[j] == b1->getProduction()[i] )
840  found = true;
841  if ( !found)
842  mismatch = true;
843  }
844 
845  for ( int j = 0; j < b2->getProduction().size(); ++j )
846  if ( b2->getProduction()[j] ) {
847  bool found = false;
848  for ( int i = 0; i < b1->getProduction().size(); ++i)
849  if ( b1->getProduction()[i] == b2->getProduction()[j] )
850  found = true;
851  if ( !found)
852  mismatch = true;
853  }
854 
855  if ( mismatch ) {
856  diff = true;
857  if ( log ) {
858  s.format ( "Building (%d,%d) production line mismatch !\n", b1->getPosition().x, b1->getPosition().y );
859  *log += s;
860  }
861  }
862  }
863  }
864 
865  return diff;
866 }
867 
int getIdentification() const
Definition: buildings.cpp:100
virtual void checkbuilding(Building *b)
void displaymap()
Definition: spfst.cpp:58
MapNetwork(GameMap *gamemap, int checkInstances=1)
void setaTemp(Uint8 atemp)
Various algorithms need to store some information in the fields they process.
Definition: mapfield.cpp:49
void cleartemps(int b=-1, int value=0)
Definition: gamemap.cpp:964
virtual void checkbuilding(Building *b)
map accessing and usage routines used by ASC and the mapeditor
Resources getResourceUsage()
returns the resource that the building consumes for its operation.
int getresource(int x, int y, int resource, int _player, int _scope)
int getResource(int amount, int resourcetype, bool queryonly, int scope=1, int player=-1)
Definition: vehicle.cpp:328
int damage
Damage. 0 is no damage, when damage reaches 100 the container is destroyed.
Vehicle * vehicle
Definition: mapfield.h:89
virtual void start(int x, int y)
Resources getResourcePlus()
virtual int fieldavail(int x, int y)=0
int getresource(int x, int y, int resource, int _need, int _queryonly, int _player, int _scope)
int getPosition() const
Definition: player.h:112
MapCoordinate getFieldCoordinates(const BuildingType::LocalCoordinate &localCoordinates) const
returns the absolute map coordinate of the given part of the building
Definition: buildings.cpp:417
const GameMap * getParentMap() const
Definition: player.h:114
ASCString getName() const
returns the name of the player
Definition: player.cpp:274
ASCString toString() const
Definition: typen.cpp:268
Resources getStorageCapacity() const
returns the local storage capacity for the given resource, which depends on the resource mode of the ...
int getOwner() const
returns the number of the player this vehicle/building belongs to
vector< int > developedTechnologies
Definition: research.h:183
ContainerBase * getContainer(int nwid)
Definition: gamemap.cpp:1231
A local coordinate referencing a single field that a building covers.
Definition: buildingtype.h:57
MapCoordinate3D getEntry() const
returns the position of the buildings entry
Definition: buildings.cpp:410
MapCoordinate3D getPosition() const
returns the units position
Definition: vehicle.cpp:1552
Resources avail[8][8]
Definition: gamemap.h:339
Interface for some basic classes from which all of ASC's dialogs are derived.
ASCString getName() const
a single field of the map
Definition: mapfield.h:26
ASCString & format(const charT *pFormat,...)
Definition: ascstring.cpp:78
int puttribute(Building *start, int resource, int _queryonly, int _forplayer, int _fromplayer, int _scope)
virtual void checkvehicle(Vehicle *v)
GameMap * actmap
Definition: resourcenet.h:32
MapField * getEntryField() const
returns the field the buildings entry is standing on
Definition: buildings.cpp:405
Resources paid[8][8]
Definition: gamemap.h:340
int netcontrol
a bitmapped variable containing the status of the resource-net connection.
Definition: buildings.h:57
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
virtual int fieldavail(int x, int y)
const Production & getProduction() const
const char * getmessage(int id)
returns a pointer to the message id. The messages must have been loaded with loadmessages ...
virtual int globalsearch(void)=0
Handling the connection of buildings by pipelines, powerlines etc.
virtual void checkbuilding(Building *b)
virtual void start(int x, int y)
virtual void searchvehicle(int x, int y)
const int sidenum
the number of sides that a field has; is now fixed at 6;
Definition: typen.h:438
virtual void searchbuilding(int x, int y)
VehicleList vehicleList
a list of all units
Definition: player.h:135
virtual int getResource(int amount, int resourcetype, bool queryonly, int scope=1, int player=-1)=0
Resources bi_resource[8]
in BI resource mode ( see _resourcemode , isResourceGlobal ) , this is where the globally available r...
Definition: gamemap.h:416
TerrainBits getTerrainBitType(TerrainBitTypes tbt)
the properties of a terrain describing which units can move onto this field and which can't ...
Definition: terraintype.h:32
void searchAllVehiclesNextToBuildings(int player)
void log(const Vehicle *attacker, const Vehicle *attackee)
Definition: attack.cpp:417
sigc::signal< void > tributeTransferred
Definition: resourcenet.cpp:32
class GameMap::ResourceTribute tribute
Coordinate on the twodimensional map.
Definition: typen.h:202
bool isResourceGlobal(int resource)
Definition: gamemap.cpp:1024
void displaymessage(const char *formatstring, int num,...)
displays a dialog box with a message
Definition: dlg_box.cpp:1849
Uint8 getaTemp()
Definition: mapfield.cpp:52
The interface for the buildingtype class.
int getnextdx(int dir, int y)
Definition: mapalgorithms.h:77
virtual void checkvehicle(Vehicle *v)
virtual void checkbuilding(Building *b)
virtual void checkvehicle(Vehicle *v)=0
virtual void checkbuilding(Building *b)=0
Vehicle * getUnit(int x, int y, int nwid)
Definition: gamemap.cpp:1215
Player player[9]
Definition: gamemap.h:253
virtual int searchfinished(void)
int getnextdy(int dir)
Definition: mapalgorithms.h:80
int tributegot[3][8]
Definition: resourcenet.h:97
TerrainBits bdt
the terraintype properties. They determine which units can move over the field. This variable is reca...
Definition: mapfield.h:161
int resourcetype
Definition: resourcenet.h:56
virtual void searchfield(int x, int y, int dir)
Definition: resourcenet.cpp:34
#define cnet_stopenergyinput
Definition: typen.h:517
BuildingList buildingList
a list of all units
Definition: player.h:139
Resources actstorage
the current storage of Resources
Definition: buildings.h:91
A Message to a player. It may either be send by another player or by the system.
Definition: messages.h:30
Interface for all the dialog boxes used by the game and the mapeditor.
int color
The owner of the container.
virtual void checkbuilding(Building *b)
Research research
the status of the scientific research
Definition: player.h:142
int & resource(int type)
Definition: typen.h:105
virtual void start(int x, int y)
const VehicleType * typ
Definition: vehicle.h:83
Building * startbuilding
Definition: resourcenet.h:117
virtual void start(int x, int y)
int getResource(int amount, int resourcetype, bool queryonly, int scope=1, int player=-1)
Definition: controls.cpp:243
Coordinate on the map including height.
Definition: typen.h:238
Building * building
Definition: mapfield.h:102
#define cnet_stopenergyoutput
Definition: typen.h:521
virtual void start(int x, int y)
virtual void checkbuilding(Building *b)
#define maxint
Definition: typen.h:462
const char * resourceNames[3]
the names of the different resources. Redundent, as we already have Resources::name ...
Definition: typen.cpp:79
GameMap * actmap
Definition: spfst.cpp:64
GameMap * getMap() const
The parent class of Vehicle and Building; The name Container originates from Battle Isle...
Definition: containerbase.h:40
An actual building on the map, which references a BuildingType Buildings have an owner,.
Definition: buildings.h:38
MapCoordinate startposition
Definition: resourcenet.h:35
void setaTemp2(Uint8 atemp2)
Definition: mapfield.cpp:56
the different players in ASC. There may be 8 players (0..7) and neutral units (8) ...
Definition: player.h:99
Resources are basically the currency of ASC.
Definition: typen.h:97
GetResource(GameMap *gamemap, int scope=-1)
void transfer_all_outstanding_tribute(Player &player)
bool compareMapResources(GameMap *currentMap, GameMap *replaymap, int player, ASCString *log)
int targplayer
Definition: resourcenet.h:116
int progress
Definition: research.h:189
int networkid
a unique identification of the unit that is used everywhere in ASC (and not only the network protocol...
Definition: vehicle.h:140
virtual ~MapNetwork()
MapCoordinate3D getPosition() const
returns the position of the buildings entry
Definition: buildings.h:152
bool exist() const
does the player exist at all
Definition: player.cpp:313
Resources payStatusLastTurn[8][8]
for the messages that are send each turn it is necessary to record how much of the transfer happend d...
Definition: gamemap.h:343
MapCoordinate3D getNeighbouringFieldCoordinate(const MapCoordinate3D &pos, int direc)
returns the coordinate of the field that is adjecent to the given field in the direction of direc ...
Uint8 getaTemp2()
Definition: mapfield.cpp:59
The map. THE central structure of ASC, which holds everything not globally available together...
Definition: gamemap.h:182
virtual int searchfinished(void)=0
MapField * getField(int x, int y)
Definition: gamemap.h:465
vector< Building * > BuildingContainer
Definition: resourcenet.h:69