1 #######################################################################
2 # Micropolis.tcl, by Don Hopkins.
3 # Copyright (C) 2002 by Electronic Arts.
4 # This file defines the user interface of Micropolis.
5 # Modify at your own risk!
6 ########################################################################
7 # Micropolis, Unix Version. This game was released for the Unix platform
8 # in or about 1990 and has been modified for inclusion in the One Laptop
9 # Per Child program. Copyright (C) 1989 - 2007 Electronic Arts Inc. If
10 # you need assistance with this program, you may contact:
11 # http://wiki.laptop.org/go/Micropolis or email micropolis@laptop.org.
13 # This program is free software: you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation, either version 3 of the License, or (at
16 # your option) any later version.
18 # This program is distributed in the hope that it will be useful, but
19 # WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 # General Public License for more details. You should have received a
22 # copy of the GNU General Public License along with this program. If
23 # not, see <http://www.gnu.org/licenses/>.
25 # ADDITIONAL TERMS per GNU GPL Section 7
27 # No trademark or publicity rights are granted. This license does NOT
28 # give you any right, title or interest in the trademark SimCity or any
29 # other Electronic Arts trademark. You may not distribute any
30 # modification of this program using the trademark SimCity or claim any
31 # affliation or association with Electronic Arts Inc. or its employees.
33 # Any propagation or conveyance of this program must include this
34 # copyright notice and these terms.
36 # If you convey this program (or any modifications of it) and assume
37 # contractual liability for the program to recipients of it, you agree
38 # to indemnify Electronic Arts for any liability that those contractual
39 # assumptions impose on Electronic Arts.
41 # You may not misrepresent the origins of this program; modified
42 # versions of the program must be marked as such and not identified as
43 # the original program.
45 # This disclaimer supplements the one included in the General Public
46 # License. TO THE FULLEST EXTENT PERMISSIBLE UNDER APPLICABLE LAW, THIS
47 # PROGRAM IS PROVIDED TO YOU "AS IS," WITH ALL FAULTS, WITHOUT WARRANTY
48 # OF ANY KIND, AND YOUR USE IS AT YOUR SOLE RISK. THE ENTIRE RISK OF
49 # SATISFACTORY QUALITY AND PERFORMANCE RESIDES WITH YOU. ELECTRONIC ARTS
50 # DISCLAIMS ANY AND ALL EXPRESS, IMPLIED OR STATUTORY WARRANTIES,
51 # INCLUDING IMPLIED WARRANTIES OF MERCHANTABILITY, SATISFACTORY QUALITY,
52 # FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT OF THIRD PARTY
53 # RIGHTS, AND WARRANTIES (IF ANY) ARISING FROM A COURSE OF DEALING,
54 # USAGE, OR TRADE PRACTICE. ELECTRONIC ARTS DOES NOT WARRANT AGAINST
55 # INTERFERENCE WITH YOUR ENJOYMENT OF THE PROGRAM; THAT THE PROGRAM WILL
56 # MEET YOUR REQUIREMENTS; THAT OPERATION OF THE PROGRAM WILL BE
57 # UNINTERRUPTED OR ERROR-FREE, OR THAT THE PROGRAM WILL BE COMPATIBLE
58 # WITH THIRD PARTY SOFTWARE OR THAT ANY ERRORS IN THE PROGRAM WILL BE
59 # CORRECTED. NO ORAL OR WRITTEN ADVICE PROVIDED BY ELECTRONIC ARTS OR
60 # ANY AUTHORIZED REPRESENTATIVE SHALL CREATE A WARRANTY. SOME
61 # JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF OR LIMITATIONS ON IMPLIED
62 # WARRANTIES OR THE LIMITATIONS ON THE APPLICABLE STATUTORY RIGHTS OF A
63 # CONSUMER, SO SOME OR ALL OF THE ABOVE EXCLUSIONS AND LIMITATIONS MAY
67 ########################################################################
69 ########################################################################
75 source $tk_library/wish.tcl
78 ########################################################################
80 ########################################################################
84 set State uninitialized
85 set CityName
"Micropolis"
88 set CityLibDir
$SimHome/cities
89 set CityDir
$CityLibDir
93 set BudgetPoliceFund
0
111 set AudioChannels
{mode edit fancy warning intercom
}
114 set BudgetTimerActive
0
116 set EvaluationsVisible
0
117 set SplashScreenDelay
5000
120 set ChatServer
"localhost"
122 set ChatConnection
{}
123 set NickName
"nickname"
124 set UserName
"username"
125 set ServerName
"servername"
126 set RealName
"realname"
127 set ChannelName
"#Micropolis"
131 set LocalHostName
"[exec hostname]"
139 set ShowingPicture
300
143 set VoteNames
{UseThisMap Ask Zone
}
144 set VotesForUseThisMap
{}
147 set VotesForBudget
{}
155 set EvaluationWindows
{}
157 set ScenarioWindows
{}
165 set HeadPanelWidth
360
166 set HeadPanelHeight
200
168 set MapPanelWidth
360
169 set MapPanelHeight
330
171 set NoticePanelWidth
360
172 set NoticePanelHeight
250
174 set SplashPanelWidth
1200
175 set SplashPanelHeight
900
177 #set ScenarioPanelWidth 420
178 #set ScenarioPanelHeight 440
179 set ScenarioPanelWidth
1200
180 set ScenarioPanelHeight
900
189 {editor EditorWindows
}
192 {budget BudgetWindows
}
193 {evaluation EvaluationWindows
}
194 {scenario ScenarioWindows
}
195 {splash SplashWindows
}
198 {player PlayerWindows
}
199 {notice NoticeWindows
}
206 # 0 1 2 3 4 5 6 7 8 9 10 11 12 13
207 # type id callback param var x y w h normal over disabled checked checkedover
208 # ----------- --------------- --------------- ------- ------- --- --- --- --- ------- ---- -------- ------- -----------
209 set ScenarioButtons1200x900
{
210 { button load DoLoad
"" "" 70 238 157 90 "" @images
/button1hilite.xpm
"" }
211 { button generate DoGenerate
"" "" 62 392 157 90 "" @images
/button2hilite.xpm
"" }
212 { button quit DoQuit
"" "" 68 544 157 90 "" @images
/button3hilite.xpm
"" }
213 { button about DoAbout
"" "" 101 705 157 90 "" @images
/button4hilite.xpm
"" }
214 { checkbox easy DoLevel
0 "" 982 106 190 70 "" @images
/checkbox1hilite.xpm
"" @images
/checkbox1checked.xpm
@images
/checkbox1hilitechecked.xpm
}
215 { checkbox medium DoLevel
1 "" 982 176 190 70 "" @images
/checkbox2hilite.xpm
"" @images
/checkbox2checked.xpm
@images
/checkbox2hilitechecked.xpm
}
216 { checkbox hard DoLevel
2 "" 982 246 190 70 "" @images
/checkbox3hilite.xpm
"" @images
/checkbox3checked.xpm
@images
/checkbox3hilitechecked.xpm
}
217 { button left DoLeft
"" "" 540 375 50 50 "" @images
/lefthilite.xpm
@images
/leftdisabled.xpm
}
218 { button right DoRight
"" "" 841 375 50 50 "" @images
/righthilite.xpm
@images
/rightdisabled.xpm
}
219 { button play DoPlay
"" "" 625 376 180 50 "" @images
/playhilite.xpm
"" }
220 { button scenario1 DoPickScenario
"1" "" 310 451 209 188 "" @images
/scenario1hilite.xpm
"" }
221 { button scenario2 DoPickScenario
"2" "" 519 451 209 188 "" @images
/scenario2hilite.xpm
"" }
222 { button scenario3 DoPickScenario
"3" "" 727 450 209 188 "" @images
/scenario3hilite.xpm
"" }
223 { button scenario4 DoPickScenario
"4" "" 936 450 209 188 "" @images
/scenario4hilite.xpm
"" }
224 { button scenario5 DoPickScenario
"5" "" 310 639 209 188 "" @images
/scenario5hilite.xpm
"" }
225 { button scenario6 DoPickScenario
"8" "" 519 639 209 188 "" @images
/scenario6hilite.xpm
"" }
226 { button scenario7 DoPickScenario
"7" "" 728 638 209 188 "" @images
/scenario7hilite.xpm
"" }
227 { button scenario8 DoPickScenario
"6" "" 937 638 209 188 "" @images
/scenario8hilite.xpm
"" }
230 set ScenarioButtons600x450
{
231 { button load DoLoad
"" "" 35 119 79 45 "" @images
/button1hilite-small.xpm
"" }
232 { button generate DoGenerate
"" "" 31 196 79 45 "" @images
/button2hilite-small.xpm
"" }
233 { button quit DoQuit
"" "" 34 272 79 45 "" @images
/button3hilite-small.xpm
"" }
234 { button about DoAbout
"" "" 51 353 79 45 "" @images
/button4hilite-small.xpm
"" }
235 { checkbox easy DoLevel
0 "" 491 53 95 35 "" @images
/checkbox1hilite-small.xpm
"" @images
/checkbox1checked-small.xpm
@images
/checkbox1hilitechecked-small.xpm
}
236 { checkbox medium DoLevel
1 "" 491 88 95 35 "" @images
/checkbox2hilite-small.xpm
"" @images
/checkbox2checked-small.xpm
@images
/checkbox2hilitechecked-small.xpm
}
237 { checkbox hard DoLevel
2 "" 491 123 95 35 "" @images
/checkbox3hilite-small.xpm
"" @images
/checkbox3checked-small.xpm
@images
/checkbox3hilitechecked-small.xpm
}
238 { button left DoLeft
"" "" 270 187 25 25 "" @images
/lefthilite-small.xpm
@images
/leftdisabled-small.xpm
}
239 { button right DoRight
"" "" 420 187 25 25 "" @images
/righthilite-small.xpm
@images
/rightdisabled-small.xpm
}
240 { button play DoPlay
"" "" 312 188 90 25 "" @images
/playhilite-small.xpm
"" }
241 { button scenario1 DoPickScenario
"1" "" 155 225 105 94 "" @images
/scenario1hilite-small.xpm
"" }
242 { button scenario2 DoPickScenario
"2" "" 259 225 105 94 "" @images
/scenario2hilite-small.xpm
"" }
243 { button scenario3 DoPickScenario
"3" "" 363 225 105 94 "" @images
/scenario3hilite-small.xpm
"" }
244 { button scenario4 DoPickScenario
"4" "" 468 225 105 94 "" @images
/scenario4hilite-small.xpm
"" }
245 { button scenario5 DoPickScenario
"5" "" 155 319 105 94 "" @images
/scenario5hilite-small.xpm
"" }
246 { button scenario6 DoPickScenario
"8" "" 259 319 105 94 "" @images
/scenario6hilite-small.xpm
"" }
247 { button scenario7 DoPickScenario
"7" "" 363 319 105 94 "" @images
/scenario7hilite-small.xpm
"" }
248 { button scenario8 DoPickScenario
"6" "" 468 319 105 94 "" @images
/scenario8hilite-small.xpm
"" }
249 { button map DoMap
"" "" 267 24 180 150 "" "" "" }
252 set ScenarioButtons
$ScenarioButtons1200x900
253 set ScenarioBackground
"@images/background-micropolis.xpm"
256 set ScenarioMapFloatX
-1
257 set ScenarioMapFloatY
-1
258 set ScenarioCityNameX
530
259 set ScenarioCityNameY
0
260 set ScenarioDescX
232
261 set ScenarioDescY
170
262 set ScenarioDescWidth
280
263 set ScenarioDescHeight
285
264 set ScenarioDescFont Large
266 set screenwidth
[winfo screenwidth .
]
267 set screenheight
[winfo screenheight .
]
269 if {($screenwidth < $ScenarioPanelWidth) ||
270 ($screenheight < $ScenarioPanelHeight)} {
271 puts stdout
"Screen too small for normal scenario window, using resized version.\n"
272 set ScenarioBackground
"@images/background-micropolis-small.xpm"
273 set ScenarioPanelWidth
600
274 set ScenarioPanelHeight
450
277 set ScenarioMapFloatX
140
278 set ScenarioMapFloatY
2
279 set ScenarioCityNameX
162
280 set ScenarioCityNameY
422
281 set ScenarioDescX
250
283 set ScenarioDescWidth
240
284 set ScenarioDescHeight
210
285 set ScenarioDescFont Tiny
286 set ScenarioButtons
$ScenarioButtons600x450
289 # Disabled until we handle mouse events on the map itself.
290 # { button map DoMap "" "" 516 30 396 338 "" @images/maphilite.xpm }
293 ########################################################################
299 {-*-dejavu lgc sans-medium-r-normal-
*-90-*}
302 {-*-dejavu lgc sans-medium-r-normal-
*-80-*}
305 {-*-dejavu lgc sans-medium-r-normal-
*-70-*}
308 {-*-dejavu lgc sans-medium-r-normal-
*-60-*}
311 {-*-dejavu lgc sans-medium-r-normal-
*-60-*}
314 {-*-dejavu lgc sans-medium-r-normal-
*-60-*}
317 {-*-dejavu lgc sans-medium-r-normal-
*-70-*}
320 {-*-dejavu lgc sans-medium-r-normal-
*-70-*}
323 {-*-dejavu lgc sans-medium-r-normal-
*-70-*}
328 ########################################################################
332 {Micropolis Overall Map
}
333 {Residential Zone Map
}
334 {Commercial Zone Map
}
335 {Industrial Zone Map
}
338 {Population Density Map
}
340 {Traffic Density Map
}
341 {Pollution Desity Map
}
345 {Police Coverage Map
}
351 leftframe.tools.palletres
352 leftframe.tools.palletcom
353 leftframe.tools.palletind
354 leftframe.tools.palletfire
355 leftframe.tools.palletquery
356 leftframe.tools.palletpolice
357 leftframe.tools.palletwire
358 leftframe.tools.palletbulldozer
359 leftframe.tools.palletrail
360 leftframe.tools.palletroad
361 leftframe.tools.palletchalk
362 leftframe.tools.palleteraser
363 leftframe.tools.palletstadium
364 leftframe.tools.palletpark
365 leftframe.tools.palletseaport
366 leftframe.tools.palletcoal
367 leftframe.tools.palletnuclear
368 leftframe.tools.palletairport
372 set EditorPalletImages
{
373 res com ind fire qry pol
374 wire dozr rail road chlk ersr
375 stad park seap coal nuc airp
379 set EditorPalletSounds
{
380 Res Com Ind Fire Query Police
381 Wire Bulldozer Rail Road Chalk Eraser
382 Stadium Park Seaport Coal Nuclear Airport
390 leftframe.right.money
391 leftframe.right.crime
392 leftframe.right.pollution
396 set GraphPalletImages
{
397 res com ind mony crim poll
401 set GraphYearPallets
{
402 leftframe.year.year10
403 leftframe.year.year120
407 set GraphYearPalletImages
{ 10 120 }
411 { {a
} {Residential Zone
} {$100}}
412 { {a
} {Commercial Zone
} {$100}}
413 { {an
} {Industrial Zone
} {$100}}
414 { {a
} {Fire Station
} {$500}}
415 { {a
} {Query
} {free
}}
416 { {a
} {Police Station
} {$500}}
418 { {a
} {Bulldozer
} {$1}}
421 { {a
} {Chalk
} {free
}}
422 { {an
} {Eraser
} {free
}}
423 { {a
} {Stadium
} {$5,000}}
425 { {a
} {Seaport
} {$3,000}}
426 { {a
} {Coal Power Plant
} {$3,000}}
427 { {a
} {Nuclear Power Plant
} {$5,000}}
428 { {an
} {Airport
} {$10,000}}
429 { {a
} {Network
} {$1,000}}
433 set DynamicDataNames
{
444 ########################################################################
446 ########################################################################
449 wm title .
{Micropolis Root
}
452 if {"[sim Platform]" == "msdos"} {
473 # The next three lines have no effect on the OLPC, where we don't provide
474 # the font in res (because it's already in the system fonts). These lines
475 # are for other systems that lack the font.
476 set FontPath
"[pwd]/res/dejavu-lgc"
477 system
"xset -fp \"$FontPath\" >/dev/null 2>&1"
478 system
"xset +fp \"$FontPath\" >/dev/null 2>&1"
480 # Ignore SIGCHLD for spawned sound-player childs, this should lead to them
481 # being reaped by init
482 signal ignore SIGCHLD
485 ########################################################################
487 ########################################################################
490 proc Message
{id color title msg
{props
{}}} {
492 set Messages
($id) [list $color $title $msg $props]
496 Message
1 #7f7fff {DULLSVILLE, USA 1900} \
497 {Things haven't changed much around here in the last hundred years or so and the residents are beginning to get bored. They think Dullsville could be the next great city with the right leader.
499 It is your job to attract new growth and development
, turning Dullsville into a Metropolis within
30 years.
}
501 Message
2 #7f7fff {SAN FRANCISCO, CA. 1906} \
502 {Damage from the earthquake was minor compared to that of the ensuing fires
, which took days to control.
1500 people died.
504 Controlling the fires should be your initial concern. Then clear the rubble and start rebuilding. You have
5 years.
}
506 Message
3 #7f7fff {HAMBURG, GERMANY 1944} \
507 {Allied fire-bombing of German cities in WWII caused tremendous damage and loss of life. People living in the inner cities were at greatest risk.
509 You must control the firestorms during the bombing and then rebuild the city
after the war. You have
5 years.
}
511 Message
4 #7f7fff {BERN, SWITZERLAND 1965} \
512 {The roads here are becoming more congested every day
, and the residents are upset. They demand that you do something about it.
514 Some have suggested a mass transit system as the answer
, but this would require major rezoning in the downtown area. You have
10 years.
}
516 Message
5 #7f7fff {TOKYO, JAPAN 1957} \
517 {A large reptilian creature has been spotted heading
for Tokyo bay. It seems to be attracted to the heavy levels of industrial pollution there.
519 Try to control the fires
, then rebuild the industrial center. You have
5 years.
}
521 Message
6 #7f7fff {DETROIT, MI. 1972} \
522 {By
1970, competition from overseas and other economic factors pushed the once
"automobile capital of the world" into recession. Plummeting land values and unemployment then increased crime in the inner-city to chronic levels.
524 You have
10 years to reduce crime and rebuild the industrial base of the city.
}
526 Message
7 #7f7fff {BOSTON, MA. 2010} \
527 {A major meltdown is about to occur at one of the new downtown nuclear reactors. The area in the vicinity of the reactor will be severly contaminated by radiation
, forcing you to restructure the city around it.
529 You have
5 years to get the situation under control.
}
531 Message
8 #7f7fff {RIO DE JANEIRO, BRAZIL 2047} \
532 {In the mid-21st century
, the greenhouse effect raised
global temperatures
6 degrees F. Polar icecaps melted and raised sea levels worldwide. Coastal areas were devastated by flood and erosion.
534 You have
10 years to turn this swamp back into a city again.
}
536 Message
9 #ffa500 {Query Zone Status} \
544 {{view
{PanView
$v $QueryX $QueryY}}}
546 Message
10 #ff4f4f {POLLUTION ALERT!} \
547 {Pollution in your city has exceeded the maximum allowable amounts established by the Micropolis Pollution Agency. You are running the risk of grave ecological consequences.
549 Either clean up your act or
open a gas mask concession at city hall.
} \
550 {{view
{PanView
$v [sim PolMaxX
] [sim PolMaxY
]}}}
552 Message
11 #ff4f4f {CRIME ALERT!} \
553 {Crime in your city is out of hand. Angry mobs are looting and vandalizing the central city. The president will
send in the national guard soon
if you cannot control the problem.
} \
554 {{view
{PanView
$v [sim CrimeMaxX
] [sim CrimeMaxY
]}}}
556 Message
12 #ff4f4f {TRAFFIC WARNING!} \
557 {Traffic in this city is horrible. The city gridlock is expanding. The commuters are getting militant.
559 Either build more roads and rails or get a bulletproof limo.
} \
560 {{view
{PanView
$v [sim TrafMaxX
] [sim TrafMaxY
]}}}
562 Message
20 #ff4f4f {FIRE REPORTED!} \
563 "A fire has been reported!" \
564 {{view
{PanView
$v [sim CrashX
] [sim CrashY
]}}}
566 Message
21 #ff4f4f {MONSTER ATTACK!} \
567 "A large reptilian creature has been spotted in the water. It seems to be attracted to areas of high pollution. There is a trail of destruction wherever it goes. \
568 All you can do is wait till he leaves, then rebuild from the rubble." \
569 {{view
{FollowView
$v monster
}}}
571 # XXX: write more text
572 Message
22 #ff4f4f {TORNADO ALERT!} \
573 {A tornado has been reported
! There's nothing you can do to stop it
, so you'd better prepare to clean up
after the disaster
!} \
574 {{view
{FollowView
$v tornado
}}}
576 # XXX: write more text
577 Message
23 #ff4f4f {EARTHQUAKE!} \
578 {A major earthquake has occurred
! Put out the fires as quickly as possible
, before they spread
, then reconnect the power
grid and rebuild the city.
} \
579 {{view
{PanView
$v [sim CenterX
] [sim CenterY
]}}}
581 # XXX: write more text
582 Message
24 #ff4f4f {PLANE CRASH!} \
583 {A plane has crashed
!} \
584 {{view
{PanView
$v [sim CrashX
] [sim CrashY
]}}}
586 # XXX: write more text
587 Message
25 #ff4f4f {SHIPWRECK!} \
588 {A ship has wrecked
!} \
589 {{view
{PanView
$v [sim CrashX
] [sim CrashY
]}}}
591 # XXX: write more text
592 Message
26 #ff4f4f {TRAIN CRASH!} \
593 {A train has crashed
!} \
594 {{view
{PanView
$v [sim CrashX
] [sim CrashY
]}}}
596 # XXX: write more text
597 Message
27 #ff4f4f {HELICOPTER CRASH!} \
598 {A helicopter has crashed
!} \
599 {{view
{PanView
$v [sim CrashX
] [sim CrashY
]}}}
601 Message
30 #ff4f4f {FIREBOMBING REPORTED!} \
602 {Firebombs are falling
!!} \
603 {{view
{PanView
$v [sim CrashX
] [sim CrashY
]}}}
605 Message
35 #7fff7f {TOWN} \
606 {Congratulations
, your village has grown to town status. You now have
2,000 citizens.
} \
607 {{view
{PanView
$v [sim CenterX
] [sim CenterY
]}}}
609 Message
36 #7fff7f {CITY} \
610 {Your town has grown into a full sized city
, with a current population of
10,000. Keep up the good work
!} \
611 {{view
{PanView
$v [sim CenterX
] [sim CenterY
]}}}
613 Message
37 #7fff7f {CAPITAL} \
614 {Your city has become a capital. The current population here is
50,000. Your political future looks bright.
} \
615 {{view
{PanView
$v [sim CenterX
] [sim CenterY
]}}}
617 Message
38 #7fff7f {METROPOLIS} \
618 {Your capital city has now achieved the status of metropolis. The current population is
100,000. With your management skills
, you should seriously consider running
for governor.
} \
619 {{view
{PanView
$v [sim CenterX
] [sim CenterY
]}}}
621 Message
39 #7fff7f {MEGALOPOLIS} \
622 {Congratulation
, you have reached the highest category of urban development
, the megalopolis.
624 If you manage to reach this level
, send us email at micropolis
@laptop.org or
send us a copy of your city. We might do something interesting with it.
} \
625 {{view
{PanView
$v [sim CenterX
] [sim CenterY
]}}}
627 Message
40 #7fff7f {MEGALINIUM} \
628 {Congratulation
, you have reached the end of
time!
630 Because of the toroidal nature of the the Micropolis Space
/Time Continuum
, your city has wrapped back in
time to
1900!} \
631 {{view
{PanView
$v [sim CenterX
] [sim CenterY
]}}}
633 # XXX: write more text
634 Message
41 #ff4f4f {HEAVY TRAFFIC!} \
636 reporting heavy traffic
!} \
637 {{view
{FollowView
$v helicopter
}}}
639 # XXX: write more text
640 Message
42 #ff4f4f {FLOODING REPORTED!} \
641 {Flooding has been been reported along the water's edge
!} \
642 {{view
{PanView
$v [sim FloodX
] [sim FloodY
]}}}
644 Message
43 #ff4f4f {NUCLEAR MELTDOWN!} \
645 {A nuclear meltdown has occured at your power plant. You are advised to avoid the area until the radioactive isotopes decay.
647 Many generations will confront this problem before it goes away
, so don't hold your breath.
} \
648 {{view
{PanView
$v [sim MeltX
] [sim MeltY
]}}}
651 Message
44 #ff4f4f {RIOTS!} \
652 {The citizens are rioting in the streets
, setting cars and houses on fire
, and bombing government buildings and businesses
!
654 All media coverage is blacked out
, while the fascist pigs beat the poor citizens into submission.
}
656 Message
46 #ff4f4f {NO SOUND SERVER!} \
657 {There is no sound server running on your X11 display
"%s". You won't hear any noise unless you run a sound server
, and turn the sound back on in the
"Options" menu.
}
659 Message
48 #7f7fff {Start a New City} \
660 {Build your very own city from the ground up
, starting with this map of uninhabited land.
}
662 Message
49 #7f7fff {Restore a Saved City} \
663 {This city was saved in the
file named
: %s
}
665 Message
100 #7fff7f {YOU'RE A WINNER!} \
666 {Your mayorial skill and city planning expertise have earned you the KEY TO THE CITY. Local residents will erect monuments to your glory and name their first-born children
after you. Why not run
for governor?
} \
667 {{middle
{@images
/key2city.xpm
}}}
669 Message
200 #ff4f4f {IMPEACHMENT NOTICE!} \
670 {The entire population of this city has finally had enough of your inept planning and incompetant management. An angry mob
-- led by your mother
-- has been spotted in the vicinity of city hall.
672 You should seriously consider taking an extended vacation
-- NOW.
(Or
read the manual and try again.
)}
674 Message
300 #ffd700 {About Micropolis} \
675 "Micropolis Version [sim Version] Copyright (C) 2007
677 Based on the Original Micropolis Concept and Design
679 TCL/Tk User Interface Designed and Created
680 by Don Hopkins, DUX Software.
681 Ported to Linux, Optimized and Adapted for OLPC
683 Licensed under the GNU General Public License,
684 version 3, with additional conditions."
687 ########################################################################
689 ########################################################################
692 option add
*CheckButton.relief flat
693 option add
*Dialog.cursor top_left_arrow
694 option add
*Entry.relief sunken
695 option add
*Frame.borderWidth
0
696 option add
*Listbox.relief sunken
697 option add
*Scrollbar.relief sunken
698 option add
*RadioButton.anchor w
699 option add
*RadioButton.relief flat
701 option add
*background
#b0b0b0
702 option add
*foreground
#000000
703 option add
*activeBackground
#d0d0d0
704 option add
*activeForeground
#000000
705 option add
*disabledForeground
""
706 option add
*selectBackground
#d0d0d0
707 option add
*selectForeground
#000000
708 #option add *selector #ffff80
709 option add
*selector
#bf0000
711 option add
*Scrollbar.Background
#b0b0b0
712 option add
*Scrollbar.Foreground
#d0d0d0
713 option add
*Interval.Background
#b0b0b0
714 option add
*Interval.Foreground
#000000
715 option add
*Interval.activeForeground
#d0d0d0
716 option add
*Interval.sliderForeground
#b0b0b0
717 option add
*Scale.activeForeground
#d0d0d0
718 option add
*Scale.sliderForeground
#b0b0b0
719 option add
*PieMenu.activeBackground
#b0b0b0
721 option add Mwm
*Micropolis.clientDecoration
-maximize
724 ########################################################################
726 ########################################################################
729 bind all
<Help
> {HandleHelp
%W
%x
%y
%X
%Y
}
730 bind all
<Shift-ButtonPress
> {HandleHelp
%W
%x
%y
%X
%Y
}
731 bind all
<Meta-ButtonPress
> {HandleHelp
%W
%x
%y
%X
%Y
}
732 bind all
<Shift-Meta-ButtonPress
> {HandleHelp
%W
%x
%y
%X
%Y
}
735 ########################################################################
737 ########################################################################
756 puts stderr
"$errorInfo"
764 proc NoFunction
{args
} {}
767 proc LinkWindow
{fromname to
} {
769 set WindowLinks
($fromname) $to
773 proc WindowLink
{fromname
} {
776 catch {set to
$WindowLinks($fromname)}
781 proc DeleteWindow
{sym name win
} {
782 set head
[WindowLink
$win.head
]
783 LinkWindow
$head.
$sym {}
785 set wins
[eval ident
"\$$name"]
786 set i
[lsearch $wins $win]
788 set $name [lreplace $wins $i $i]
794 proc Font
{win name
} {
795 global FontInfo FontCache HeadWindows
796 set scr
[winfo screen
$win]
799 set font $FontCache($scr,$name)
804 set label $FontCache($scr)
806 if {"$label" == ""} {
807 foreach head
$HeadWindows {
808 if {"[winfo screen $head]" == "$scr"} {
809 set label $head.fontlabel
810 label $label -text "X11 Sucks" -font fixed
811 set FontCache
($scr) $label
816 set fonts
[keylget FontInfo
$name]
817 foreach font $fonts {
818 #echo "Configuring font $font on $label"
819 if {[catch "$label config -font \"$font\""] == 0} {
832 set FontCache
($scr,$name) $font
838 proc Color
{win color mono
} {
839 if {[winfo screendepth
$win] == 1} {
847 ########################################################################
848 # Window Definition Functions
849 ########################################################################
852 proc MakeWindow.head
{{display
":0"}} {
854 source $ResourceDir/whead.tcl
859 proc MakeWindow.editor
{head
{display
":0"}} {
861 source $ResourceDir/weditor.tcl
866 proc MakeWindow.map
{head
{display
":0"}} {
868 source $ResourceDir/wmap.tcl
873 proc MakeWindow.graph
{head
{display
":0"}} {
875 source $ResourceDir/wgraph.tcl
880 proc MakeWindow.budget
{head
{display
":0"}} {
882 source $ResourceDir/wbudget.tcl
887 proc MakeWindow.evaluation
{head
{display
":0"}} {
889 source $ResourceDir/weval.tcl
894 proc MakeWindow.splash
{head
{display
":0"}} {
896 source $ResourceDir/wsplash.tcl
901 proc MakeWindow.scenario
{head
{display
":0"}} {
903 source $ResourceDir/wscen.tcl
908 proc MakeWindow.
file {head
{display
":0"}} {
910 source $ResourceDir/wfile.tcl
915 proc MakeWindow.ask
{head
{display
":0"}} {
917 source $ResourceDir/wask.tcl
922 proc MakeWindow.player
{head
{display
":0"}} {
924 source $ResourceDir/wplayer.tcl
929 proc MakeWindow.notice
{head
{display
":0"}} {
931 source $ResourceDir/wnotice.tcl
935 proc MakeWindow.help
{head
{display
":0"}} {
937 source $ResourceDir/whelp.tcl
941 proc MakeWindow.frob
{head
{display
":0"}} {
943 source $ResourceDir/wfrob.tcl
948 ########################################################################
950 ########################################################################
953 proc UIInitializeSound
{} {
957 proc UIShutDownSound
{} {
961 proc UIDoSoundOn
{win cmd
} {
962 global Sound SoundServers
964 set win
[WindowLink
[winfo toplevel $win].head
]
965 if {[lsearch $SoundServers $win] != -1} {
966 set cmd
"send -quick -server $win Sound sound $cmd"
968 # XXX: Lost a sound server...
976 proc UIDoSound
{cmd
} {
977 global Sound SoundServers
979 foreach win
$SoundServers {
980 set foo
"send -quick -server $win Sound $cmd"
982 # XXX: Lost a sound server...
990 proc KillSoundServers
{} {
992 foreach win
$SoundServers {
993 set foo
"send -quick -server $win Sound KillSoundServer"
1000 proc UISetChannelVolume
{win chan vol
} {
1001 UIDoSoundOn
$win "channel $chan -volume $vol"
1005 proc EchoPlaySound
{soundspec
} {
1009 proc UIMakeSoundOn
{win chan sound
{opts
""}} {
1010 playsound
$chan $sound $opts
1014 proc UIStartSoundOn
{win chan sound
{opts
""}} {
1015 # Send message to Python to play sound.
1016 EchoPlaySound
$sound
1018 #UIDoSoundOn $win "play $sound -replay -channel $chan -repeat 100 $opts"
1022 proc UIMakeSound
{chan sound
{opts
""}} {
1023 playsound
$chan $sound $opts
1027 proc UIStartSound
{chan sound
{opts
""}} {
1028 # Send message to Python to play sound.
1029 EchoPlaySound
$sound
1031 #UIDoSound "sound play $sound -channel $chan -repeat 100 $opts"
1035 proc SetupSoundServer
{win
} {
1040 proc AddSoundServer
{win
} {
1042 set i
[lsearch $SoundServers $win]
1044 set SoundServers
[linsert $SoundServers 0 $win]
1049 proc LostSoundServer
{win
} {
1050 DeleteSoundServer
$win
1051 # UIShowPictureOn [WindowLink $win.head] 46 [winfo screen $win]
1055 proc DeleteSoundServer
{win
} {
1057 set i
[lsearch $SoundServers $win]
1059 set SoundServers
[lreplace $SoundServers $i $i]
1064 proc UISoundOff
{} {
1068 proc MonsterSpeed
{} {
1069 return [expr "[sim Rand 40] + 70"]
1073 proc ExplosionPitch
{} {
1074 return [expr "[sim Rand 20] + 90"]
1079 return [expr "[sim Rand 20] + 90"]
1083 ########################################################################
1084 # Global Window Handlers
1087 proc WithdrawAll
{} {
1105 proc ShowInitial
{} {
1113 ########################################################################
1114 # Head Window Handlers
1117 proc PrepHead
{head
} {
1124 WithdrawHeadOf
$head
1128 after 1000 "WithdrawSplashOf $head"
1129 WithdrawHeadOf
$head
1130 ShowScenarioOf
$head
1134 WithdrawSplashOf
$head
1135 WithdrawScenarioOf
$head
1140 ReShowPictureOn
$head
1148 proc ShowHeadOf
{head
} {
1153 proc WithdrawHeadOf
{head
} {
1160 foreach win
$HeadWindows {
1166 proc WithdrawHeads
{} {
1168 foreach win
$HeadWindows {
1174 proc DeleteHeadWindow
{head
} {
1181 foreach win
$HeadWindows {
1187 proc InitHead
{win
} {
1188 set w
[WindowLink
$win.
text]
1189 $w configure
-state normal
1192 $w configure
-state disabled
1194 if {[sim MultiPlayerMode
]} {
1195 set w
[WindowLink
$win.
entry]
1206 proc InitAllHeadMenus
{} {
1209 foreach win
$HeadWindows {
1215 proc InitHeadMenus
{win
} {
1217 set m0
[WindowLink
$win.m0
]
1218 set m1
[WindowLink
$win.m1
]
1219 set m2
[WindowLink
$win.m2
]
1220 set m3
[WindowLink
$win.m3
]
1221 set m4
[WindowLink
$win.m4
]
1222 set b0
[WindowLink
$win.b0
]
1223 set b1
[WindowLink
$win.b1
]
1224 set b2
[WindowLink
$win.b2
]
1225 set b3
[WindowLink
$win.b3
]
1226 set b4
[WindowLink
$win.b4
]
1240 # When in multi player mode there is an extra menu
1241 # item to add another player, before the quit item,
1242 # so compensate for it here.
1243 if {[sim MultiPlayerMode
]} {
1248 $b0 config
-state normal
1249 $b2 config
-state disabled
1250 $b4 config
-state disabled
1255 # When in multi player mode there is an extra menu
1256 # item to add another player, before the quit item,
1257 # so compensate for it here.
1258 if {[sim MultiPlayerMode
]} {
1263 $b0 config
-state normal
1264 $b2 config
-state normal
1265 $b4 config
-state normal
1271 proc UIDisaster
{win cmd action
} {
1272 AskQuestion
[Color
$win #ff0000 #ffffff] "Cause a Disaster" \
1273 "Oh no! Do you really want to $action" \
1274 "{No way!} Disaster.No {WithdrawAsks}" \
1276 "{I guess so.} Disaster.Yes {WithdrawAsks ; $cmd}"
1280 proc CrushHead
{head
} {
1281 global SubWindows VoteNames
1283 foreach foo
$VoteNames {
1285 set votes
[eval ident
\$VotesFor$foo]
1286 set i
[lsearch $votes $head]
1288 set VotesFor
$foo [lreplace $votes $i $i]
1292 foreach foo
$SubWindows {
1293 set sym
[lindex $foo 0]
1294 set name
[lindex $foo 1]
1296 set wins
[eval ident
"\$$name"]
1298 if {[WindowLink
$win.head
] == $head} {
1299 DeleteWindow
$sym $name $win
1306 proc ChatDown
{win
} {
1328 global ChatConnection
1330 DoSendMessage
"Opening Connection to Chat Server $ChatServer socket $ChatSocket ..." status
1332 set ChatConnection
{}
1334 set ChatConnection
[connect
$ChatServer $ChatSocket]
1337 if {$ChatConnection == {}} then
{
1338 DoSendMessage
"Sorry, I could not open a connection to chat server $ChatServer socket $ChatSocket." status
1341 filehandler
$ChatConnection r
"ReceiveChat"
1352 puts $ChatConnection "USER $UserName $HostName $ServerName $RealName\r\n" nonewline
1353 puts $ChatConnection "NICK $NickName\r\n" nonewline
1354 puts $ChatConnection "JOIN $ChannelName\r\n" nonewline
1355 flush $ChatConnection
1360 proc ReceiveChat
{mode f
} {
1361 # DoSendMessage "ReceiveChat: MODE $mode F $f"
1365 if {[string first
{:} $msg]} {
1369 set from
[lindex $msg 0]
1370 set cmd
[string tolower
[lindex $msg 1]]
1374 if {($cmd == "privmsg") ||
1375 ($cmd == "notice")} then
{
1377 set chan
[lindex $msg 2]
1378 set i
[expr "[string length $from] + 1 + [string length $cmd] + 1 + [string length $chan] + 2"]
1379 set j
[expr "[string length $msg] - 2"]
1380 set line
[string range
$msg $i $j]
1381 set chan
[string range
$chan 1 [string length
$chan]]
1382 set from
[string range
$from 1 [expr "[string length $from] - 1"]]
1383 set from
[split $from {!}]
1384 set from
[lindex $from 0]
1385 DoSendMessage
"$from> $line"
1388 if {$handled == 0} {
1389 set msg
[string range
$msg \
1390 [expr "[string length $from] + 1"] \
1391 [expr "[string length $msg] - 2"]]
1397 proc SendChatMessage
{msg win
} {
1398 global ChatConnection ChannelName NickName
1404 if {[string range
$msg 0 0] == "/"} {
1405 set cmd
[string range
$msg 1 [string length
$msg]]
1406 DoSendMessage
"$NickName> \[$cmd\]"
1409 set cmd
"PRIVMSG $ChannelName :$msg\r\n"
1410 DoSendMessage
"$NickName> $msg"
1417 puts $ChatConnection $cmd nonewline
1418 flush $ChatConnection
1423 DoSendMessage
"IRC Broke the connection"
1433 global ChatConnection
1435 DoSendMessage
"Closing Connection to Chat Server." status
1438 puts $ChatConnection "QUIT\r\n" nonewline
1439 flush $ChatConnection
1440 $ChatConnection close
1443 set ChatConnection
{}
1448 proc DoEnterMessage
{win var
} {
1451 set msg
[eval ident
"\$\{$var\}"]
1453 if {$Chatting} then
{
1454 SendChatMessage
$msg $win
1462 proc DoEvalMessage
{win var
} {
1464 set command
[eval ident
"\$\{$var\}"]
1466 DoSendMessage
"Evaluating TCL: $command"
1467 catch {uplevel #0 $command} result
1468 DoSendMessage
"Result: $result"
1472 proc DoSendMessage
{msg
{tag
message}} {
1474 foreach win
$HeadWindows {
1475 appendWithTag
[WindowLink
$win.
text] $tag "$msg"
1480 proc UISetMessage
{msg
{tag status
}} {
1481 global DoMessages EditorWindows HeadWindows
1483 if {$DoMessages == 0} {
1487 foreach win
$EditorWindows {
1488 [WindowLink
$win.
message] configure
-text "$msg"
1491 foreach win
$HeadWindows {
1492 appendWithTag
[WindowLink
$win.
text] $tag "$msg"
1499 proc appendWithTag
{w tag
text} {
1503 set start
[$w index end
]
1504 $w configure
-state normal
1505 if {$start > $MaxLines} then
{
1506 $w delete
0.0 $ShrinkLines.0
1507 set start
[$w index end
]
1509 $w insert end
"${text}\n"
1510 $w tag add
$tag $start {end
- 1 char
}
1511 $w configure
-state disabled
1512 $w yview
-pickplace {end
- 1 char
}
1516 ########################################################################
1517 # Budget Window Handlers
1520 proc ShowBudgetOf
{head
} {
1521 set win
[WindowLink
$head.budget
]
1523 set win
[MakeWindow.budget
$head [winfo screen
$head]]
1532 proc ShowBudgets
{} {
1533 global HeadWindows BudgetsVisible
1534 set BudgetsVisible
1
1535 foreach win
$HeadWindows {
1541 proc WithdrawBudgets
{} {
1542 global BudgetWindows BudgetsVisible
1543 foreach win
$BudgetWindows {
1547 set BudgetsVisible
0
1551 proc BudgetContinue
{{win
""}} {
1552 global OldBudget BudgetRoadFund BudgetFireFund BudgetPoliceFund BudgetTaxRate
1554 if {([sim RoadFund
] != $BudgetRoadFund) ||
1555 ([sim FireFund
] != $BudgetFireFund) ||
1556 ([sim PoliceFund
] != $BudgetPoliceFund) ||
1557 ([sim TaxRate
] != $BudgetTaxRate)} {
1558 UISetMessage
"The budget was changed."
1560 UISetMessage
"The budget wasn't changed."
1568 proc BudgetReset
{{win
""}} {
1569 global OldBudget BudgetRoadFund BudgetFireFund BudgetPoliceFund BudgetTaxRate
1570 if {([sim RoadFund
] != $BudgetRoadFund) ||
1571 ([sim FireFund
] != $BudgetFireFund) ||
1572 ([sim PoliceFund
] != $BudgetPoliceFund) ||
1573 ([sim TaxRate
] != $BudgetTaxRate)} {
1574 UISetMessage
"The budget was reset."
1575 if {[sim Players
] > 1} {
1576 UIMakeSound edit Sorry
1579 UISetMessage
"The budget was reset."
1581 sim RoadFund
$BudgetRoadFund
1582 sim FireFund
$BudgetFireFund
1583 sim PoliceFund
$BudgetPoliceFund
1584 sim TaxRate
$BudgetTaxRate
1590 proc BudgetCancel
{{win
""}} {
1598 proc SetTaxRate
{rate
} {
1603 proc BudgetSetTaxRate
{rate
} {
1609 proc BudgetSetRoadFund
{percent
} {
1610 sim RoadFund
$percent
1615 proc BudgetSetFireFund
{percent
} {
1616 sim FireFund
$percent
1621 proc BudgetSetPoliceFund
{percent
} {
1622 sim PoliceFund
$percent
1627 proc UIShowBudgetAndWait
{} {
1628 global OldBudget BudgetRoadFund BudgetFireFund BudgetPoliceFund BudgetTaxRate
1629 if {$OldBudget == 0} {
1630 set BudgetRoadFund
[sim RoadFund
]
1631 set BudgetFireFund
[sim FireFund
]
1632 set BudgetPoliceFund
[sim PoliceFund
]
1633 set BudgetTaxRate
[sim TaxRate
]
1637 UISetMessage
"Pausing to set the budget ..."
1643 sim UpdateBudgetWindow
1647 proc ToggleBudgetTimer
{} {
1648 global BudgetTimerActive
1649 if {$BudgetTimerActive} {
1657 proc StopBudgetTimer
{} {
1658 global BudgetTimerActive
1659 set BudgetTimerActive
0
1664 proc StartBudgetTimer
{} {
1665 global BudgetTimerActive BudgetTimer BudgetTimeout
1667 set BudgetTimerActive
$me
1668 set BudgetTimer
$BudgetTimeout
1670 after 1000 TickBudgetTimer
$me
1674 proc RestartBudgetTimer
{} {
1675 global BudgetTimerActive
1676 if {$BudgetTimerActive} {
1683 proc UpdateBudgetTimer
{} {
1684 global BudgetWindows BudgetTimerActive BudgetTimer
1685 if {$BudgetTimerActive} {
1686 set text [format "Auto Cancel In %d Seconds (click to disable)" $BudgetTimer]
1688 set text [format "Enable Auto Cancel (currently disabled)"]
1690 foreach win
$BudgetWindows {
1691 set t
[WindowLink
$win.timer
]
1692 $t config
-text "$text"
1697 proc TickBudgetTimer
{me
} {
1698 global BudgetTimerActive BudgetTimer BudgetTimeout
1699 if {$BudgetTimerActive == $me} {
1701 if {$BudgetTimer < 0} {
1707 after 1000 TickBudgetTimer
$me
1713 proc FireBudgetTimer
{} {
1723 proc ToggleAutoBudget
{} {
1726 #echo "ToggleAutoBudget found on, clearing"
1729 #echo "ToggleAutoBudget found off, setting"
1735 proc UIUpdateBudget
{} {
1740 proc UpdateAutoBudget
{} {
1741 global BudgetWindows AutoBudget
1742 if {[sim AutoBudget
]} {
1743 set text "Disable Auto Budget (currently enabled)"
1745 set text "Enable Auto Budget (currently disabled)"
1747 #echo "UpdateAutoBudget $AutoBudget $text"
1748 foreach win
$BudgetWindows {
1749 set t
[WindowLink
$win.autobudget
]
1750 $t config
-text "$text"
1755 proc UISetBudget
{cashflow previous current collected taxrate
} {
1756 global BudgetWindows BudgetsVisible
1758 #echo "UISetBudgetValues $taxrate $BudgetsVisible"
1760 if {$BudgetsVisible} {
1762 foreach win
$BudgetWindows {
1763 set w
[WindowLink
$win.cashflow
]
1764 set old
[lindex [$w configure
-text] 4]
1765 if {$old != $cashflow} {
1766 $w configure
-text $cashflow
1768 set w
[WindowLink
$win.previous
]
1769 set old
[lindex [$w configure
-text] 4]
1770 if {$old != $previous} {
1771 $w configure
-text $previous
1773 set w
[WindowLink
$win.current
]
1774 set old
[lindex [$w configure
-text] 4]
1775 if {$old != $current} {
1776 $w configure
-text $current
1778 set w
[WindowLink
$win.collected
]
1779 set old
[lindex [$w configure
-text] 4]
1780 if {$old != $collected} {
1781 $w configure
-text $collected
1784 set w
[WindowLink
$win.taxrate
]
1786 if {$old != $taxrate} {
1790 set w
[WindowLink
$win.taxlabel
]
1791 set old
[lindex [$w configure
-text] 4]
1794 $w configure
-text $new
1800 foreach win
$HeadWindows {
1802 set w
[WindowLink
$win.taxrate
]
1804 if {$old != $taxrate} {
1805 # FIXME: this might not work if the slider is disabled in multi player mode.
1809 set w
[WindowLink
$win.taxlabel
]
1810 set old
[lindex [$w configure
-text] 4]
1811 set new
"Tax Rate: $taxrate%"
1813 $w configure
-text $new
1819 proc UISetBudgetValues
{roadgot roadwant roadpercent policegot policewant policepercent firegot firewant firepercent
} {
1820 global BudgetWindows BudgetsVisible
1822 if {$BudgetsVisible == 0} {
1826 foreach win
$BudgetWindows {
1827 set w
[WindowLink
$win.fire
].request
1828 set old
[lindex [$w configure
-text] 4]
1829 set new
"$firepercent% of $firewant = $firegot"
1831 $w configure
-text $new
1833 set w
[WindowLink
$win.fire
].fund
1835 if {$old != $firepercent} {
1839 set w
[WindowLink
$win.police
].request
1840 set old
[lindex [$w configure
-text] 4]
1841 set new
"$policepercent% of $policewant = $policegot"
1843 $w configure
-text $new
1845 set w
[WindowLink
$win.police
].fund
1847 if {$old != $policepercent} {
1848 $w set $policepercent
1851 set w
[WindowLink
$win.road
].request
1852 set old
[lindex [$w configure
-text] 4]
1853 set new
"$roadpercent% of $roadwant = $roadgot"
1855 $w configure
-text $new
1857 set w
[WindowLink
$win.road
].fund
1859 if {$old != $roadpercent} {
1866 proc ChangeBudget
{} {
1867 global VotesForBudget
1868 if {"$VotesForBudget" != ""} {
1875 proc InitVotesForBudget
{} {
1876 global VotesForBudget BudgetWindows
1877 set VotesForBudget
{}
1878 foreach win
$BudgetWindows {
1879 [WindowLink
$win.vote
] config
-relief raised
1881 UpdateVotesForBudget
1885 proc UpdateVotesForBudget
{} {
1886 global BudgetWindows
1887 UpdateVotesFor Budget
$BudgetWindows
1891 proc UpdateTaxRateSliders
{} {
1893 set players
[sim Players
]
1894 foreach win
$HeadWindows {
1895 set slider
[WindowLink
$win.taxrate
]
1896 #echo "UpdateTaxRateSliders players $players win $win slider $slider"
1897 if {$players == 1} {
1898 $slider configure
-state normal
1900 $slider configure
-state disabled
1906 ########################################################################
1907 # Evaluation Window Handlers
1910 proc ToggleEvaluationOf
{head
} {
1912 if {"$State" != "play"} {
1917 set win
[WindowLink
$head.evaluation
]
1919 set mapped
[winfo ismapped
$win]
1923 WithdrawEvaluationOf
$head
1925 ShowEvaluationOf
$head
1931 proc WithdrawEvaluationOf
{head
} {
1932 set win
[WindowLink
$head.evaluation
]
1939 proc ShowEvaluationOf
{head
} {
1940 set win
[WindowLink
$head.evaluation
]
1942 set win
[MakeWindow.evaluation
$head [winfo screen
$head]]
1946 set parent
[WindowLink
$win.parent
]
1947 #pack append [WindowLink $head.col2]\
1948 # $parent {top frame nw fill}
1949 pack append $parent\
1950 $win {top
frame nw fillx
}
1952 sim UpdateEvaluation
1956 proc WithdrawEvaluations
{} {
1957 global EvaluationWindows EvaluationsVisible
1958 foreach win
$EvaluationWindows {
1960 #set parent [WindowLink $win.parent]
1961 #pack unpack $parent
1964 set EvaluationsVisible
0
1968 proc EvaluationVisible
{w v
} {
1969 global EvaluationsVisible
1970 global [set var
$w.visible
]
1975 set EvaluationsVisible
[expr "$EvaluationsVisible + 1"]
1977 set EvaluationsVisible
[expr "$EvaluationsVisible - 1"]
1982 proc UISetEvaluation
{changed score ps0 ps1 ps2 ps3 pv0 pv1 pv2 pv3 pop delta assessed cityclass citylevel goodyes goodno title
} {
1983 global EvaluationWindows EvaluationsVisible CurrentDate
1985 set class
[string tolower
$cityclass]
1986 UISetMessage
"$CurrentDate: Score $score, $class population $pop."
1988 if {$EvaluationsVisible} {
1990 foreach win
$EvaluationWindows {
1992 global [set var
$win.visible
]
1993 set visible
[eval ident
"\$\{$var\}"]
1997 # TODO: set evaluation window and icon title
1998 #wm title $win "$title"
1999 #wm iconname $win "$title"
2001 set w
[WindowLink
$win.goodjob
]
2002 set old
[lindex [$w configure
-text] 4]
2003 set new
"$goodyes\n$goodno"
2005 $w configure
-text $new
2008 set w
[WindowLink
$win.problemnames
]
2009 set old
[lindex [$w configure
-text] 4]
2010 set new
"$ps0\n$ps1\n$ps2\n$ps3"
2012 $w configure
-text $new
2015 set w
[WindowLink
$win.problempercents
]
2016 set old
[lindex [$w configure
-text] 4]
2017 set new
"$pv0\n$pv1\n$pv2\n$pv3"
2019 $w configure
-text $new
2022 set w
[WindowLink
$win.stats
]
2023 set old
[lindex [$w configure
-text] 4]
2024 set new
"$pop\n$delta\n\n$assessed\n$cityclass\n$citylevel"
2026 $w configure
-text $new
2029 set w
[WindowLink
$win.score
]
2030 set old
[lindex [$w configure
-text] 4]
2031 set new
"$score\n$changed"
2033 $w configure
-text $new
2041 ########################################################################
2042 # File Window Handlers
2045 proc ShowFileOf
{head
} {
2046 set win
[WindowLink
$head.
file]
2048 set win
[MakeWindow.
file $head [winfo screen
$head]]
2058 foreach win
$HeadWindows {
2064 proc WithdrawFiles
{} {
2066 foreach win
$FileWindows {
2072 proc DoFileDialog
{win Message Path Pattern FileName ActionOk ActionCancel
} {
2073 ShowFileDialog
$win "$Path" "$Pattern"
2074 $win.message1 configure
-text "$Message"
2075 $win.path.path delete
0 end
2076 $win.path.path insert
0 $Path
2077 $win.
file.
file delete
0 end
2078 $win.
file.
file insert
0 "$FileName"
2079 $win.frame1.ok config
-command "
2080 $ActionOk \[$win.file.file get\] \[$win.path.path get\]
2082 $win.frame1.rescan config
-command "
2083 ShowFileDialog $win \[$win.path.path get\] $Pattern"
2084 $win.frame1.cancel config
-command "
2087 bind $win.files.files
"<Double-Button-1>" "\
2088 FileSelectDouble $win %W %y $Pattern \"
2089 $ActionOk {\[$win.file.file get\]} {\[$win.path.path get\]}\""
2090 bind $win.path.path
<Return
> "
2091 ShowFileDialog $win \[$win.path.path get\] $Pattern
2092 $win.file.file cursor 0
2093 focus $win.file.file"
2094 bind $win.
file.
file <Return
> "\
2095 $ActionOk \[$win.file.file get\] \[$win.path.path get\]
2100 proc BindSelectOne
{win Y
} {
2101 set Nearest
[$win nearest
$Y]
2102 if {$Nearest >= 0} {
2103 $win select from
$Nearest
2104 $win select to
$Nearest
2109 proc FileSelect
{win widget Y
} {
2110 BindSelectOne
$widget $Y
2111 set Nearest
[$widget nearest
$Y]
2112 if {$Nearest >= 0} {
2113 set Path
[$win.path.path get
]
2114 set TmpEntry
[$widget get
$Nearest]
2115 if {[string compare
"/" [string index
$TmpEntry \
2116 [expr [string length
$TmpEntry]-1]]] == 0 ||
\
2117 [string compare
"@" [string index
$TmpEntry \
2118 [expr [string length
$TmpEntry]-1]]] == 0} {
2119 # handle directories, and symbolic links to directories
2120 set FileName
[string range
$TmpEntry 0 \
2121 [expr [string length
$TmpEntry]-2]]
2122 # whoops / or @ is part of the name
2123 if {[MiscIsDir
$Path/$FileName] != 1} {
2124 set FileName
$TmpEntry
2127 if {[string compare
"*" [string index
$TmpEntry \
2128 [expr [string length
$TmpEntry]-1]]] == 0} {
2129 # handle executable filenames
2130 set FileName
[string range
$TmpEntry 0 \
2131 [expr [string length
$TmpEntry]-2]]
2132 # whoops * is part of the name
2133 if {[file executable
$Path/$FileName] != 1} {
2134 set FileName
$TmpEntry
2137 # a ordinary filename
2138 set FileName
$TmpEntry
2141 # enter the selected filename into the filename field
2142 if {[MiscIsDir
$Path/$FileName] != 1} {
2143 $win.
file.
file delete
0 end
2144 $win.
file.
file insert
0 $FileName
2150 proc FileSelectDouble
{win widget Y Pattern Action
} {
2151 BindSelectOne
$widget $Y
2152 set Nearest
[$widget nearest
$Y]
2153 if {$Nearest >= 0} {
2154 set Path
[$win.path.path get
]
2155 set TmpEntry
[$widget get
$Nearest]
2156 if {[string compare
$TmpEntry "../"] == 0} {
2157 # go up one directory
2159 [string trimright
[string trimright
[string trim
$Path] /] @]
2160 if {[string length
$TmpEntry] <= 0} {
2163 set Path
[file dirname
$TmpEntry]
2164 $win.path.path delete
0 end
2165 $win.path.path insert
0 $Path
2166 ShowFileDialog
$win $Path $Pattern
2168 if {[string compare
"/" [string index
$TmpEntry \
2169 [expr [string length
$TmpEntry]-1]]] == 0 ||
\
2170 [string compare
"@" [string index
$TmpEntry \
2171 [expr [string length
$TmpEntry]-1]]] == 0} {
2172 # handle directorys, and symbolic links to directorys
2173 set FileName
[string range
$TmpEntry 0 \
2174 [expr [string length
$TmpEntry]-2]]
2175 # whoops / or @ is part of the name
2176 if {[MiscIsDir
$Path/$FileName] != 1} {
2177 set FileName
$TmpEntry
2180 if {[string compare
"*" [string index
$TmpEntry \
2181 [expr [string length
$TmpEntry]-1]]] == 0} {
2182 # handle executable filenames
2183 set FileName
[string range
$TmpEntry 0 \
2184 [expr [string length
$TmpEntry]-2]]
2185 # whoops * is part of the name
2186 if {[file executable
$Path/$FileName] != 1} {
2187 set FileName
$TmpEntry
2190 # a ordinary filename
2191 set FileName
$TmpEntry
2195 if {[MiscIsDir
$Path/$FileName] == 1} {
2196 if {[string compare
"/" [string index
$Path \
2197 [expr [string length
$Path]-1]]] == 0} {
2198 append Path
$FileName
2200 append Path
/ $FileName
2202 $win.path.path delete
0 end
2203 $win.path.path insert
0 $Path
2204 ShowFileDialog
$win $Path $Pattern
2206 # enter the selected filename into the filename field
2207 $win.
file.
file delete
0 end
2208 $win.
file.
file insert
0 "$FileName"
2209 if {[string length
$Action] > 0} {
2219 proc NameComplete
{win Type
} {
2224 if {[string compare
$Type path
] == 0} {
2225 set DirName
[file dirname
[$win.path.path get
]]
2226 set FileName
[file tail
[$win.path.path get
]]
2228 set DirName
[file dirname
[$win.path.path get
]/]
2229 set FileName
[file tail
[$win.
file.
file get
]]
2233 if {[MiscIsDir
$DirName] == 1} {
2234 catch "exec ls $DirName/" Result
2236 set ListLength
[llength $Result]
2238 while {$Counter < $ListLength} {
2239 if {[string length
$FileName] == 0} {
2240 if {$FoundCounter == 0} {
2241 set NewFile
[lindex $Result $Counter]
2244 set TmpFile1
$NewFile
2245 set TmpFile2
[lindex $Result $Counter]
2246 set Length1
[string length
$TmpFile1]
2247 set Length2
[string length
$TmpFile2]
2249 if {$Length1 > $Length2} {
2250 set Length1
$Length2
2252 while {$Counter1 < $Length1} {
2253 if {[string compare
[string index
$TmpFile1 $Counter1] \
2254 [string index
$TmpFile2 $Counter1]] == 0} {
2255 append NewFile
[string index
$TmpFile1 $Counter1]
2264 if {[regexp "^$FileName" [lindex $Result $Counter] \
2266 if {$FoundCounter == 0} {
2267 set NewFile
[lindex $Result $Counter]
2270 set TmpFile1
$NewFile
2271 set TmpFile2
[lindex $Result $Counter]
2272 set Length1
[string length
$TmpFile1]
2273 set Length2
[string length
$TmpFile2]
2275 if {$Length1 > $Length2} {
2276 set Length1
$Length2
2278 while {$Counter1 < $Length1} {
2279 if {[string compare
[string index
$TmpFile1 $Counter1] \
2280 [string index
$TmpFile2 $Counter1]] == 0} {
2281 append NewFile
[string index
$TmpFile1 $Counter1]
2295 if {$FoundCounter == 1} {
2296 if {[MiscIsDir
$DirName/$NewFile] == 1} {
2297 if {[string compare
$DirName "/"] == 0} {
2298 $win.path.path delete
0 end
2299 $win.path.path insert
0 "/[string trim [string trim $NewFile /] @]/"
2301 $win.path.path delete
0 end
2302 $win.path.path insert
0 "[string trimright $DirName /]/[string trim [string trim $NewFile /] @]/"
2305 $win.path.path delete
0 end
2306 $win.path.path insert
0 \
2307 "[string trim [string trimright $DirName /] @]/"
2308 $win.
file.
file delete
0 end
2309 $win.
file.
file insert
0 "$NewFile"
2312 if {[MiscIsDir
$DirName/$NewFile] == 1 ||
2313 [string compare
$Type path
] == 0} {
2314 $win.path.path delete
0 end
2315 $win.path.path insert
0 \
2316 "[string trimright $DirName /]/[string trim [string trim $NewFile /] @]"
2318 $win.path.path delete
0 end
2319 $win.path.path insert
0 "$DirName"
2320 if {[string length
$NewFile] > 0} {
2321 $win.
file.
file delete
0 end
2322 $win.
file.
file insert
0 "$NewFile"
2329 proc ShowFileDialog
{win Path Pattern
} {
2331 #set Path [lindex [split $Path] 0]
2332 if {[$win.files.files size
] > 0} {
2333 $win.files.files delete
0 end
2336 if {[catch "exec ls -F \"$Path\"" Result
]} {
2339 if {[string match
$Result "* not found"]} {
2342 set ElementList
[lsort [split $Result "\n"]]
2345 if {[string compare
$Path "/"]} {
2346 $win.files.files insert end
"../"
2350 foreach Counter
$ElementList {
2352 if {[string match
$Pattern $Counter] == 1} {
2353 if {[string compare
$Counter "../"] &&
2354 [string compare
$Counter "./"]} {
2355 $win.files.files insert end
$Counter
2358 set fn
$Path/[string trim
[string trim
[string trim
$Counter /] @] *]
2359 if {[MiscIsDir
$fn]} {
2360 $win.files.files insert end
$Counter
2368 proc MiscIsDir
{PathName
} {
2370 if {[file isdirectory
$PathName] == 1} {
2373 catch "file type $PathName" Type
2374 if {[string compare
$Type link
] == 0} {
2375 set LinkName
[file readlink
$PathName]
2376 catch "file type $LinkName" Type
2377 while {[string compare
$Type link
] == 0} {
2378 set LinkName
[file readlink
$LinkName]
2380 return [file isdirectory
$LinkName]
2387 proc busy
{win cmds
} {
2389 set list [winfo children
$win]
2391 while {$list != ""} {
2394 set class
[winfo class
$w]
2395 set cursor
[lindex [$w config
-cursor] 4]
2396 if {[winfo toplevel $w] == $w} {
2397 lappend busy
[list $w $cursor]
2399 set next
[concat $next [winfo children
$w]]
2405 catch {[lindex $w 0] config
-cursor watch
}
2410 set error [catch {uplevel eval [list $cmds]} result
]
2413 catch {[lindex $w 0] config
-cursor [lindex $w 1]}
2424 ########################################################################
2425 # Editor Window Handlers
2427 proc ShowEditorOf
{head
} {
2428 global EditorWindows
2430 foreach win
$EditorWindows {
2431 if {[WindowLink
$win.head
] == $head} {
2432 set parent
[WindowLink
$win.parent
]
2433 #pack append [WindowLink $head.col2]\
2434 # $parent {top frame nw expand fill}
2435 pack append $parent\
2436 $win {top
frame nw expand fill
}
2450 proc NewEditorOf
{head
} {
2451 set win
[MakeWindow.editor
$head [winfo screen
$head]]
2453 set parent
[WindowLink
$win.parent
]
2454 pack append $parent\
2455 $win {top
frame nw expand fill
}
2462 proc ShowEditors
{} {
2464 foreach win
$HeadWindows {
2470 proc WithdrawEditors
{} {
2471 global EditorWindows
2472 foreach win
$EditorWindows {
2473 #set parent [WindowLink $win.parent]
2474 #pack unpack $parent
2480 proc InitEditors
{} {
2481 global EditorWindows
2482 foreach win
$EditorWindows {
2488 proc InitEditor
{win
} {
2489 set e
[WindowLink
$win.view
]
2490 UISetToolState
$win 7
2495 global $e.TrackState
2496 set $e.TrackState
{}
2500 proc SetEditorAutoGoto
{win val
} {
2501 global AutoGoto.
$win
2502 set AutoGoto.
$win $val
2503 set e
[WindowLink
$win.view
]
2508 proc SetEditorControls
{win val
} {
2509 global Controls.
$win
2510 set Controls.
$win $val
2512 pack append $win $win.leftframe
{left
frame center filly
}
2514 pack unpack
$win.leftframe
2519 proc SetEditorOverlay
{win val
} {
2521 set Overlay.
$win $val
2522 set e
[WindowLink
$win.view
]
2527 proc SetEditorDynamicFilter
{win val
} {
2528 global DynamicFilter.
$win
2529 set DynamicFilter.
$win $val
2530 set e
[WindowLink
$win.view
]
2531 $e DynamicFilter
$val
2532 if {$val == 1} then
{
2533 ShowFrobOf
[WindowLink
$win.head
]
2538 proc SetEditorSkip
{win val
} {
2539 set e
[WindowLink
$win.view
]
2544 proc EditorToolDown
{mod w x y
} {
2545 global [set var
$w.TrackState
]
2549 case
[$w ToolState
] in
\
2551 UIMakeSoundOn
$w edit Rumble
"-repeat 4"
2559 set $var [list constrain_start
$x $y]
2560 $w ToolConstrain
$x $y
2565 EditorTool ToolDown
$w $x $y
2570 proc EditorToolDrag
{w x y
} {
2571 EditorTool ToolDrag
$w $x $y
2576 proc EditorToolUp
{w x y
} {
2577 global [set var
$w.TrackState
]
2580 case
[$w ToolState
] in
\
2588 EditorTool ToolUp
$w $x $y
2590 $w ToolConstrain
-1 -1
2597 proc EditorTool
{action w x y
} {
2598 global [set var
$w.TrackState
]
2599 set state
[eval ident
"\$\{$var\}"]
2600 case
[lindex $state 0] in
\
2602 set x0
[lindex $state 1]
2603 set y0
[lindex $state 2]
2604 set dx
[expr "$x - $x0"]
2605 set dy
[expr "$y - $y0"]
2606 if [expr "($dx > 16) || ($dx < -16)"] then
{
2607 $w ToolConstrain
-1 $y0
2610 if [expr "($dy > 16) || ($dy < -16)"] then
{
2611 $w ToolConstrain
$x0 -1
2620 proc StartChalk
{w
} {
2621 sim CollapseMotion
0
2625 proc StopChalk
{w
} {
2626 sim CollapseMotion
1
2630 proc EditorPanDown
{mod w x y
} {
2631 global [set var
$w.TrackState
]
2635 set $var [list constrain_start
$x $y]
2636 $w ToolConstrain
$x $y
2641 EditorTool PanStart
$w $x $y
2645 proc EditorPanDrag
{w x y
} {
2646 EditorTool PanTo
$w $x $y
2650 proc EditorPanUp
{w x y
} {
2653 EditorTool PanTo
$w $x $y
2654 $w ToolConstrain
-1 -1
2660 proc EditorKeyDown
{w k
} {
2665 proc EditorKeyUp
{w k
} {
2670 proc BindEditorButtons
{win
} {
2671 set w
[WindowLink
$win.top
]
2673 bind $win <1> "CancelPie $win ; EditorToolDown none %W %x %y"
2674 bind $win <B1-Motion
> {EditorToolDrag
%W
%x
%y
}
2675 bind $win <ButtonRelease-1
> {EditorToolUp
%W
%x
%y
}
2677 bind $win <Control-1
> "CancelPie $win ; EditorToolDown constrain %W %x %y"
2678 bind $win <Control-B1-Motion
> {EditorToolDrag
%W
%x
%y
}
2679 bind $win <Control-ButtonRelease-1
> {EditorToolUp
%W
%x
%y
}
2681 bind $win <2> "CancelPie $win ; EditorPanDown none %W %x %y"
2682 bind $win <B2-Motion
> {EditorPanDrag
%W
%x
%y
}
2683 bind $win <ButtonRelease-2
> {EditorPanUp
%W
%x
%y
}
2685 bind $win <Control-2
> "CancelPie $win ; EditorPanDown constrain %W %x %y"
2686 bind $win <Control-B2-Motion
> {EditorPanDrag
%W
%x
%y
}
2687 bind $win <Control-ButtonRelease-2
> {EditorPanUp
%W
%x
%y
}
2689 InitPie
$win $w.toolpie
2693 proc UISetFunds
{funds
} {
2695 foreach win
$HeadWindows {
2696 [WindowLink
$win.funds
] configure
-text "$funds"
2701 proc UISetDate
{date month year
} {
2705 set CurrentDate
"$date"
2707 foreach win
$HeadWindows {
2708 [WindowLink
$win.date
] Set
$month $year
2713 proc SetPriority
{index
} {
2739 proc UISetDemand
{r c i
} {
2740 global HeadWindows DemandRes DemandCom DemandInd
2746 if {$r <= 0} then
{set ry0
32} else {set ry0
24}
2747 set ry1
[expr "$ry0 - $r"]
2748 if {$c <= 0} then
{set cy0
32} else {set cy0
24}
2749 set cy1
[expr "$cy0 - $c"]
2750 if {$i <= 0} then
{set iy0
32} else {set iy0
24}
2751 set iy1
[expr "$iy0 - $i"]
2753 foreach win
$HeadWindows {
2754 set can
[WindowLink
$win.demand
]
2755 # $can coords r 8 $ry0 14 $ry1
2756 # $can coords c 17 $cy0 23 $cy1
2757 # $can coords i 26 $iy0 32 $iy1
2758 $can coords r
49 $ry0 55 $ry1
2759 $can coords c
58 $cy0 64 $cy1
2760 $can coords i
67 $iy0 73 $iy1
2765 proc UISetOptions
{autobudget autogoto autobulldoze disasters sound animation messages notices
} {
2766 global AutoBudget AutoGoto AutoBulldoze Disasters Sound
2767 set AutoBudget
$autobudget
2768 set AutoGoto
$autogoto
2769 set AutoBulldoze
$autobulldoze
2770 set Disasters
$disasters
2772 set DoAnimation
$animation
2773 set DoMessages
$messages
2774 set DoNotices
$notices
2778 proc UIDidToolRes
{win x y
} {
2779 UIMakeSoundOn
$win edit O
"-speed 140"
2783 proc UIDidToolCom
{win x y
} {
2784 UIMakeSoundOn
$win edit A
"-speed 140"
2788 proc UIDidToolInd
{win x y
} {
2789 UIMakeSoundOn
$win edit E
"-speed 140"
2793 proc UIDidToolFire
{win x y
} {
2794 UIMakeSoundOn
$win edit O
"-speed 130"
2798 proc UIDidToolQry
{win x y
} {
2799 UIMakeSoundOn
$win edit E
"-speed 200"
2803 proc UIDidToolPol
{win x y
} {
2804 UIMakeSoundOn
$win edit E
"-speed 130"
2808 proc UIDidToolWire
{win x y
} {
2809 UIMakeSoundOn
$win edit O
"-speed 120"
2813 proc UIDidToolDozr
{win x y
} {
2814 UIMakeSoundOn
$win edit Rumble
2818 proc UIDidToolRail
{win x y
} {
2819 UIMakeSoundOn
$win edit O
"-speed 100"
2823 proc UIDidToolRoad
{win x y
} {
2824 UIMakeSoundOn
$win edit E
"-speed 100"
2828 proc UIDidToolChlk
{win x y
} {
2832 proc UIDidToolEraser
{win x y
} {
2836 proc UIDidToolStad
{win x y
} {
2837 UIMakeSoundOn
$win edit O
"-speed 90"
2841 proc UIDidToolPark
{win x y
} {
2842 UIMakeSoundOn
$win edit A
"-speed 130"
2846 proc UIDidToolSeap
{win x y
} {
2847 UIMakeSoundOn
$win edit E
"-speed 90"
2851 proc UIDidToolCoal
{win x y
} {
2852 UIMakeSoundOn
$win edit O
"-speed 75"
2856 proc UIDidToolNuc
{win x y
} {
2857 UIMakeSoundOn
$win edit E
"-speed 75"
2861 proc UIDidToolAirp
{win x y
} {
2862 UIMakeSoundOn
$win edit A
"-speed 50"
2866 proc UISetToolState
{w state
} {
2867 global EditorPallets EditorPalletImages ToolInfo
2868 set win
[WindowLink
$w.top
]
2869 #echo "UISETTOOLSTATE w $w win $win $state"
2870 ExclusivePallet
$state $win $EditorPallets ic
$EditorPalletImages \
2871 raised sunken
{NoFunction
}
2873 set c1
[WindowLink
$w.cost1
]
2875 set info [lindex $ToolInfo $state]
2876 set cost1
[lindex $info 1]
2877 set cost2
[lindex $info 2]
2878 $c1 configure
-text "$cost1"
2879 [WindowLink
$w.cost2
] configure
-text "$cost2"
2884 proc UIShowZoneStatus
{zone density value crime pollution growth x y
} {
2885 global QueryX QueryY
2886 set QueryX
[expr "8 + 16 * $x"]
2887 set QueryY
[expr "8 + 16 * $y"]
2888 UIShowPicture
9 [list $zone $density $value $crime $pollution $growth]
2892 ########################################################################
2893 # Map Window Handlers
2896 proc ShowMapOf
{head
} {
2899 foreach win
$MapWindows {
2900 if {"[WindowLink $win.head]" == "$head"} {
2901 global MapPanelWidth MapPanelHeight
2902 #place configure $win -x 0 -y 0 -width $MapPanelWidth -height $MapPanelHeight
2903 #[WindowLink $win.parent] configure -width $MapPanelWidth -height $MapPanelHeight
2904 set parent
[WindowLink
$win.parent
]
2905 pack append [WindowLink
$head.w2
] \
2906 $win {top
frame nw expand fill
}
2919 proc NewMapOf
{head
} {
2920 set win
[MakeWindow.map
$head [winfo screen
$head]]
2921 global MapPanelWidth MapPanelHeight
2922 #place configure $win -x 0 -y 0 -width $MapPanelWidth -height $MapPanelHeight
2923 #[WindowLink $win.parent] configure -width $MapPanelWidth -height $MapPanelHeight
2924 set parent
[WindowLink
$win.parent
]
2925 #pack append [WindowLink $head.col1]\
2926 # $parent {top frame nw fillx}
2927 pack append [WindowLink
$head.w2
] \
2928 $win {top
frame nw expand fill
}
2935 foreach win
$HeadWindows {
2941 proc WithdrawMaps
{} {
2943 foreach win
$MapWindows {
2952 foreach win
$MapWindows {
2958 proc InitMap
{win
} {
2963 proc EnableMaps
{} {
2965 foreach win
$MapWindows {
2971 proc EnableMap
{win
} {
2972 [WindowLink
$win.view
] ShowEditors
1
2973 [WindowLink
$win.zones
] config
-state normal
2974 [WindowLink
$win.overlays
] config
-state normal
2978 proc DisableMaps
{} {
2980 foreach win
$MapWindows {
2986 proc DisableMap
{win
} {
2987 [WindowLink
$win.view
] ShowEditors
0
2988 [WindowLink
$win.zones
] config
-state disabled
2989 [WindowLink
$win.overlays
] config
-state disabled
2993 proc SetMapState
{win state
} {
2994 set m
[WindowLink
$win.view
]
2996 if {$state == 14} then
{
2997 ShowFrobOf
[WindowLink
$win.head
]
3002 proc MapPanDown
{w x y
} {
3007 proc MapPanDrag
{w x y
} {
3012 proc MapPanUp
{w x y
} {
3019 proc UISetMapState
{w state
} {
3021 #set win [winfo toplevel $w]
3022 set win
[WindowLink
$w.win
]
3023 set m
[WindowLink
$win.view
]
3024 set title
[lindex $MapTitles $state]
3026 # TODO: set map text field header to title
3027 #wm title $win "$title"
3028 #wm iconname $win "$title"
3030 global [set var MapState.
$win]
3034 {6 8 9 10 11 12 13} {
3035 [WindowLink
$win.legend
] config
-bitmap "@images/legendmm.xpm"
3038 [WindowLink
$win.legend
] config
-bitmap "@images/legendpm.xpm"
3041 [WindowLink
$win.legend
] config
-bitmap "@images/legendn.xpm"
3047 ########################################################################
3048 # Graph Window Handlers
3051 proc ToggleGraphOf
{head
} {
3053 if {"$State" != "play"} {
3058 set win
[WindowLink
$head.graph
]
3060 set mapped
[winfo ismapped
$win]
3064 WithdrawGraphOf
$head
3072 proc WithdrawGraphOf
{head
} {
3073 set win
[WindowLink
$head.graph
]
3080 proc ShowGraphOf
{head
} {
3081 set win
[WindowLink
$head.graph
]
3083 set win
[MakeWindow.graph
$head [winfo screen
$head]]
3087 set parent
[WindowLink
$win.parent
]
3088 pack append $parent\
3089 $win {top
frame nw fillx
}
3095 proc WithdrawGraphs
{} {
3097 foreach win
$GraphWindows {
3104 proc InitGraphs
{} {
3106 foreach win
$GraphWindows {
3112 proc InitGraph
{win
} {
3113 UISetGraphState
$win 1 1 1 1 1 1 0
3117 proc UISetGraphState
{win t0 t1 t2 t3 t4 t5 range
} {
3118 set g
[WindowLink
$win.graphview
]
3119 GraphPalletMask
$win [expr "$t0 + ($t1<<1) + ($t2<<2) + ($t3<<3) + ($t4<<4) + ($t5<<5)"]
3120 GraphYearPallet
$win $range
3124 ########################################################################
3125 # Splash Window Handlers
3128 proc ShowSplashOf
{head
} {
3129 set win
[WindowLink
$head.splash
]
3131 set win
[MakeWindow.splash
$head [winfo screen
$head]]
3133 set splashscreen
[WindowLink
$win.splashscreen
]
3135 catch {$splashscreen config
-bitmap "@images/splashscreen.xpm"; set success 1}
3138 global SplashScreenDelay
3139 after $SplashScreenDelay "UIPickScenarioMode"
3146 proc WithdrawSplashOf
{head
} {
3147 set win
[WindowLink
$head.splash
]
3154 proc ShowSplashes
{} {
3156 foreach win
$HeadWindows {
3162 proc WithdrawSplashes
{} {
3163 global SplashWindows
3164 foreach win
$SplashWindows {
3166 set splashscreen
[WindowLink
$win.splashscreen
]
3167 $splashscreen config
-bitmap ""
3172 proc InitSplashes
{} {
3176 proc InitSplash
{win
} {
3180 proc DeleteSplashWindow
{win
} {
3185 ########################################################################
3186 # Scenario Window Handlers
3189 proc ShowScenarioOf
{head
} {
3190 set win
[WindowLink
$head.scenario
]
3192 set win
[MakeWindow.scenario
$head [winfo screen
$head]]
3194 # TODO: load background bitmap
3199 proc WithdrawScenarioOf
{head
} {
3200 set win
[WindowLink
$head.scenario
]
3207 proc ShowScenarios
{} {
3209 foreach win
$HeadWindows {
3215 proc WithdrawScenarios
{} {
3216 global ScenarioWindows
3217 foreach win
$ScenarioWindows {
3219 # TODO: flush background bitmap
3224 proc InitScenarios
{} {
3225 global MapHistory MapHistoryNum
3226 if {$MapHistoryNum < 1} {
3231 if {$MapHistoryNum == ([llength $MapHistory] - 1)} {
3236 global ScenarioWindows
3237 foreach win
$ScenarioWindows {
3239 #[WindowLink $win.previous] config -state $prev
3240 #[WindowLink $win.next] config -state $next
3245 proc InitScenario
{win
} {
3246 global MapHistory MapHistoryNum
3247 if {$MapHistoryNum < 1} {
3253 if {$MapHistoryNum == ([llength $MapHistory] - 1)} {
3260 #[WindowLink $win.previous] config -state $prev
3261 #[WindowLink $win.next] config -state $next
3263 LinkWindow
$win.scenarioTarget
-1
3264 LinkWindow
$win.scenarioTargetDown
-1
3266 global ScenarioButtons
3268 set len
[llength $ScenarioButtons]
3270 set data
[lindex $ScenarioButtons $i]
3271 set type
[lindex $data 0]
3272 set id
[lindex $data 1]
3276 LinkWindow
$win.
$id.over
0
3277 LinkWindow
$win.
$id.enabled
1
3278 LinkWindow
$win.
$id.checked
0
3279 #echo "SETTING WIN $win ID $id"
3281 set i
[expr "$i + 1"]
3284 UpdateLevelSelection
$win
3285 UpdateLeftRightEnabled
$win
3289 proc UpdateLevelSelection
{win
} {
3290 #echo UpdateLevelSelection
3292 if {$GameLevel == 0} then
{
3293 LinkWindow
$win.easy.checked
1
3294 LinkWindow
$win.medium.checked
0
3295 LinkWindow
$win.hard.checked
0
3297 if {$GameLevel == 1} then
{
3298 LinkWindow
$win.easy.checked
0
3299 LinkWindow
$win.medium.checked
1
3300 LinkWindow
$win.hard.checked
0
3302 if {$GameLevel == 2} then
{
3303 LinkWindow
$win.easy.checked
0
3304 LinkWindow
$win.medium.checked
0
3305 LinkWindow
$win.hard.checked
1
3308 UpdateScenarioButtonID
$win easy
3309 UpdateScenarioButtonID
$win medium
3310 UpdateScenarioButtonID
$win hard
3315 proc UpdateLeftRightEnabled
{win
} {
3316 #echo UpdateLeftRightEnabled
3318 global MapHistory MapHistoryNum
3319 if {$MapHistoryNum < 1} {
3320 LinkWindow
$win.left.enabled
0
3322 LinkWindow
$win.left.enabled
1
3325 if {$MapHistoryNum == ([llength $MapHistory] - 1)} {
3326 LinkWindow
$win.right.enabled
0
3328 LinkWindow
$win.right.enabled
1
3331 UpdateScenarioButtonID
$win left
3332 UpdateScenarioButtonID
$win right
3336 proc UpdateScenarioButtonID
{win id
} {
3338 global ScenarioButtons
3340 set len
[llength $ScenarioButtons]
3342 set data
[lindex $ScenarioButtons $i]
3344 if {$id == [lindex $data 1]} then
{
3345 UpdateScenarioButton
$win $data
3349 set i
[expr "$i + 1"]
3354 proc UpdateScenarioButton
{win data
} {
3357 set type
[lindex $data 0]
3358 set id
[lindex $data 1]
3359 set over
[WindowLink
$win.
$id.over
]
3360 set enabled
[WindowLink
$win.
$id.enabled
]
3361 set checked
[WindowLink
$win.
$id.checked
]
3362 #echo "WIN $win TYPE $type ID $id OVER $over ENABLED $enabled CHECKED $checked"
3364 if {[lindex ${data
} 2] == "DoPickScenario"} {
3365 global ScenarioDescX ScenarioDescY ScenarioDescWidth ScenarioDescHeight ScenarioDescFont
3366 catch {text $win.desc
\
3371 -font [Font
$win $ScenarioDescFont]}
3373 $win.desc configure
-state normal
3374 $win.desc delete
0.0 end
3375 $win.desc insert end
"[lindex $Messages([lindex ${data} 3]) 1]\n\n[lindex $Messages([lindex ${data} 3]) 2]"
3376 $win.desc configure
-state disabled
3378 place $win.desc
-x $ScenarioDescX -y $ScenarioDescY -width $ScenarioDescWidth -height $ScenarioDescHeight
3380 if {[lindex ${data
} 2] == "DoMap"} {
3381 global ScenarioMapFloatX ScenarioMapFloatY
3382 if { $ScenarioMapFloatX != "-1" } {
3383 place $win.
canvas.view
-x $ScenarioMapFloatX -y $ScenarioMapFloatY
3387 catch {destroy $win.desc
}
3388 global ScenarioMapFloatX
3389 if { $ScenarioMapFloatX != "-1" } {
3390 catch {place forget
$win.
canvas.view
}
3396 set bm
[lindex $data 13]
3398 set bm
[lindex $data 12]
3402 set bm
[lindex $data 10]
3404 set bm
[lindex $data 9]
3408 set bm
[lindex $data 11]
3411 [WindowLink
$win.
canvas] itemconfig
$id -bitmap $bm
3415 proc DoEnterCityName
{win
} {
3419 proc InitVotesForUseThisMap
{} {
3420 # TODO: Disabled for new scenario window.
3423 global VotesForUseThisMap ScenarioWindows
3424 set VotesForUseThisMap
{}
3425 foreach win
$ScenarioWindows {
3426 [WindowLink
$win.vote
] config
-relief raised
3428 UpdateVotesForUseThisMap
3432 proc UpdateVotesForUseThisMap
{} {
3433 global ScenarioWindows
3434 UpdateVotesFor UseThisMap
$ScenarioWindows
3438 proc UIUseThisMap
{} {
3439 global CityName GameLevel Scenario
3441 # special handling for scenarios?
3442 if {$GameLevel != -1} {
3443 sim GameLevel
$GameLevel
3445 sim CityName
$CityName
3448 if {$Scenario != -1} {
3449 UIShowPicture
$Scenario
3454 proc HandleScenarioDown
{win x y
} {
3455 #echo HandleScenarioDown $win $x $y
3456 HandleScenarioMove
$win $x $y
3457 set w
[WindowLink
$win.w
]
3458 set target
[WindowLink
$w.scenarioTarget
]
3459 LinkWindow
$w.scenarioTargetDown
$target
3463 proc HandleScenarioUp
{win x y
} {
3464 #echo HandleScenarioUp $win $x $y
3465 HandleScenarioMove
$win $x $y
3466 global ScenarioButtons
3467 set w
[WindowLink
$win.w
]
3468 set target
[WindowLink
$w.scenarioTarget
]
3469 set targetDown
[WindowLink
$w.scenarioTargetDown
]
3470 if {($target != -1) &&
3471 ($target == $targetDown)} {
3472 set data
[lindex $ScenarioButtons $target]
3473 set type
[lindex $data 0]
3474 set id
[lindex $data 1]
3475 set callback
[lindex $data 2]
3476 set param
[lindex $data 3]
3477 set var
[lindex $data 4]
3478 set xx
[lindex $data 5]
3479 set yy
[lindex $data 6]
3480 set ww
[lindex $data 7]
3481 set hh
[lindex $data 8]
3482 set normal
[lindex $data 9]
3483 set over
[lindex $data 10]
3484 set disabled
[lindex $data 11]
3485 if {$type == "button"} {
3486 #echo callback $callback w $w param $param
3487 eval "$callback $w {$param}"
3489 if {$type == "checkbox"} {
3490 #echo checkbox callback $callback w $w param $param
3491 eval "$callback $w {$param}"
3498 proc HandleScenarioMove
{win x y
} {
3499 #echo HandleScenarioMove $win $x $y
3500 global ScenarioButtons
3501 set w
[WindowLink
$win.w
]
3502 set target
[WindowLink
$w.scenarioTarget
]
3505 set len
[llength $ScenarioButtons]
3507 set data
[lindex $ScenarioButtons $i]
3508 set type
[lindex $data 0]
3509 set id
[lindex $data 1]
3510 set callback
[lindex $data 2]
3511 set param
[lindex $data 3]
3512 set var
[lindex $data 4]
3513 set xx
[lindex $data 5]
3514 set yy
[lindex $data 6]
3515 set ww
[lindex $data 7]
3516 set hh
[lindex $data 8]
3518 set enabled
[WindowLink
$w.
$id.enabled
]
3519 set checked
[WindowLink
$w.
$id.checked
]
3521 #echo "ID $id ENABLED $enabled CHECKED $checked w $w id $id"
3523 if {($enabled != 0) &&
3525 ($x < ($xx + $ww)) &
3527 ($y < ($yy + $hh))} {
3532 set i
[expr "$i + 1"]
3535 if {$found != $target} {
3538 if {$target != -1} {
3540 #echo OUT $w $found $xx $yy $normal
3541 LinkWindow
$w.scenarioTarget
-1
3543 set targetdata
[lindex $ScenarioButtons $target]
3544 set targetid
[lindex $targetdata 1]
3545 LinkWindow
$w.
$targetid.over
0
3546 UpdateScenarioButton
$w $targetdata
3551 #echo IN $w $found $xx $yy $over
3552 LinkWindow
$w.scenarioTarget
$found
3553 LinkWindow
$w.
$id.over
1
3555 if {$target != -1} {
3556 set targetdata
[lindex $ScenarioButtons $target]
3557 set targetid
[lindex $targetdata 1]
3558 LinkWindow
$w.
$targetid.over
0
3559 UpdateScenarioButton
$w $targetdata
3562 UpdateScenarioButton
$w $data
3568 proc DoLoad
{win param
} {
3569 #echo DOLOAD $win $param
3574 proc DoGenerate
{win param
} {
3575 #echo DOGENERATE $win $param
3580 proc DoQuit
{win param
} {
3581 #echo DOQUIT $win $param
3586 proc DoAbout
{win param
} {
3587 #echo DOABOUT $win $param
3588 MakeHistory
"DoLoadCity cities/about.cty"
3592 proc DoMap
{win param
} {
3593 #echo DOMAP $win $param
3597 proc DoLevel
{win param
} {
3598 #echo DOLEVEL $win $param
3599 DoSetGameLevel
$param
3603 proc DoLeft
{win param
} {
3604 #echo DOLEFT $win $param
3609 proc DoRight
{win param
} {
3610 #echo DORIGHT $win $param
3615 proc DoPlay
{win param
} {
3616 #echo DOPLAY $win $param
3621 proc DoPickScenario
{win param
} {
3622 #echo DOPICKSCENARIO $win $param
3623 UILoadScenario
$param
3626 proc DeleteScenarioWindow
{win
} {
3631 ########################################################################
3632 # Undo/Redo Facility
3635 proc InitHistory
{} {
3637 global MapHistoryNum
3639 set MapHistoryNum
-1
3643 proc MakeHistory
{cmd
} {
3645 set len
[llength $MapHistory]
3647 ($cmd != [lindex $MapHistory [expr $len-1]])} {
3648 lappend MapHistory
$cmd
3656 proc GotoHistory
{i
} {
3658 global MapHistoryNum
3659 InitVotesForUseThisMap
3660 if {$i != $MapHistoryNum} {
3661 set MapHistoryNum
$i
3662 set cmd
[lindex $MapHistory $i]
3665 if {$MapHistoryNum == 0} {
3670 if {$MapHistoryNum == ([llength $MapHistory] - 1)} {
3676 global ScenarioWindows
3677 foreach win
$ScenarioWindows {
3678 UpdateLeftRightEnabled
$win
3684 proc NextHistory
{} {
3686 global MapHistoryNum
3687 set len
[llength $MapHistory]
3688 set i
[expr "$MapHistoryNum + 1"]
3695 proc PrevHistory
{} {
3697 global MapHistoryNum
3698 set i
[expr "$MapHistoryNum - 1"]
3705 ########################################################################
3706 # Ask Window Handlers
3708 proc ShowAskOf
{head
} {
3709 set win
[WindowLink
$head.ask
]
3711 set win
[MakeWindow.ask
$head [winfo screen
$head]]
3721 foreach win
$HeadWindows {
3727 proc WithdrawAsks
{} {
3729 foreach win
$AskWindows {
3735 proc WithdrawAskOf
{win
} {
3736 set ask
[WindowLink
$win.ask
]
3743 proc AskQuestion
{color title
text left middle right
} {
3745 foreach win
$HeadWindows {
3746 AskQuestionOn
$win $color $title $text $left $middle $right
3751 proc AskQuestionOn
{head color title
text left middle right
} {
3754 set win
[WindowLink
$head.ask
]
3755 set t
[WindowLink
$win.title
]
3756 $t configure
-text $title
3757 $t configure
-background $color
3759 set t
[WindowLink
$win.
text]
3760 $t configure
-state normal
3762 $t insert end
"${text}\n"
3763 $t configure
-state disabled
3765 set bf
[WindowLink
$win.
frame]
3766 set l
[WindowLink
$win.left
]
3767 set m
[WindowLink
$win.middle
]
3768 set r
[WindowLink
$win.vote
]
3769 set rf
[WindowLink
$win.voteframe
]
3773 -text [lindex $left 0] \
3774 -command [format [lindex $left 2] $head]
3775 SetHelp
$l [lindex $left 1]
3776 pack append $bf $l {left
frame center
}
3781 if {$middle != ""} {
3783 -text [lindex $middle 0] \
3784 -command [format [lindex $middle 2] $head]
3785 SetHelp
$m [lindex $middle 1]
3786 pack append $bf $m {left
frame center expand
}
3792 set notify
[format [lindex $right 2] $head]
3793 set preview
[format [lindex $right 3] $head]
3794 set cmd
[list DoVote
$win Ask
$notify $preview]
3796 -text [lindex $right 0] \
3798 SetHelp
$r [lindex $right 1]
3799 pack append $bf $rf {right
frame center
}
3808 proc BindVotingButton
{win but name
} {
3809 set w
[WindowLink
$win.top
]
3811 bind $but <Any-Enter
> "VoteButtonEnter $win $but"
3812 bind $but <Any-Leave
> "VoteButtonLeave $win $but"
3813 bind $but <1> "VoteButtonDown $win $but $name"
3814 bind $but <ButtonRelease-1
> "VoteButtonUp $win $but $name"
3815 bind $but <2> "VoteButtonDown $win $but $name"
3816 bind $but <ButtonRelease-2
> "VoteButtonUp $win $but $name"
3817 bind $but <3> "VoteButtonDown $win $but $name"
3818 bind $but <ButtonRelease-3
> "VoteButtonUp $win $but $name"
3822 proc VoteButtonEnter
{win but
} {
3824 set screen
[winfo screen
$but]
3825 if {[lindex [$but config
-state] 4] != "disabled"} {
3826 $but config
-state active
3827 set tk_priv
(window
@$screen) $but
3829 set tk_priv
(window
@$screen) ""
3834 proc VoteButtonLeave
{win but
} {
3836 if {[lindex [$but config
-state] 4] != "disabled"} {
3837 $but config
-state normal
3839 set screen
[winfo screen
$but]
3840 set tk_priv
(window
@$screen) ""
3844 proc VoteButtonDown
{win but name
} {
3846 set screen
[winfo screen
$but]
3847 set rel
[lindex [$but config
-relief] 4]
3848 set tk_priv
(relief
@$screen) $rel
3849 if {[lindex [$but config
-state] 4] != "disabled"} {
3850 set head
[WindowLink
$win.head
]
3851 if {[IsVotingFor
$head $name]} {
3852 $but config
-relief raised
3854 $but config
-relief sunken
3860 proc VoteButtonUp
{win but name
} {
3862 set screen
[winfo screen
$but]
3863 $but config
-relief $tk_priv(relief
@$screen)
3864 if {($but == $tk_priv(window
@$screen))
3865 && ([lindex [$but config
-state] 4] != "disabled")} {
3866 uplevel #0 [list $but invoke]
3867 set head
[WindowLink
$win.head
]
3868 if {[IsVotingFor
$head $name]} {
3869 $but config
-relief sunken
3871 $but config
-relief raised
3877 proc PressVoteButton
{win but name
} {
3879 uplevel #0 [list $but invoke]
3880 set head
[WindowLink
$win.head
]
3881 if {[IsVotingFor
$head $name]} {
3882 $but config
-relief sunken
3884 $but config
-relief raised
3889 proc IsVotingFor
{win name
} {
3890 global VotesFor
$name
3891 set votes
[eval ident
"\$\{VotesFor$name\}"]
3892 if {[lsearch $votes $win] == -1} {
3900 proc DoVote
{win name notify preview
} {
3901 global VotesFor
$name
3902 set votes
[eval ident
"\$\{VotesFor$name\}"]
3904 set win
[WindowLink
$win.head
]
3905 set i
[lsearch $votes $win]
3907 lappend VotesFor
$name $win
3909 set VotesFor
$name [lreplace $votes $i $i]
3912 set votes
[eval ident
"\$\{VotesFor$name\}"]
3913 if {[llength $votes] >= [NeededVotes
]} {
3921 proc UpdateVotesFor
{name wins
} {
3922 global VotesFor
$name
3923 set votes
[eval llength "\$\{VotesFor$name\}"]
3924 set needed
[NeededVotes
]
3927 set head
[WindowLink
$win.head
]
3928 if {[IsVotingFor
$head $name]} {
3929 set border
[expr "($needed - $votes) * 1"]
3930 set pad
[expr "6 - $border"]
3931 [WindowLink
$win.vote
] config
-padx $pad -pady $pad
3932 [WindowLink
$win.voteframe
] config
-borderwidth $border
3934 set border
[expr "($needed - $votes - 1) * 1"]
3935 set pad
[expr "6 - $border"]
3936 [WindowLink
$win.vote
] config
-padx $pad -pady $pad
3937 [WindowLink
$win.voteframe
] config
-borderwidth $border
3943 proc InitVotesForAsk
{} {
3944 global VotesForAsk AskWindows
3946 foreach win
$AskWindows {
3947 [WindowLink
$win.vote
] config
-relief raised
3954 proc UpdateVotesForAsk
{} {
3956 UpdateVotesFor Ask
$AskWindows
3960 ########################################################################
3961 # Player Window Handlers
3963 proc ShowPlayerOf
{head
} {
3964 set win
[WindowLink
$head.player
]
3966 set win
[MakeWindow.player
$head [winfo screen
$head]]
3974 proc ShowPlayers
{} {
3976 foreach win
$HeadWindows {
3982 proc WithdrawPlayers
{} {
3983 global PlayerWindows
3984 foreach win
$PlayerWindows {
3990 proc UpdatePlayers
{} {
3991 # TODO: Disabled for new scenario window.
3994 global HeadWindows PlayerWindows
3997 foreach win
$HeadWindows {
3998 set server
[winfo screen
$win]
3999 # if {[string first : $server] == 0} {
4000 # set server "[exec hostname]:0"
4002 lappend players
$server
4005 sim Players
[llength $players]
4007 foreach win
$PlayerWindows {
4008 set list [WindowLink
$win.players
]
4010 eval "$list insert 0 $players"
4013 UpdateVotesForUseThisMap
4015 UpdateVotesForBudget
4016 UpdateTaxRateSliders
4020 proc UIShowPlayer
{win
} {
4025 proc DoNewPlayer
{win
} {
4026 set field
[WindowLink
$win.display
]
4027 set dpy
[$field get
]
4032 if {[AddPlayer
$dpy] != ""} {
4038 ########################################################################
4039 # Notice Window Handlers
4042 proc ShowNoticeOf
{head
} {
4043 set win
[WindowLink
$head.notice
]
4045 set win
[MakeWindow.notice
$head [winfo screen
$head]]
4047 global NoticePanelWidth NoticePanelHeight
4048 #place configure $win -x 0 -y 0 -width $NoticePanelWidth -height $NoticePanelHeight
4049 pack append [WindowLink
$head.w3
] \
4050 $win {bottom
frame sw expand fill
}
4055 proc ShowNotices
{} {
4057 foreach win
$HeadWindows {
4063 proc WithdrawNotices
{} {
4064 global NoticeWindows
4065 foreach win
$NoticeWindows {
4072 proc ReShowPictureOn
{{head
""}} {
4073 global ShowingPicture ShowingParms
4074 UIShowPictureOn
$head $ShowingPicture $ShowingParms
4078 proc UIShowPicture
{id
{parms
""}} {
4079 UIShowPictureOn
"" $id $parms
4083 proc UIShowPictureOn
{where id
{parms
""}} {
4084 global DoNotices Messages ShowingPicture ShowingParms
4085 if {$DoNotices == 0} {
4089 set ShowingPicture
$id
4090 set ShowingParms
$parms
4091 set msg
$Messages($id)
4092 set color
[lindex $msg 0]
4093 set title
[lindex $msg 1]
4094 set body
[lindex $msg 2]
4096 set cmd
"format {$body} $parms"
4097 set body
[uplevel #0 $cmd]
4099 set props
[lindex $msg 3]
4100 if {"$where" == ""} {
4102 set where
$HeadWindows
4104 foreach head
$where {
4105 NoticeMessageOn
$head "$title" $color "$body" Medium
$props
4110 proc NoticeMessageOn
{head title color
text font props
} {
4112 set win
[WindowLink
$head.notice
]
4114 set t
[WindowLink
$win.title
]
4115 $t configure
-text $title -background $color
4117 set t
[WindowLink
$win.
text]
4118 $t configure
-state normal
-font [Font
$head $font]
4120 $t insert end
"${text}\n"
4121 $t configure
-state disabled
4124 catch {set left
[keylget props left
]}
4125 set l
[WindowLink
$win.left
]
4127 $l config
-bitmap $left
4128 place $l -in $t -anchor sw
-relx .05 -rely .95
4134 catch {set middle
[keylget props middle
]}
4135 set m
[WindowLink
$win.middle
]
4136 if {$middle != ""} {
4137 $m config
-bitmap $middle
4138 place $m -in $t -anchor s
-relx .5 -rely .95
4144 catch {set right
[keylget props right
]}
4145 set r
[WindowLink
$win.right
]
4147 $r config
-bitmap $right
4148 place $r -in $t -anchor se
-relx .95 -rely .95
4154 catch {set view
[keylget props view
]}
4155 set vf
[WindowLink
$win.viewframe
]
4157 set v
[WindowLink
$win.view
]
4158 set bg
[WindowLink
$win.background
]
4162 pack append $bg $vf {left
frame center fill
}
4163 pack append $bg $t {right
frame center fill expand
}
4170 proc UIPopUpMessage
{msg
} {
4175 proc ComeToMe
{view
} {
4176 set win
[winfo toplevel $view]
4179 set x
[expr "[lindex $xy 0] >>4"]
4180 set y
[expr "[lindex $xy 1] >>4"]
4186 proc ComeTo
{win x y
} {
4187 global EditorWindows
4188 set head
[WindowLink
$win.head
]
4191 foreach ed
$EditorWindows {
4192 if {"[WindowLink $ed.head]" == "$head"} {
4194 set view
[WindowLink
$ed.view
]
4195 if {[$view AutoGoto
]} {
4196 lappend myautoeds
$ed
4200 if {[llength $myautoeds]} {
4201 UIAutoGotoOn
$x $y $myautoeds
4203 if {[llength $myeds]} {
4204 UIAutoGotoOn
$x $y $myeds
4210 proc FollowView
{view id
} {
4214 if {[sim DoAnimation
]} {
4215 set head
[WindowLink
[winfo toplevel $view].head
]
4216 global EditorWindows
4217 foreach win
$EditorWindows {
4218 if {"[WindowLink $win.head]" == "$head"} {
4219 set s
[[WindowLink
$win.view
] Skip
]
4220 set skips
[min
$skips $s]
4224 if {$skips == 999999} {
4234 proc PanView
{view x y
} {
4240 ########################################################################
4241 # Help Window Handlers
4244 proc ShowHelpOf
{head
} {
4245 set win
[WindowLink
$head.help
]
4247 set win
[MakeWindow.help
$head [winfo screen
$head]]
4257 foreach win
$HeadWindows {
4263 proc WithdrawHelps
{} {
4265 foreach win
$HelpWindows {
4271 ########################################################################
4272 # Frob Window Handlers
4275 proc ShowFrobOf
{head
} {
4276 set win
[WindowLink
$head.frob
]
4278 set win
[MakeWindow.frob
$head [winfo screen
$head]]
4289 foreach win
$HeadWindows {
4295 proc WithdrawFrobs
{} {
4297 foreach win
$FrobWindows {
4303 proc UISetDynamic
{i min max
} {
4304 sim DynamicData
[expr "$i*2"] $min
4305 sim DynamicData
[expr "$i*2+1"] $max
4309 ########################################################################
4316 source $ResourceDir/help.tcl
4319 proc HandleHelp
{win x y rootx rooty
} {
4320 global HelpLoaded HelpWidgets Messages
4322 if {$HelpLoaded == 0} {
4328 set head
[WindowLink
[winfo toplevel $win].head
]
4331 catch {set id
$HelpWidgets($win)}
4335 set list [split $win .
]
4336 set len
[expr "[llength $list] - 2"]
4337 set list [lrange $list 0 $len]
4338 if {[llength $list] <= 1} {
4342 set win
[join $list .
]
4344 if [info exists Messages
($id)] {
4345 UIShowHelpOn
$head $id
4347 UIShowHelpOn
$head Window
4352 proc UIShowHelpOn
{win id
{parms
""}} {
4353 global Messages ShowingPicture ShowingParms ResourceDir
4354 set head
[WindowLink
$win.head
]
4355 set msg
$Messages($id)
4356 set color
[lindex $msg 0]
4357 set title
[lindex $msg 1]
4358 set body
[lindex $msg 2]
4360 set cmd
"format {$body} $parms"
4361 set body
[uplevel #0 $cmd]
4363 set props
[lindex $msg 3]
4366 set win
[WindowLink
$head.help
]
4368 set t
[WindowLink
$win.title
]
4369 $t configure
-text $title -background $color
4371 set t
[WindowLink
$win.
text]
4372 $t configure
-state normal
-font [Font
$head Large
]
4374 $t insert end
"${body}\n"
4375 FormatHTML
$ResourceDir/doc
/$id.html
$t
4376 $t configure
-state disabled
4380 proc FormatHTML
{filename text} {
4383 set f
[open $filename]
4390 while {[gets $f line
] >= 0} {
4391 if {"$line" == "</body>"} {
4394 if {([string index
$line 0] == "#") ||
([string length
$line] == 0)} {
4397 $text insert end
"$line\n"
4406 proc SetHelp
{win id
} {
4408 set HelpWidgets
($win) $id
4412 proc Help
{id title
{msg
{}} {props
{}}} {
4413 Message
$id #7f7fff $title $msg $props
4416 ########################################################################
4420 # Set up the bindings to pop up $pie when the right button is clicked in $win
4421 proc InitPie
{win pie
} {
4422 bind $win <Motion
> {}
4423 bind $win <3> "PieMenuDown $win $pie $pie Initial %X %Y"
4424 bind $win <B3-Motion
> {}
4425 bind $win <B3-ButtonRelease
> {}
4429 # Set up the bindings to continue tracking $pie
4430 # Get this: we keep the tracking machine state in the bindings!
4431 proc ActivatePie
{win root pie state
} {
4432 bind $win <Motion
> "PieMenuMotion $win $root $pie $state %X %Y"
4433 bind $win <3> "PieMenuDown $win $root $pie $state %X %Y"
4434 bind $win <B3-Motion
> "PieMenuMotion $win $root $pie $state %X %Y"
4435 bind $win <B3-ButtonRelease
> "PieMenuUp $win $root $pie $state %X %Y"
4439 # Cancel and reset a pie menu
4440 proc CancelPie
{win
} {
4441 set binding
[bind $win <3>]
4442 set root
[lindex $binding 2]
4443 set pie
[lindex $binding 3]
4444 set state
[lindex $binding 4]
4445 if {"$state" != "Initial"} {
4446 catch {$root ungrab
$win}
4449 UIMakeSoundOn
$win fancy Oop
4455 # Handle pie menu button down
4456 proc PieMenuDown
{win root pie state x y
} {
4459 ActivatePie
$win $root $pie FirstDown
4461 catch {$root grab $win}
4464 PreviewPieMenu
$win $pie $x $y
4468 TrackPieMenu
$pie $x $y
4469 ActivatePie
$win $root $pie SecondDown
4475 PreviewPieMenu
$win $pie $x $y
4476 ActivatePie
$win $root $pie SecondDown
4481 SecondDown
{ # error
4488 # Handle pie menu button motion
4489 proc PieMenuMotion
{win root pie state x y
} {
4492 TrackPieMenu
$pie $x $y
4500 TrackPieMenu
$pie $x $y
4514 # Handle pie menu button up
4515 proc PieMenuUp
{win root pie state x y
} {
4518 TrackPieMenu
$pie $x $y
4519 set active
[$pie index active
]
4520 if {$active == "none"} {
4522 catch {$root grab $win}
4523 ActivatePie
$win $root $pie ClickedUp
4525 set label [lindex [$pie entryconfig
$active -label] 4]
4526 set submenu
[lindex [$pie entryconfig
$active -piemenu] 4]
4527 UIMakeSoundOn
$win mode
$label
4528 if {$submenu == {}} {
4529 set reward
[$pie pending
]
4530 catch {$root ungrab
$win}
4534 sim Funds
[expr "[sim Funds] + 5"]
4535 UIMakeSoundOn
$win fancy Aaah
4537 eval [lindex [$pie entryconfig
$active -command] 4]
4542 $submenu activate none
4544 PreviewPieMenu
$win $submenu $x $y
4545 catch {$root grab $win}
4546 ActivatePie
$win $root $submenu SelectedUp
4551 TrackPieMenu
$pie $x $y
4552 set active
[$pie index active
]
4553 if {$active == "none"} {
4556 set label [lindex [$pie entryconfig
$active -label] 4]
4557 set submenu
[lindex [$pie entryconfig
$active -piemenu] 4]
4558 UIMakeSoundOn
$win mode
$label
4559 if {$submenu == {}} {
4560 set reward
[$pie pending
]
4561 catch {$root ungrab
$win}
4565 sim Funds
[expr "[sim Funds] + 5"]
4566 UIMakeSoundOn
$win fancy Aaah
4568 eval [lindex [$pie entryconfig
$active -command] 4]
4573 $submenu activate none
4575 PreviewPieMenu
$win $submenu $x $y
4576 catch {$root grab $win}
4577 ActivatePie
$win $root $submenu SelectedUp
4587 SelectedUp
{ # error
4594 # Track the selected item
4595 proc TrackPieMenu
{pie x y
} {
4596 $pie activate
@$x,$y
4600 proc PreviewPieMenu
{win pie x y
} {
4601 set preview
[lindex [$pie config
-preview] 4]
4602 if {"$preview" != ""} {
4603 set rx
[winfo rootx
$win]
4604 set ry
[winfo rooty
$win]
4605 set x
[expr "$x - $rx"]
4606 set y
[expr "$y - $ry"]
4607 eval [format $preview $x $y]
4612 ########################################################################
4616 proc ExclusivePallet
{state parent children prefix images inactive active cmd
} {
4617 #echo "ExclusivePallet state $state parent $parent children $children prefix $prefix images $images inactive $inactive active $active cmd $cmd"
4619 foreach child
$children {
4620 set name
[lindex $images $i]
4621 if {$i == $state} then
{
4622 $parent.
$child config
\
4623 -bitmap "@images/${prefix}${name}hi.xpm" \
4626 $parent.
$child config
\
4627 -bitmap "@images/${prefix}${name}.xpm" \
4632 eval [concat $cmd $state]
4636 proc NonExclusivePallet
{mask parent children prefix images
4637 inactive active cmd
} {
4639 foreach child
$children {
4640 set name
[lindex $images $i]
4641 if {$mask & (1<<$i)} then
{
4642 $parent.
$child config
\
4643 -bitmap "@images/${prefix}${name}hi.xpm" \
4646 $parent.
$child config
\
4647 -bitmap "@images/${prefix}${name}.xpm" \
4652 eval [concat $cmd $mask]
4656 proc EditorPallet
{win state
} {
4657 global EditorPalletSounds
4658 UIMakeSoundOn
$win mode
[lindex $EditorPalletSounds $state]
4659 EditorSetTool
$win $state
4663 proc EditorSetTool
{win state
} {
4664 global EditorPallets
4665 global EditorPalletImages
4666 ExclusivePallet
$state $win $EditorPallets ic
$EditorPalletImages \
4667 flat raised
"$win.centerframe.view ToolState"
4671 proc GraphPallet
{win state
} {
4672 set mask
[[WindowLink
$win.graphview
] Mask
]
4673 set mask
[expr "$mask ^ (1<<$state)"]
4674 GraphPalletMask
$win $mask
4678 proc GraphPalletMask
{win mask
} {
4680 global GraphPalletImages
4681 NonExclusivePallet
$mask $win $GraphPallets gr
$GraphPalletImages \
4682 flat flat
"SetGraphState $win"
4686 proc GraphYearPallet
{win state
} {
4687 global GraphYearPallets
4688 global GraphYearPalletImages
4689 ExclusivePallet
$state $win $GraphYearPallets gr
$GraphYearPalletImages \
4690 flat flat
"SetGraphYearState $win"
4694 proc SetGraphYearState
{win state
} {
4695 set graph
[WindowLink
$win.graphview
]
4704 proc SetGraphState
{win mask
} {
4706 set graph
[WindowLink
$win.graphview
]
4711 ########################################################################
4714 proc sim_butEnter
{w
} {
4716 set screen
[winfo screen
$w]
4717 set tk_priv
(window
@$screen) $w
4721 proc sim_butLeave
{w
} {
4723 set screen
[winfo screen
$w]
4724 set tk_priv
(window
@$screen) ""
4728 proc sim_butDown
{w
} {
4730 set screen
[winfo screen
$w]
4731 set pict
[lindex [$w config
-bitmap] 4]
4732 set tk_priv
(relief
@$screen) $pict
4733 $w config
-bitmap [lindex [split $pict .
] 0]hi.xpm
4738 proc sim_butUp
{w
} {
4740 set screen
[winfo screen
$w]
4741 $w config
-bitmap $tk_priv(relief
@$screen)
4743 if {$w == $tk_priv(window
@$screen)} {
4744 uplevel #0 [list $w invoke]
4749 proc BindSimButton
{w
} {
4750 bind $w <Any-Enter
> {sim_butEnter
%W
}
4751 bind $w <Any-Leave
> {sim_butLeave
%W
}
4752 bind $w <1> {sim_butDown
%W
}
4753 bind $w <ButtonRelease-1
> {sim_butUp
%W
}
4754 bind $w <2> {sim_butDown
%W
}
4755 bind $w <ButtonRelease-2
> {sim_butUp
%W
}
4756 bind $w <3> {sim_butDown
%W
}
4757 bind $w <ButtonRelease-3
> {sim_butUp
%W
}
4761 ########################################################################
4762 # Internal Callbacks
4765 proc UIStartMicropolis
{homedir resourcedir hostname
} {
4766 global HomeDir ResourceDir HostName HeadWindows
4767 set HomeDir
$homedir
4768 set ResourceDir
$resourcedir
4769 set HostName
$hostname
4774 foreach display
[sim Displays
] {
4775 if {"[AddPlayer $display]" == ""} {
4776 echo Couldn't add a player on
$display ...
4780 if {"$HeadWindows" == ""} {
4781 echo Micropolis is exiting because it couldn't connect to any players.
4787 proc UISelectCity
{win
} {
4788 AskQuestion
[Color
$win #ff0000 #ffffff] "Choose Another City" \
4789 "Do you want to abandon this city and choose another one?" \
4790 "{Keep playing.} SelectCity.No {RejectPlan}" \
4792 "{Another city!} SelectCity.Yes {UIPickScenarioMode}"
4796 proc UIQuit
{head
} {
4797 if {[sim Players
] == 1} {
4798 set l
"{Keep playing.} Quit.No {RejectPlan}"
4800 set r
"{I quit!} Quit.IQuit {DoReallyQuit %s}"
4802 set l
"{Keep playing.} Quit.No {RejectPlan}"
4803 set m
"{I quit!} Quit.IResign {DoIResign %s}"
4804 set r
"{Everyone quit!} Quit.AllQuit {DoReallyQuit %s}"
4806 AskQuestion
[Color
$head #ff0000 #ffffff] "Quit Playing Micropolis" \
4807 "Do you want to quit playing Micropolis?" \
4812 proc DoIResign
{head
} {
4814 set display
[winfo screen
$head]
4816 DecRefDisplay
$display
4817 UISetMessage
"The player on X11 Display $display has resigned."
4819 if {([sim Players
] == 0) ||
4820 ([llength $VotesForAsk] >= [sim Players
])} {
4826 proc DoReallyQuit
{head
} {
4832 proc UISplashMode
{} {
4842 proc UIPickScenarioMode
{} {
4851 InitVotesForUseThisMap
4856 proc ForcePickScenarioMode
{} {
4858 if {"$State" != "scenario"} {
4864 proc UIGenerateCityNow
{} {
4865 global CityName GameLevel
4866 sim CityName NowHere
4872 proc UIGenerateNewCity
{} {
4873 global CityName GameLevel
4874 if {$GameLevel == -1} {
4877 MakeHistory
"DoNewCity NowHere $GameLevel [sim Rand] [sim TreeLevel] [sim LakeLevel] [sim CurveLevel] [sim CreateIsland]"
4881 proc DoNewCity
{name level
{r
""} {tl
-1} {ll
-1} {cl
-1} {ci
-1}} {
4887 sim CreateIsland
$ci
4891 sim GenerateSomeCity
$r
4894 sim GameLevel
$level
4899 proc UIDidGenerateNewCity
{} {
4904 proc IncRefDisplay
{display
} {
4905 global DisplayRegistry
4906 if ![info exists DisplayRegistry
($display)] {
4907 set DisplayRegistry
($display) 0
4909 incr DisplayRegistry
($display)
4913 proc DecRefDisplay
{display
} {
4914 global DisplayRegistry
4915 incr DisplayRegistry
($display) -1
4916 if {$DisplayRegistry($display) <= 0} {
4917 CloseDisplay
$display
4922 proc CloseDisplay
{display
} {
4926 proc DoStopMicropolis
{} {
4932 proc AddPlayer
{display
} {
4933 set i
[string first
: $display]
4937 set display
"$display:0"
4941 echo Adding a player on
$display ...
4943 set head
[MakeWindow.head
$display]
4945 if {"$head" != ""} {
4946 set display
[winfo screen
$head]
4947 IncRefDisplay
$display
4949 UISetMessage
"Added a player on X11 Display \"$display\"."
4952 UISetMessage
"Couldn't add a player on X11 Display \"$display\"!"
4962 proc DropFireBombs
{} {
4970 proc UIMakeMonster
{} {
4971 sim MakeMonster
[sim Rand
120] [sim Rand
100]
4994 proc TogglePause
{} {
4997 if {"$State" != "play" ||
[sim Speed
]} {
5008 proc SetSpeedTime
{time} {
5014 proc MakeRunningSound
{} {
5017 if {"$State" == "play" && [sim Speed
]} {
5018 UIMakeSound edit Boing
"-speed 1[sim Speed]0"
5020 UIMakeSound edit Boing
"-speed 90"
5025 proc SayDemands
{} {
5026 global DemandRes DemandCom DemandInd
5028 set r
[expr "100 + ($DemandRes * $slope)"]
5029 set c
[expr "100 + ($DemandCom * $slope)"]
5030 set i
[expr "100 + ($DemandInd * $slope)"]
5031 after 020 "UIMakeSound edit O \"-speed $r\""
5032 after 220 "UIMakeSound edit A \"-speed $c\""
5033 after 440 "UIMakeSound edit E \"-speed $i\""
5037 proc UISaveCity
{win
} {
5039 set SaveCityWin
$win
5044 proc UISaveCityAs
{{win
""}} {
5046 if {"$win" == ""} {set win
$SaveCityWin}
5047 set SaveCityWin
$win
5050 set file [ShowFileOf
$win]
5051 DoFileDialog
$file "Choose a File to Save the City" $CityDir "*.cty" "" \
5052 "UIDoReallySaveCity" ""
5056 proc UIDoReallySaveCity
{name path
} {
5058 if {![string match
*.cty
$name]} {
5062 sim SaveCityAs
$path/$name
5066 proc UIDidSaveCity
{} {
5067 DoSendMessage
"Saved the city in \"[sim CityFileName]\"." status
5071 proc UIDidntSaveCity
{msg
} {
5072 DoSendMessage
$msg alert
5073 UIMakeSound warning Sorry
"-speed 85"
5077 proc UILoadScenario
{scen
} {
5078 MakeHistory
"DoScenario $scen"
5082 proc DoScenario
{scen
} {
5085 sim LoadScenario
$scen
5090 proc UIDidLoadScenario
{} {
5094 proc UIStartScenario
{id
} {
5103 proc UIPlayNewCity
{} {
5109 proc UIStartLoad
{} {
5114 proc UIReallyStartGame
{} {
5120 proc UIPlayGame
{} {
5127 SetPriority
$Priority
5135 proc UISetSpeed
{speed
} {
5138 if {"$State" == "play"} {
5139 UISetMessage
[lindex {
5142 {Time flows medium.
}
5150 proc UIUpdateRunning
{} {
5151 global HeadWindows Time State
5153 if {($State == "play") && $Time} {
5154 set pict
"@images/micropolisg.xpm"
5156 set pict
"@images/micropoliss.xpm"
5159 foreach win
$HeadWindows {
5160 set can
[WindowLink
$win.demand
]
5161 $can itemconfig micropolis
-bitmap $pict
5166 proc DoSetGameLevel
{level
} {
5167 sim GameLevel
$level
5171 proc UISetGameLevel
{level
} {
5173 set GameLevel
$level
5174 global ScenarioWindows
5175 foreach win
$ScenarioWindows {
5176 UpdateLevelSelection
$win
5181 proc UISetCityName
{name
} {
5182 global EditorWindows
5185 set title
"Micropolis Editor on $name"
5186 foreach win
$EditorWindows {
5187 # TODO: set editor window and icon title
5188 #wm title $win "$title"
5189 #wm iconname $win "$title"
5194 proc UILoadCity
{win
} {
5195 # if changed, r-u-sure?
5197 set file [ShowFileOf
$win]
5198 DoFileDialog
$file "Choose a City to Load" $CityDir "*.cty" "" \
5203 proc UIDoLoadCity
{name path
} {
5206 if {![string match
*.cty
$name]} {
5209 MakeHistory
"DoLoadCity {$path/$name}"
5213 proc DoLoadCity
{filename} {
5214 sim LoadCity
$filename
5217 proc UIDidLoadCity
{} {
5218 global State GameLevel Scenario
5221 if {$State == "play"} {
5224 UIShowPicture
49 [sim CityFileName
]
5229 proc UIDidntLoadCity
{msg
} {
5230 DoSendMessage
$msg alert
5231 UIMakeSound warning Sorry
"-speed 85"
5232 UIShowPicture
49 [sim CityFileName
]
5251 proc UIDidPan
{w x y
} {
5252 if {[$w ToolMode
] == 1} {
5253 EditorToolDrag
$w $x $y
5259 proc UIDidStopPan
{win
} {
5260 UIMakeSoundOn
$win fancy Skid
"-volume 25"
5265 proc UIEarthQuake
{} {
5269 proc UIAutoGoto
{x y
{except
{}}} {
5270 global EditorWindows
5272 set x
[expr "$x * 16 + 8"]
5273 set y
[expr "$y * 16 + 8"]
5274 foreach win
$EditorWindows {
5275 if {"$win" != "$except"} {
5276 set view
[WindowLink
$win.view
]
5277 if {[$view AutoGoto
]} {
5279 $view AutoGoal
$x $y
5289 proc UIAutoGotoOn
{x y eds
} {
5290 set x
[expr "$x * 16 + 8"]
5291 set y
[expr "$y * 16 + 8"]
5293 [WindowLink
$win.view
] AutoGoal
$x $y
5299 proc DoLeaveGame
{head
} {
5303 proc UILoseGame
{} {
5307 AskQuestion
[Color .
#ff0000 #ffffff] [lindex $Messages(200) 1] \
5308 [lindex $Messages(200) 2] \
5311 "{Ok} SelectCity.Yes {UIPickScenarioMode}"
5320 proc DoPendTool
{view tool x y
} {
5321 global HeadWindows ToolInfo VotesForAsk
5323 set win
[WindowLink
$view.top
]
5324 set head
[WindowLink
$win.head
]
5326 if {($tool == [sim PendingTool
]) &&
5327 ($x == [sim PendingX
]) &&
5328 ($y == [sim PendingY
])} {
5329 if {[lsearch $VotesForAsk $head] != -1} {
5330 # you can only vote once
5331 UIMakeSound edit Oop
5333 UIMakeSound edit Boing
5334 set ask
[WindowLink
$head.ask
]
5335 PressVoteButton
$ask [WindowLink
$ask.vote
] Ask
5338 UIAutoGoto
$x $y $win
5340 UIMakeSound edit Boing
5341 set info [lindex $ToolInfo $tool]
5342 set a
[lindex $info 0]
5343 set name
[lindex $info 1]
5344 set cost
[lindex $info 2]
5345 set title
"Build $a $name"
5346 set question
"Do you support the plan to build $a $name for $cost?"
5347 AskQuestion
[Color
$win #00ff00 #ffffff] "$title" \
5349 "{Veto plan.} Plan.Veto
5351 "{Goto plan.} Plan.Goto
5352 {ComeTo %s $x $y}" \
5353 "{Support plan!} Plan.Support
5354 {SupportPlan $view %s $tool $x $y}
5355 {PreviewSupportPlan $view %s $tool $x $y}"
5356 set VotesForAsk
$head
5357 set ask
[WindowLink
$head.ask
]
5358 [WindowLink
$ask.vote
] config
-relief sunken
5362 sim PendingTool
$tool
5365 sim Votes
[llength $VotesForAsk]
5370 proc RejectPlan
{} {
5372 if {[sim Players
] > 1} {
5373 UIMakeSound edit Sorry
5379 proc NeededVotes
{} {
5381 set players
[sim Players
]
5382 set needed
[expr "$players - $FreeVotes"]
5383 return [max
0 $needed]
5387 proc SupportPlan
{view h tool x y
} {
5389 sim Votes
[llength $VotesForAsk]
5392 $view DoTool
$tool $x $y
5395 UIMakeSound edit Aaah
5399 proc PreviewSupportPlan
{view h tool x y
} {
5401 sim Votes
[llength $VotesForAsk]
5405 proc SugarStartUp
{uri
} {
5409 # TODO: Load the city file at the given URI, or configure according to URI parameters.
5413 proc SugarNickName
{nick
} {
5414 global SugarNickName
5415 set SugarNickName
$nick
5419 proc SugarActivate
{} {
5420 global SugarActivated
5421 set SugarActivated
1
5425 proc SugarDeactivate
{} {
5426 global SugarActivated
5427 set SugarActivated
0
5431 proc SugarShare
{} {
5437 proc SugarBuddyAdd
{key nick color address
} {
5439 set buddy
[list $key $nick $color $address]
5440 lappend SugarBuddies
$buddy
5444 proc SugarBuddyDel
{key nick color address
} {
5446 set buddy
[list $key $nick $color $address]
5447 set i
[lsearch $wins $win]
5449 set SugarBuddies
[lreplace $wins $i $i]
5459 ########################################################################