(svn r13421) [NoAI] -Fix: remove the need for a Sleep(1) before executing a command at the beginning of Start(), by skipping the first tick before calling Start() in the first place
--- a/bin/ai/regression/regression.txt Sun Jun 08 19:35:16 2008 +0000
+++ b/bin/ai/regression/regression.txt Sun Jun 08 21:11:05 2008 +0000
@@ -1,7 +1,7 @@
--TestInit--
- TickTest: 0
TickTest: 1
+ TickTest: 2
SetCommandDelay: (null : 0x00000000)
IsValid(vehicle.plane_speed): true
vehicle.plane_speed: 2
@@ -12,9 +12,9 @@
abs( 21): 21
--AIBase--
- Rand(): -71599500
- Rand(): -625161313
- Rand(): -38326422
+ Rand(): 753450495
+ Rand(): 202826571
+ Rand(): 203856518
RandRange(0): 0
RandRange(0): 0
RandRange(0): 0
@@ -24,12 +24,12 @@
RandRange(2): 1
RandRange(2): 0
RandRange(2): 1
- RandRange(9): 0
- RandRange(9): 0
- RandRange(9): 5
+ RandRange(9): 7
+ RandRange(9): 2
+ RandRange(9): 7
Chance(1, 2): true
Chance(1, 2): true
- Chance(1, 2): true
+ Chance(1, 2): false
--List--
IsEmpty(): true
@@ -242,144 +242,144 @@
1098 => 4768614
1099 => 4772957
Randomize ListDump:
- 1 => 5934189
- 2 => -1761272564
- 1000 => 998881475
- 1001 => 409666838
- 1002 => -948603759
- 1003 => -1581773722
- 1004 => 2104319151
- 1005 => 64634822
- 1006 => -671738360
- 1007 => 1178243491
- 1008 => 1680605747
- 1009 => 2067858917
- 1010 => -1906406406
- 1011 => -1795626673
- 1012 => 375391239
- 1013 => -494815434
- 1014 => -2138911669
- 1015 => -218170941
- 1016 => -2145147030
- 1017 => -1889805802
- 1018 => -188719086
- 1019 => 254262262
- 1020 => -1432258301
- 1021 => 753450495
- 1022 => 202826571
- 1023 => 203856518
- 1024 => 2033066803
- 1025 => -1217026074
- 1026 => 177237636
- 1027 => -1862680832
- 1028 => -809506802
- 1029 => 799054729
- 1030 => -870842760
- 1031 => 1235706796
- 1032 => 1805577366
- 1033 => -529149597
- 1034 => -1160496110
- 1035 => -2112828300
- 1036 => 1031472271
- 1037 => -1067512395
- 1038 => -1670717046
- 1039 => -1893761951
- 1040 => -1937566705
- 1041 => 875192026
- 1042 => -799929174
- 1043 => 429626413
- 1044 => -821285437
- 1045 => 1670322612
- 1046 => 1925605331
- 1047 => 1705170599
- 1048 => -256175309
- 1049 => 651753684
- 1051 => -1710121819
- 1052 => 1155454929
- 1053 => 461431108
- 1054 => -2028561436
- 1055 => 1977157906
- 1056 => -54636091
- 1057 => -669496035
- 1058 => -959189089
- 1059 => -1081705818
- 1060 => 935048341
- 1061 => 1848058144
- 1062 => 682657049
- 1063 => 9406967
- 1064 => -98686165
- 1065 => -64824797
- 1066 => 1365042371
- 1067 => 1754819174
- 1068 => 933840019
- 1069 => 1577578402
- 1070 => 420566759
- 1071 => -1872469035
- 1072 => -697881323
- 1073 => 1091027235
- 1074 => 1001969154
- 1075 => 315466472
- 1076 => 840435208
- 1077 => 2010662021
- 1078 => -1784655975
- 1079 => 1413073566
- 1080 => -841240668
- 1081 => 103625484
- 1082 => -1658507510
- 1083 => -102091421
- 1084 => 1464728002
- 1085 => 1049162075
- 1086 => 769281991
- 1087 => 384138993
- 1088 => -2064287113
- 1089 => -931746111
- 1090 => -358850804
- 1091 => 978513867
- 1092 => -1756292659
- 1093 => 73085820
- 1094 => 284986576
- 1095 => 1908549801
- 1096 => 1031985888
- 1097 => -216278913
- 1098 => 988268067
- 1099 => -618655226
+ 1 => -1893761951
+ 2 => -1937566705
+ 1000 => 875192026
+ 1001 => -799929174
+ 1002 => 429626413
+ 1003 => -821285437
+ 1004 => 1670322612
+ 1005 => 1925605331
+ 1006 => 1705170599
+ 1007 => -256175309
+ 1008 => 651753684
+ 1009 => -1710121819
+ 1010 => 1155454929
+ 1011 => 461431108
+ 1012 => -2028561436
+ 1013 => 1977157906
+ 1014 => -54636091
+ 1015 => -669496035
+ 1016 => -959189089
+ 1017 => -1081705818
+ 1018 => 935048341
+ 1019 => 1848058144
+ 1020 => 682657049
+ 1021 => 9406967
+ 1022 => -98686165
+ 1023 => -64824797
+ 1024 => 1365042371
+ 1025 => 1754819174
+ 1026 => 933840019
+ 1027 => 1577578402
+ 1028 => 420566759
+ 1029 => -1872469035
+ 1030 => -697881323
+ 1031 => 1091027235
+ 1032 => 1001969154
+ 1033 => 315466472
+ 1034 => 840435208
+ 1035 => 2010662021
+ 1036 => -1784655975
+ 1037 => 1413073566
+ 1038 => -841240668
+ 1039 => 103625484
+ 1040 => -1658507510
+ 1041 => -102091421
+ 1042 => 1464728002
+ 1043 => 1049162075
+ 1044 => 769281991
+ 1045 => 384138993
+ 1046 => -2064287113
+ 1047 => -931746111
+ 1048 => -358850804
+ 1049 => 978513867
+ 1051 => -1756292659
+ 1052 => 73085820
+ 1053 => 284986576
+ 1054 => 1908549801
+ 1055 => 1031985888
+ 1056 => -216278913
+ 1057 => 988268067
+ 1058 => -618655226
+ 1059 => -232110358
+ 1060 => 278694908
+ 1061 => 1444189056
+ 1062 => -690668105
+ 1063 => 1453737449
+ 1064 => 1222082116
+ 1065 => 1315480265
+ 1066 => 2101304211
+ 1067 => -1428786480
+ 1068 => 636630420
+ 1069 => 1910533661
+ 1070 => 1823367094
+ 1071 => -2058922812
+ 1072 => 396819271
+ 1073 => -963848185
+ 1074 => 881736883
+ 1075 => -758945066
+ 1076 => -2050156175
+ 1077 => -801286336
+ 1078 => -1276947052
+ 1079 => 64214997
+ 1080 => 515657110
+ 1081 => -1992243338
+ 1082 => -2088507011
+ 1083 => -437598559
+ 1084 => -963693423
+ 1085 => 508374070
+ 1086 => -637379826
+ 1087 => 1816492397
+ 1088 => -927496464
+ 1089 => -1386798276
+ 1090 => -246561744
+ 1091 => 1111334158
+ 1092 => -164201614
+ 1093 => -762675739
+ 1094 => 906198641
+ 1095 => 1018408444
+ 1096 => 1077722054
+ 1097 => 1091067333
+ 1098 => -815996928
+ 1099 => -571363581
KeepTop(10):
- 1 => 5934189
- 2 => -1761272564
- 1000 => 998881475
- 1001 => 409666838
- 1002 => -948603759
- 1003 => -1581773722
- 1004 => 2104319151
- 1005 => 64634822
- 1006 => -671738360
- 1007 => 1178243491
+ 1 => -1893761951
+ 2 => -1937566705
+ 1000 => 875192026
+ 1001 => -799929174
+ 1002 => 429626413
+ 1003 => -821285437
+ 1004 => 1670322612
+ 1005 => 1925605331
+ 1006 => 1705170599
+ 1007 => -256175309
KeepBottom(8):
- 1000 => 998881475
- 1001 => 409666838
- 1002 => -948603759
- 1003 => -1581773722
- 1004 => 2104319151
- 1005 => 64634822
- 1006 => -671738360
- 1007 => 1178243491
+ 1000 => 875192026
+ 1001 => -799929174
+ 1002 => 429626413
+ 1003 => -821285437
+ 1004 => 1670322612
+ 1005 => 1925605331
+ 1006 => 1705170599
+ 1007 => -256175309
RemoveBottom(2):
- 1000 => 998881475
- 1001 => 409666838
- 1002 => -948603759
- 1003 => -1581773722
- 1004 => 2104319151
- 1005 => 64634822
+ 1000 => 875192026
+ 1001 => -799929174
+ 1002 => 429626413
+ 1003 => -821285437
+ 1004 => 1670322612
+ 1005 => 1925605331
RemoveTop(2):
- 1002 => -948603759
- 1003 => -1581773722
- 1004 => 2104319151
- 1005 => 64634822
+ 1002 => 429626413
+ 1003 => -821285437
+ 1004 => 1670322612
+ 1005 => 1925605331
RemoveList({1003, 1004}):
- 1002 => -948603759
- 1005 => 64634822
+ 1002 => 429626413
+ 1005 => 1925605331
KeepList({1003, 1004, 1005}):
- 1005 => 64634822
+ 1005 => 1925605331
AddList({1005, 4000, 4001, 4002}):
1005 => 1005
4000 => 4000
@@ -6908,50 +6908,11 @@
IsValidSubsidy(): true
IsAwarded(): false
GetAwardedTo(): -1
- GetExpireDate(): 712619
- SourceIsTown(): true
- GetSource(): 25
- DestionationIsTown(): true
- GetDestionation(): 10
- GetCargoType(): 0
- GetNextEvent: instance
- GetEventType: 3
- EventName: SubsidyOffer
- --Subsidy (1) --
- IsValidSubsidy(): true
- IsAwarded(): false
- GetAwardedTo(): -1
- GetExpireDate(): 712647
- SourceIsTown(): true
- GetSource(): 24
- DestionationIsTown(): true
- GetDestionation(): 21
- GetCargoType(): 0
- GetNextEvent: instance
- GetEventType: 3
- EventName: SubsidyOffer
- --Subsidy (2) --
- IsValidSubsidy(): true
- IsAwarded(): false
- GetAwardedTo(): -1
- GetExpireDate(): 712739
- SourceIsTown(): true
- GetSource(): 0
- DestionationIsTown(): true
- GetDestionation(): 21
- GetCargoType(): 0
- GetNextEvent: instance
- GetEventType: 3
- EventName: SubsidyOffer
- --Subsidy (3) --
- IsValidSubsidy(): true
- IsAwarded(): false
- GetAwardedTo(): -1
GetExpireDate(): 712800
SourceIsTown(): true
- GetSource(): 4
+ GetSource(): 7
DestionationIsTown(): true
- GetDestionation(): 27
+ GetDestionation(): 15
GetCargoType(): 0
IsEventWaiting: false
ERROR: We've got a suicidal AI for player 1
--- a/bin/ai/wrightai/main.nut Sun Jun 08 19:35:16 2008 +0000
+++ b/bin/ai/wrightai/main.nut Sun Jun 08 21:11:05 2008 +0000
@@ -328,9 +328,6 @@
return;
}
- /* Sleep 1 tick, as we can't execute anything in tick 0 */
- Sleep(1);
-
/* Give the boy a name */
if (!AICompany.SetCompanyName("WrightAI")) {
local i = 2;
--- a/src/ai/ai_threads.cpp Sun Jun 08 19:35:16 2008 +0000
+++ b/src/ai/ai_threads.cpp Sun Jun 08 21:11:05 2008 +0000
@@ -274,6 +274,10 @@
/* Switch to running */
this->state = RUNNING;
+ /* We want to skip the first tick, so switch back to the main fiber */
+ AIFiber *main = stFind(MAIN_FIBER);
+ main->SwitchToState(RUNNING);
+
/* Start up the AI (this should be an infinite loop) */
this->controller->Start();
@@ -281,7 +285,6 @@
DEBUG(ai, 1, "We've got a suicidal AI for player %d", this->fiber_id);
/* Wait until we are killed nicely by the game */
- AIFiber *main = stFind(MAIN_FIBER);
while (this->state != STOPPING) {
main->SwitchToState(RUNNING);
}