Guest User

Untitled

a guest
Sep 10th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 33.23 KB | None | 0 0
  1. # This program is free software; you can redistribute it and/or
  2. # modify it under the terms of the GNU General Public License
  3. # as published by the Free Software Foundation; either version 2
  4. # of the License, or (at your option) any later version. The original
  5. # author also sells licenses for use in proprietary software under
  6. # a different license. Contact information for the author can be
  7. # found in the Copyright text file included with this package.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software Foundation,
  16. # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. #
  18. # The Original Code is Copyright (C) 2006 by Roland Hess.
  19. # All rights reserved.
  20. #
  21. # The Original Code is: all of this file.
  22.  
  23. #!BPY
  24.  
  25. # """
  26. # Name: 'BlenderPeople.0.8'
  27. # Blender: 242
  28. # Group: 'Animation'
  29. # Tooltip: 'Crowd Simulation'
  30. # """
  31.  
  32. ####################################################################
  33. ##
  34. ## BlenderPeople 0.8
  35. ##
  36. ####################################################################
  37.  
  38. ## Press alt-p to run
  39.  
  40. from Blender import *
  41. import Blender
  42. import MySQLdb
  43. import CheckDB,Initialization,BuildTree,Main,AutoInitCnC,ManualCnC,ChangeOrders,ActorQueries,Effectors,Locomotion,BuildNLA,Replacement
  44. reload(Main)
  45.  
  46. host = Draw.Create('127.0.0.1')
  47. password = Draw.Create('')
  48. user = Draw.Create('root')
  49. message = Draw.Create('')
  50.  
  51. msgWindow01 = Draw.Create("> Connected to Database")
  52. msgWindow02 = Draw.Create(">")
  53. msgWindow03 = Draw.Create(">")
  54. msgWindow04 = Draw.Create("> Blender People 0.8")
  55. msgWindow05 = Draw.Create("> (c) Roland Hess 2006")
  56. Blender.resolution = 12
  57.  
  58. orderlist=['Attack','Directed','StrictDefend','Defend','StrictMarch','March','StrictMill','Mill','Target','Rank','RegroupMain','RegroupCommander','Retreat']
  59. teamlist=['a','b']
  60. orders = Draw.Create(0)
  61. number = Draw.Create(1)
  62. toggle = Draw.Create(0)
  63. team = Draw.Create(0)
  64. target = Draw.Create("")
  65. general = Draw.Create(1)
  66. obstacle = Draw.Create(1)
  67. information = Draw.Create(0)
  68. simtools = Draw.Create(0)
  69.  
  70. # character stat variables
  71. globalID = 0
  72. dbID = Draw.Create(0)
  73. dbType = Draw.Create('Type')
  74. dbTeam = Draw.Create('Team')
  75. dbObjectName = Draw.Create('Name')
  76. dbOrderSpeed = Draw.Create(1.0)
  77. dbOrders = Draw.Create(0)
  78. dbOrderParam = Draw.Create('')
  79. dbCommanderID = Draw.Create(0)
  80. dbSpeed = Draw.Create(0.0)
  81. dbAttack = Draw.Create(0.0)
  82. dbDefense = Draw.Create(0.0)
  83. dbIntellect = Draw.Create(0.0)
  84. dbHealth = Draw.Create(0.0)
  85. dbFieldofView = Draw.Create(0.0)
  86. dbMaxTurn = Draw.Create(0.0)
  87. dbWeapon = Draw.Create('Weapon')
  88. dbAttackRadius = Draw.Create(0.0)
  89. dbChargeRadius = Draw.Create(0.0)
  90. dbCowardRadius = Draw.Create(0.0)
  91. dbBuddyRadius = Draw.Create(0.0)
  92. dbLoyalty = Draw.Create(0.0)
  93. dbActorRadius = Draw.Create(0.0)
  94. defaultpathmode = 'terrain'
  95. pathmodes={'terrain':1,'astar':2,'none':3}
  96. reversepathmodes={1:'terrain',2:'astar',3:'none'}
  97.  
  98. # character type variables
  99. originalType = ""
  100. TypeMenuList = []
  101. TypeMenu = Draw.Create(0)
  102. tpTypeID = Draw.Create('a')
  103. tpTypeName = Draw.Create('Name')
  104. tpSpeed = Draw.Create(0.0)
  105. tpSpeedV = Draw.Create(0.0)
  106. tpAttackRadius = Draw.Create(0.0)
  107. tpAttackRadiusV = Draw.Create(0.0)
  108. tpChargeRadius = Draw.Create(0.0)
  109. tpChargeRadiusV = Draw.Create(0.0)
  110. tpCowardRadius = Draw.Create(0.0)
  111. tpCowardRadiusV = Draw.Create(0.0)
  112. tpBuddyRadius = Draw.Create(0.0)
  113. tpBuddyRadiusV = Draw.Create(0.0)
  114. tpHealth = Draw.Create(0.0)
  115. tpHealthV = Draw.Create(0.0)
  116. tpAttack = Draw.Create(0.0)
  117. tpAttackV = Draw.Create(0.0)
  118. tpDefense = Draw.Create(0.0)
  119. tpDefenseV = Draw.Create(0.0)
  120. tpIntellect = Draw.Create(0.0)
  121. tpIntellectV = Draw.Create(0.0)
  122. tpFieldofView = Draw.Create(0.0)
  123. tpFieldofViewV = Draw.Create(0.0)
  124. tpMaxTurn = Draw.Create(0.0)
  125. tpMaxTurnV = Draw.Create(0.0)
  126. tpActorRadius = Draw.Create(0.0)
  127.  
  128. #simulation tools
  129. AffectsList = ['All','Team','Type']
  130. AttributeList = ['Health','Speed','Attack','Defense','Intellect','CommanderID','FieldofView','MaxTurn','AttackRadius','ChargeRadius','CowardRadius','BuddyRadius']
  131. OperatorList = ['=','*','/','+','-']
  132. DurationList = ['Permanent','Temporary']
  133. EffectorName = 'None'
  134. efAffects = Draw.Create(1)
  135. efAffectsValue = Draw.Create('')
  136. efAttributeMenu = Draw.Create(1)
  137. efOperatorMenu = Draw.Create(1)
  138. efValue = Draw.Create(0.0)
  139. efAction = Draw.Create('None')
  140. efActive = Draw.Create(1)
  141. efDuration = Draw.Create(1)
  142.  
  143. def main():
  144. CheckDB.CheckDB()
  145.  
  146. #register the MySQLdb cursor in the Blender object for other scripts to use
  147. Blender.barriers = 1
  148.  
  149. Blender.globalGround = {}
  150.  
  151. BuildTree.loadTree()
  152.  
  153. print()
  154. print('Connection to DB Successfully established')
  155.  
  156. Draw.Register(drawGUI, event, buttonEvents) # refresh all windows
  157.  
  158. def drawMySQL():
  159. global testbutton, host, password, user, message
  160.  
  161. BGL.glClearColor(0.753, 0.753, 0.753, 0.0)
  162. BGL.glClear(BGL.GL_COLOR_BUFFER_BIT)
  163.  
  164.  
  165. BGL.glColor3f(0.000, 0.000, 0.000)
  166. BGL.glRasterPos2i(24, 252)
  167. Draw.Text('Password:')
  168. BGL.glRasterPos2i(24, 276)
  169. Draw.Text('User:')
  170. BGL.glRasterPos2i(24, 300)
  171. Draw.Text('Host:')
  172. BGL.glRasterPos2i(24, 380)
  173. Draw.Text('Enter your configuration here for your')
  174. BGL.glRasterPos2i(24, 360)
  175. Draw.Text("MySQL setup. If you've done the default")
  176. BGL.glRasterPos2i(24, 340)
  177. Draw.Text('install of MySQL, you should only need')
  178. BGL.glRasterPos2i(24, 320)
  179. Draw.Text('to enter the correct password.')
  180. BGL.glRasterPos2i(24, 428)
  181. Draw.Text('BlenderPeople MySQL Configuration')
  182.  
  183. Draw.Button('Test Connection', 1, 24, 208, 120, 23, '')
  184. Draw.Button('Quit',6,150,208,80,23, '')
  185.  
  186. host = Draw.String('', 2, 88, 290, 151, 23, host.val, 200, '')
  187. password = Draw.String('', 3, 88, 242, 151, 23, password.val, 200, '')
  188. user = Draw.String('', 4, 88, 266, 151, 23, user.val, 200, '')
  189. message = Draw.String('', 5, 56, 160, 151, 23, message.val, 200, '')
  190.  
  191. def MySQLevent(evt, val):
  192. if (evt== Draw.QKEY or evt== Draw.ESCKEY and not val): Draw.Exit()
  193. def MySQLbevent(evt):
  194. if evt==1:
  195. try:
  196. dbConn = MySQLdb.connect(host.val, user.val, password.val)
  197. except:
  198. message.val='Connection failed.'
  199. else: #connection successful
  200. newtxt=Blender.Text.New("MySQLInfo")
  201. newtxt.write(host.val+"\n"+user.val+"\n"+password.val+"\n")
  202. message.val = 'Connection Succeeded!'
  203. main()
  204. Blender.Redraw()
  205. elif evt==6:
  206. Draw.Exit()
  207.  
  208. def drawGUI():
  209.  
  210. global number, toggle, orders, team, target, general, information, simtools
  211. global msgWindow01,msgWindow02,msgWindow03,msgWindow04,msgWindow05,pathmodes
  212. global dbID,dbType,dbTeam,dbObjectName,dbCommanderID,dbOrderSpeed,dbSpeed,dbAttack,dbActorRadius,dbOrderParam
  213. global dbDefense,dbIntellect,dbHealth,dbFieldofView,dbMaxTurn,dbPathmode,dbOrders,defaultpathmode
  214. global dbAttackRadius,dbChargeRadius,dbCowardRadius,dbBuddyRadius,dbLoyalty,globalID
  215. global tpTypeID,tpTypeName,tpSpeed,tpSpeedV,tpAttackRadius,tpAttackRadiusV,tpChargeRadius
  216. global tpChargeRadiusV,tpCowardRadius,tpCowardRadiusV,tpBuddyRadius,tpBuddyRadiusV,originalType
  217. global tpHealth,tpHealthV,tpAttack,tpAttackV,tpDefense,tpDefenseV,tpIntellect,tpIntellectV
  218. global tpFieldofView,tpFieldofViewV,tpMaxTurn,tpMaxTurnV,tpActorRadius,TypeMenuList,TypeMenu,EffectorName,efDuration,DurationList
  219. global AffectsList,AttributeList,OperatorList,efAffects,efAffectsValue,efAttributeMenu,efOperatorMenu,efValue,efAction,efActive
  220.  
  221. BGL.glClearColor(0.5, 0.5, 0.5, 0.0)
  222. BGL.glClear(BGL.GL_COLOR_BUFFER_BIT)
  223.  
  224. Draw.Button("Exit", 10, 12, 12, 56, 18)
  225. #Draw.Toggle("Obstacles", 30, 270, 12, 70, 18, obstacle.val, 'Turn vert paint obstacles on and off')
  226.  
  227. #Info Window
  228.  
  229. msgWindow05 = Draw.String("", 81, 4, 478, 361, 18, msgWindow05.val, 45)
  230. msgWindow04 = Draw.String("", 81, 4, 496, 361, 18, msgWindow04.val, 45)
  231. msgWindow03 = Draw.String("", 81, 4, 514, 361, 18, msgWindow03.val, 45)
  232. msgWindow02 = Draw.String("", 81, 4, 532, 361, 18, msgWindow02.val, 45)
  233. msgWindow01 = Draw.String("", 81, 4, 550, 361, 18, msgWindow01.val, 45)
  234.  
  235. general = Draw.Toggle('General', 99, 4, 450, 110, 18, general.val, 'Setup, orders and simulation.')
  236. information = Draw.Toggle('Information', 98, 124, 450, 110, 18, information.val, 'Info about actors.')
  237. simtools = Draw.Toggle('Sim. Tools', 97, 244, 450, 110, 18, simtools.val, 'Simulation Tools - Effectors.')
  238.  
  239. if general.val == 1:
  240. #Setup widgets
  241.  
  242. BGL.glColor3ub(219, 134, 134)
  243. BGL.glRectf(4, 320, 365, 430)
  244.  
  245. BGL.glColor3ub(0, 0, 0)
  246. BGL.glRasterPos2d(12, 410)
  247. Draw.Text("Setup")
  248. BGL.glRasterPos2d(140, 385)
  249. Draw.Text("Clear database and create actors")
  250. BGL.glRasterPos2d(140, 360)
  251. Draw.Text("Create search tree for ground")
  252. BGL.glRasterPos2d(140, 335)
  253. Draw.Text("Reset Actor health and location")
  254.  
  255. Draw.Button("Initialize Actors", 2, 12, 380, 120, 20)
  256. Draw.Button("Initialize Ground", 3, 12, 355, 120, 20)
  257. Draw.Button("Reset Actors", 16, 12, 330, 120, 20)
  258.  
  259. #Command and Control widgets
  260.  
  261. BGL.glColor3ub(254, 255, 184)
  262. BGL.glRectf(4, 225, 365, 310)
  263.  
  264. BGL.glColor3ub(0, 0, 0)
  265. BGL.glRasterPos2d(12, 290)
  266. Draw.Text("Command and Control")
  267. BGL.glRasterPos2d(140, 265)
  268. Draw.Text("Do CnC by proximity and name")
  269. BGL.glRasterPos2d(140, 240)
  270. Draw.Text("Assign selected Actors to active object")
  271.  
  272. Draw.Button("Automatic CnC", 5, 12, 260, 120, 20)
  273. Draw.Button("Manual CnC", 6, 12, 235, 120, 20)
  274.  
  275. #Orders widgets
  276.  
  277. BGL.glColor3ub(220,220,255)
  278. BGL.glRectf(4, 145, 365, 215)
  279.  
  280. BGL.glColor3ub(0, 0, 0)
  281. BGL.glRasterPos2d(12, 185)
  282. Draw.Text("Change Orders")
  283. orderkinds = 'Orders %t'
  284. for order in orderlist:
  285. orderkinds += '|' + order
  286. orders = Draw.Menu(orderkinds, 90, 70, 155, 150, 20, 1)
  287. team = Draw.Menu('Teams %t|a|b', 92, 12, 155, 50, 20, 1)
  288. Draw.Button('Order', 12, 230, 155, 50, 20)
  289. target = Draw.String("",91,290,155,50,20,"",30)
  290.  
  291. #Simulate widgets
  292.  
  293. BGL.glColor3ub(184, 255, 191)
  294. BGL.glRectf(4, 50, 365, 135)
  295.  
  296. BGL.glColor3ub(0, 0, 0)
  297. BGL.glRasterPos2d(12, 115)
  298. Draw.Text("Simulate")
  299. #BGL.glRasterPos2d(140, 90)
  300. #Draw.Text("Run simulation until toggle is released")
  301. BGL.glRasterPos2d(140, 65)
  302. Draw.Text("Run simulation for turns")
  303. #toggle = Draw.Toggle("Run", 7, 12, 85, 120, 20, toggle.val)
  304. Draw.Button("Run", 1, 12, 60, 120, 20)
  305. number = Draw.Slider("", 4, 245, 60, 70, 20, number.val, 1, 100)
  306.  
  307. elif information.val == 1:
  308. BGL.glRasterPos2d(12,432)
  309. Draw.Text('Select an Actor and press Get Stats.')
  310.  
  311. BGL.glRasterPos2d(12,414)
  312. Draw.Text('ID#')
  313. dbID = Draw.Number("", 81, 12, 396, 60, 15, dbID.val, 0, 500000)
  314.  
  315. BGL.glRasterPos2d(80,414)
  316. Draw.Text('Name')
  317. dbObjectName = Draw.String("", 81, 80, 396, 120, 15, dbObjectName.val, 64)
  318.  
  319. BGL.glRasterPos2d(208,414)
  320. Draw.Text('Type')
  321. dbType = Draw.String("", 81, 208, 396, 40, 15, dbType.val, 1)
  322.  
  323. BGL.glRasterPos2d(256,414)
  324. Draw.Text('Team')
  325. dbTeam = Draw.String("", 81, 256, 396, 40, 15, dbTeam.val, 1)
  326.  
  327. Draw.Button("Self", 74, 306, 396, 30, 15)
  328.  
  329. BGL.glRasterPos2d(288,383)
  330. Draw.Text('Commander ID')
  331. dbCommanderID = Draw.Number("", 81, 288, 363, 60, 15, dbCommanderID.val, 0, 500000)
  332.  
  333. BGL.glRasterPos2d(80,383)
  334. Draw.Text('Orders')
  335. ordermenustring = ''
  336. for singleOrder in orderlist:
  337. ordermenustring+=singleOrder+'|'
  338. ordermenustring=ordermenustring[:-1]
  339. dbOrders = Draw.Menu(ordermenustring, 81, 80, 363, 120, 15, dbOrders.val)
  340.  
  341. BGL.glRasterPos2d(210,383)
  342. Draw.Text('Params')
  343. dbOrderParam = Draw.String("", 81, 210, 363, 70, 15, dbOrderParam.val, 30)
  344.  
  345. BGL.glRasterPos2d(12,383)
  346. Draw.Text('xSpeed')
  347. dbOrderSpeed = Draw.Number("", 81, 12, 363, 60, 15, dbOrderSpeed.val, 0, 5)
  348.  
  349. BGL.glRasterPos2d(284,350)
  350. Draw.Text('Intellect')
  351. dbIntellect = Draw.Number("", 81, 284, 330, 60, 15, dbIntellect.val, 0, 1)
  352.  
  353. BGL.glRasterPos2d(12,350)
  354. Draw.Text('Speed')
  355. dbSpeed = Draw.Number("", 81, 12, 330, 60, 15, dbSpeed.val, 0, 20)
  356.  
  357. BGL.glRasterPos2d(80,350)
  358. Draw.Text('Attack')
  359. dbAttack = Draw.Number("", 81, 80, 330, 60, 15, dbAttack.val, 0, 50)
  360.  
  361. BGL.glRasterPos2d(148,350)
  362. Draw.Text('Defense')
  363. dbDefense = Draw.Number("", 81, 148, 330, 60, 15, dbDefense.val, 0, 50)
  364.  
  365. BGL.glRasterPos2d(216,350)
  366. Draw.Text('Health')
  367. dbHealth = Draw.Number("", 81, 216, 330, 60, 15, dbHealth.val, 0, 50)
  368.  
  369. BGL.glRasterPos2d(12,318)
  370. Draw.Text('R-Attack')
  371. dbAttackRadius = Draw.Number("", 81, 12, 298, 60, 15, dbAttackRadius.val, 0, 100)
  372.  
  373. BGL.glRasterPos2d(80,318)
  374. Draw.Text('R-Charge')
  375. dbChargeRadius = Draw.Number("", 81, 80, 298, 60, 15, dbChargeRadius.val, 0, 500)
  376.  
  377. BGL.glRasterPos2d(148,318)
  378. Draw.Text('R-Coward')
  379. dbCowardRadius = Draw.Number("", 81, 148, 298, 60, 15, dbCowardRadius.val, 0, 1000)
  380.  
  381. BGL.glRasterPos2d(216,318)
  382. Draw.Text('R-Buddy')
  383. dbBuddyRadius = Draw.Number("", 81, 216, 298, 60, 15, dbBuddyRadius.val, 0, 50)
  384.  
  385. BGL.glRasterPos2d(284,318)
  386. Draw.Text('R-Actor')
  387. dbActorRadius = Draw.Number("", 81, 284, 298, 60, 15, dbActorRadius.val, 0, 10)
  388.  
  389. BGL.glRasterPos2d(12,286)
  390. Draw.Text('View')
  391. dbFieldofView = Draw.Number("", 81, 12, 266, 60, 15, dbFieldofView.val, 0, 6.28)
  392.  
  393. BGL.glRasterPos2d(80,286)
  394. Draw.Text('MaxTurn')
  395. dbMaxTurn = Draw.Number("", 81, 80, 266, 60, 15, dbMaxTurn.val, 0, 6.28)
  396.  
  397. BGL.glRasterPos2d(148,286)
  398. Draw.Text('Loyalty')
  399. dbLoyalty = Draw.Number("", 81, 148, 266, 60, 15, dbLoyalty.val, 0, 1)
  400.  
  401. BGL.glRasterPos2d(216,286)
  402. Draw.Text('Pathfinding')
  403. dbPathmode = Draw.Menu('Types %t|terrain|astar|none', 81, 216, 266, 130, 15, pathmodes[defaultpathmode])
  404.  
  405. Draw.Button('Get Stats', 13, 12, 236, 70, 20)
  406. Draw.Button('Select Cmndr', 14, 90, 236, 90, 20)
  407. Draw.Button('Select Subs', 15, 188, 236, 90, 20)
  408. Draw.Button('Set Stats', 17, 286, 236, 70, 20)
  409.  
  410. Blender.dbCursor.execute('SELECT TypeID, TypeName FROM tblTypes')
  411. TypeMenuList = []
  412. typeList = Blender.dbCursor.fetchall()
  413. typeNames = 'Types %t'
  414. for order in typeList:
  415. TypeMenuList.append(order[0])
  416. typeNames += '|' + order[0] + ', ' + order[1]
  417. TypeMenu = Draw.Menu(typeNames, 18, 12, 35, 150, 20, 1)
  418.  
  419. BGL.glRasterPos2d(12,216)
  420. Draw.Text('Speed')
  421. tpSpeed = Draw.Number("",81,80,212,60,15,tpSpeed.val, 0, 20)
  422. tpSpeedV = Draw.Number("",81,140,212,60,15,tpSpeedV.val, 0, 1)
  423.  
  424. BGL.glRasterPos2d(12,200)
  425. Draw.Text('Attack Rad.')
  426. tpAttackRadius = Draw.Number("",81,80,196,60,15,tpAttackRadius.val, 0, 50)
  427. tpAttackRadiusV = Draw.Number("",81,140,196,60,15,tpAttackRadiusV.val, 0, 1)
  428.  
  429. BGL.glRasterPos2d(12,184)
  430. Draw.Text('Charge Rad.')
  431. tpChargeRadius = Draw.Number("",81,80,180,60,15,tpChargeRadius.val, 0, 50)
  432. tpChargeRadiusV = Draw.Number("",81,140,180,60,15,tpChargeRadiusV.val, 0, 1)
  433.  
  434. BGL.glRasterPos2d(12,168)
  435. Draw.Text('Coward Rad.')
  436. tpCowardRadius = Draw.Number("",81,80,164,60,15,tpCowardRadius.val, 0, 50)
  437. tpCowardRadiusV = Draw.Number("",81,140,164,60,15,tpCowardRadiusV.val, 0, 1)
  438.  
  439. BGL.glRasterPos2d(12,152)
  440. Draw.Text('Buddy Rad.')
  441. tpBuddyRadius = Draw.Number("",81,80,148,60,15,tpBuddyRadius.val, 0, 50)
  442. tpBuddyRadiusV = Draw.Number("",81,140,148,60,15,tpBuddyRadiusV.val, 0, 1)
  443.  
  444. BGL.glRasterPos2d(12,136)
  445. Draw.Text('Health')
  446. tpHealth = Draw.Number("",81,80,132,60,15,tpHealth.val, 0, 50)
  447. tpHealthV = Draw.Number("",81,140,132,60,15,tpHealthV.val, 0, 1)
  448.  
  449. BGL.glRasterPos2d(12,120)
  450. Draw.Text('Attack')
  451. tpAttack = Draw.Number("",81,80,116,60,15,tpAttack.val, 0, 50)
  452. tpAttackV = Draw.Number("",81,140,116,60,15,tpAttackV.val, 0, 1)
  453.  
  454. BGL.glRasterPos2d(12,104)
  455. Draw.Text('Defense')
  456. tpDefense = Draw.Number("",81,80,100,60,15,tpDefense.val, 0, 50)
  457. tpDefenseV = Draw.Number("",81,140,100,60,15,tpDefenseV.val, 0, 1)
  458.  
  459. BGL.glRasterPos2d(12,88)
  460. Draw.Text('Intellect')
  461. tpIntellect = Draw.Number("",81,80,84,60,15,tpIntellect.val, 0, 1)
  462. tpIntellectV = Draw.Number("",81,140,84,60,15,tpIntellectV.val, 0, 1)
  463.  
  464. BGL.glRasterPos2d(205,216)
  465. Draw.Text('Field of View')
  466. tpFieldofView = Draw.Number("",81,285,212,60,15,tpFieldofView.val, 0, 180)
  467. tpFieldofViewV = Draw.Number("",81,285,197,60,15,tpFieldofViewV.val, 0, 1)
  468.  
  469. BGL.glRasterPos2d(205,177)
  470. Draw.Text('MaxTurn')
  471. tpMaxTurn = Draw.Number("",81,285,173,60,15,tpMaxTurn.val, 0, 180)
  472. tpMaxTurnV = Draw.Number("",81,285,158,60,15,tpMaxTurnV.val, 0, 1)
  473.  
  474. BGL.glRasterPos2d(205,138)
  475. Draw.Text('Name')
  476. tpTypeName = Draw.String("", 81, 205, 118, 150, 15, tpTypeName.val, 60)
  477.  
  478. BGL.glRasterPos2d(205,104)
  479. Draw.Text('Type Identifier')
  480.  
  481. tpTypeID = Draw.String("", 81, 205, 84, 150, 15, tpTypeID.val, 1)
  482.  
  483. Draw.Button('Get Type', 19, 170, 35, 60, 20)
  484. Draw.Button('Set Type', 20, 238, 35, 60, 20)
  485. Draw.Button('New', 21, 304, 35, 50, 20)
  486.  
  487. elif simtools.val == 1:
  488. #Effectors and Simulation widgets
  489.  
  490. BGL.glRasterPos2d(12,220)
  491. Draw.Text('Effector Name:')
  492. BGL.glRasterPos2d(12,205)
  493. Draw.Text(EffectorName)
  494.  
  495. BGL.glRasterPos2d(170,220)
  496. Draw.Text('Duration')
  497. efDuration = Draw.Menu('Duration %t|Permanent|Temporary', 81, 170, 200, 100, 15, efDuration.val)
  498.  
  499. BGL.glRasterPos2d(12,180)
  500. Draw.Text('Works on these Actors')
  501. efAffects = Draw.Menu('Affects %t|All|Team|Type', 81, 12, 160, 150, 15, efAffects.val)
  502.  
  503. BGL.glRasterPos2d(170,180)
  504. Draw.Text('Team or Type')
  505. efAffectsValue = Draw.String("", 81, 170, 160, 60, 15, efAffectsValue.val, 5)
  506.  
  507. BGL.glRasterPos2d(12,140)
  508. Draw.Text('Attribute Affected')
  509. eam = 'Attributes %t'
  510. for listitem in AttributeList:
  511. eam+='|' + listitem
  512. efAttributeMenu = Draw.Menu(eam, 81, 12, 120, 80, 15, efAttributeMenu.val)
  513.  
  514. BGL.glRasterPos2d(120,140)
  515. Draw.Text('Operator')
  516. eom = 'Operators %t'
  517. for listitem in OperatorList:
  518. eom+='|' + listitem
  519. efOperatorMenu = Draw.Menu(eom, 81, 120, 120, 40, 15, efOperatorMenu.val)
  520.  
  521. BGL.glRasterPos2d(175,140)
  522. Draw.Text('Value')
  523. efValue = Draw.Number("", 81, 175, 120, 60, 15, efValue.val, 0, 1000)
  524.  
  525. BGL.glRasterPos2d(12,105)
  526. Draw.Text('Associated Action')
  527. efAction = Draw.String("", 81, 12, 85, 120, 15, efAction.val, 30)
  528.  
  529. efActive = Draw.Toggle("Active", 81, 150, 85, 60, 15, efActive.val)
  530.  
  531. Draw.Button("Create/Set", 70, 12, 40, 90, 20)
  532. Draw.Button("Retrieve", 71, 115, 40, 90, 20)
  533.  
  534. Draw.Button("Generate Locomtion",72,12,360,180,20)
  535. Draw.Button("Set Level of Detail",73,12,330,180,20)
  536. Draw.Button("Generate NLA",75,12,300,180,20)
  537.  
  538. def event(evt, val):
  539. if ((evt == Draw.QKEY or evt == Draw.ESCKEY) and not val):
  540. #Blender.dbCursor.disconnect
  541. #print 'Connection to DB closed.'
  542. Draw.Exit()
  543. if (evt == Draw.XKEY and not val):
  544. toggle.val = 0
  545.  
  546. def buttonEvents(evt):
  547.  
  548. global toggle, number, obstacle, reversepathmodes, orderlist
  549. global dbID,dbType,dbTeam,dbObjectName,dbCommanderID,dbOrderSpeed,dbSpeed,dbAttack,dbActorRadius
  550. global dbDefense,dbIntellect,dbHealth,dbFieldofView,dbMaxTurn,dbPathmode,dbOrders,defaultpathmode
  551. global dbAttackRadius,dbChargeRadius,dbCowardRadius,dbBuddyRadius,dbLoyalty,globalID,dbOrderParam
  552.  
  553. global TypeMenu,tpTypeID,tpTypeName,tpSpeed,tpSpeedV,tpAttackRadius,tpAttackRadiusV,tpChargeRadius
  554. global tpChargeRadiusV,tpCowardRadius,tpCowardRadiusV,tpBuddyRadius,tpBuddyRadiusV
  555. global tpHealth,tpHealthV,tpAttack,tpAttackV,tpDefense,tpDefenseV,tpIntellect,tpIntellectV
  556. global tpFieldofView,tpFieldofViewV,tpMaxTurn,tpMaxTurnV,tpActorRadius,TypeMenuList,originalType
  557.  
  558. global AffectsList,AttributeList,OperatorList,efAffects,efAffectsValue,efAttributeMenu,efOperatorMenu,efValue,efAction,efActive
  559. global EffectorName,efDuration,DurationList
  560.  
  561. if evt == 1:
  562. for counter in range(number.val):
  563. scrollMessage(Effectors.CheckEffectors())
  564. scrollMessage(Main.Main())
  565. #Window.DrawProgressBar(float(counter)/number.val,'Moving')
  566. Draw.Draw()
  567. Blender.Redraw()
  568. #Window.DrawProgressBar(1,'Done')
  569. elif evt == 10:
  570. Draw.Exit()
  571. elif evt == 14:
  572. subObject = Blender.Object.GetSelected()
  573. if subObject == []:
  574. scrollMessage('Please select an object.')
  575. Draw.Draw()
  576. else:
  577. subList = ActorQueries.getActor(subObject[0])
  578. if subList == -1:
  579. scrollMessage('Please select a registered Actor.')
  580. else:
  581. commanderid=subList[6]
  582. if commanderid > 0:
  583. SQLQuery='SELECT ObjectName FROM tblActors WHERE ID=' + str(commanderid)
  584. Blender.dbCursor.execute(SQLQuery)
  585. SQLResult=Blender.dbCursor.fetchone()
  586. if SQLResult:
  587. CommanderObject=Blender.Object.Get(SQLResult[0])
  588. subObject[0].select(0)
  589. CommanderObject.select(1)
  590. Blender.Window.RedrawAll()
  591. elif evt == 15:
  592. comObject = Blender.Object.GetSelected()
  593. if comObject == []:
  594. scrollMessage('Please select an object.')
  595. else:
  596. comList = ActorQueries.getActor(comObject[0])
  597. if comList == -1:
  598. scrollMessage('Please select a registered Actor.')
  599. else:
  600. commanderid=comList[0]
  601. SQLQuery='SELECT ObjectName FROM tblActors WHERE CommanderID=' + str(commanderid)
  602. Blender.dbCursor.execute(SQLQuery)
  603. SQLResult=Blender.dbCursor.fetchall()
  604. print(SQLResult)
  605. for subActor in SQLResult:
  606. tempObject = Blender.Object.Get(subActor[0])
  607. tempObject.select(1)
  608. comObject[0].select(1)
  609. Blender.Window.RedrawAll()
  610. elif evt == 30:
  611. if obstacle.val == 0:
  612. Blender.barriers = 0
  613. else:
  614. Blender.barriers = 1
  615. Draw.Draw()
  616. elif evt == 2:
  617. scrollMessage('Initializing...')
  618. scrollMessage(Initialization.Initialize(Blender.dbCursor))
  619. elif evt == 3:
  620. scrollMessage('Building Search Tree...')
  621. scrollMessage(BuildTree.BuildTree())
  622. BuildTree.loadTree()
  623. Draw.Draw()
  624. elif evt == 16:
  625. scrollMessage('Resetting...')
  626. scrollMessage(Initialization.ResetActors(Blender.dbCursor))
  627. elif evt == 5:
  628. scrollMessage(AutoInitCnC.AutoInitCnC())
  629. elif evt == 6:
  630. ManualCnC.ManualCnC()
  631. elif evt == 7:
  632. #while toggle.val == 1:
  633. # scrollMessage(Main.Main())
  634. # Draw.Draw()
  635. pass
  636. elif evt == 12:
  637. scrollMessage(ChangeOrders.ChangeOrders(teamlist[team.val-1],orderlist[orders.val-1],target.val))
  638. Draw.Draw()
  639. elif evt == 99:
  640. general.val = 1
  641. information.val = 0
  642. simtools.val = 0
  643. Draw.Draw()
  644. elif evt == 98:
  645. general.val = 0
  646. information.val = 1
  647. simtools.val = 0
  648. Draw.Draw()
  649. elif evt == 97:
  650. general.val = 0
  651. information.val = 0
  652. simtools.val = 1
  653. Draw.Draw()
  654. elif evt == 13: # Get Actor stats from database and display
  655. statObject = Blender.Object.GetSelected()
  656. if statObject == []:
  657. scrollMessage('Please select an object.')
  658. Draw.Draw()
  659. else:
  660. statList = ActorQueries.getActor(statObject[0])
  661. if statList == -1:
  662. scrollMessage('Please select a registered Actor.')
  663. Draw.Draw()
  664. else:
  665. dbID.val = statList[0]
  666. globalID = dbID.val
  667. dbType.val = statList[1]
  668. dbTeam.val = statList[2]
  669. dbObjectName.val = statList[3]
  670. dbOrderSpeed.val = statList[4]
  671. actualorder=statList[5]
  672. if actualorder == None:
  673. actualorder = ''
  674. dbOrders.val=0
  675. dbOrderParam.val = ''
  676. else:
  677. orderindex=0
  678. orderfound=False
  679. while (orderfound==False):
  680. orderindex+=1
  681. orderfound = actualorder.startswith(orderlist[orderindex-1])
  682. dbOrders.val = orderindex
  683. dbOrderParam.val = actualorder[len(orderlist[orderindex-1]):]
  684. dbCommanderID.val = statList[6]
  685. dbSpeed.val = statList[7]
  686. dbAttack.val = statList[8]
  687. dbDefense.val = statList[9]
  688. dbIntellect.val = statList[10]
  689. dbHealth.val = statList[11]
  690. dbFieldofView.val = statList[12]
  691. dbMaxTurn.val = statList[13]
  692. if statList[14] == None:
  693. dbWeapon.val = ''
  694. else:
  695. dbWeapon.val = statList[14]
  696. dbAttackRadius.val = statList[15]
  697. dbChargeRadius.val = statList[16]
  698. dbCowardRadius.val = statList[17]
  699. dbBuddyRadius.val = statList[18]
  700. dbLoyalty.val = statList[19]
  701. dbActorRadius.val = statList[20]
  702. defaultpathmode = statList[21]
  703. Draw.Draw()
  704. elif evt == 17:
  705. actualorder = orderlist[dbOrders.val-1] + dbOrderParam.val
  706. statList = [globalID,dbType.val,dbTeam.val,dbObjectName.val,dbOrderSpeed.val,actualorder,dbCommanderID.val,dbSpeed.val,dbAttack.val,dbDefense.val,dbIntellect.val,dbHealth.val,dbFieldofView.val,dbMaxTurn.val,dbWeapon.val,dbAttackRadius.val,dbChargeRadius.val,dbCowardRadius.val,dbBuddyRadius.val,dbLoyalty.val,dbActorRadius,reversepathmodes[dbPathmode.val]]
  707. scrollMessage(ActorQueries.setActor(statList))
  708. defaultpathmode=reversepathmodes[dbPathmode.val]
  709. Draw.Draw()
  710. elif evt == 74: # Set Actor to be it's own Commander
  711. dbCommanderID.val = dbID.val
  712. scrollMessage(ActorQueries.selfCommander(dbID.val))
  713. Draw.Draw()
  714. elif evt == 19: # Get Actor Type from database and display
  715. statList = ActorQueries.getType(TypeMenuList[TypeMenu.val - 1])
  716. if statList == -1:
  717. scrollMessage('That Type is not in the database.')
  718. Draw.Draw()
  719. else:
  720. tpTypeID.val = statList[0]
  721. originalType = tpTypeID.val
  722. tpTypeName.val = statList[1]
  723. tpSpeed.val = statList[2]
  724. tpSpeedV.val = statList[3]
  725. tpAttackRadius.val = statList[4]
  726. tpAttackRadiusV.val = statList[5]
  727. tpChargeRadius.val = statList[6]
  728. tpChargeRadiusV.val = statList[7]
  729. tpCowardRadius.val = statList[8]
  730. tpCowardRadiusV.val = statList[9]
  731. tpBuddyRadius.val = statList[10]
  732. tpBuddyRadiusV.val = statList[11]
  733. tpHealth.val = statList[12]
  734. tpHealthV.val = statList[13]
  735. tpAttack.val = statList[14]
  736. tpAttackV.val = statList[15]
  737. tpDefense.val = statList[16]
  738. tpDefenseV.val = statList[17]
  739. tpIntellect.val = statList[18]
  740. tpIntellectV.val = statList[19]
  741. tpFieldofView.val = statList[20]
  742. tpFieldofViewV.val = statList[21]
  743. tpMaxTurn.val = statList[22]
  744. tpMaxTurnV.val = statList[23]
  745. tpActorRadius.val = statList[24]
  746. Draw.Draw()
  747. elif evt == 20: #Set values into display Type
  748. statList = [tpTypeID.val,tpTypeName.val,tpSpeed.val,tpSpeedV.val,tpAttackRadius.val,tpAttackRadiusV.val]
  749. statList.extend([tpChargeRadius.val,tpChargeRadiusV.val,tpCowardRadius.val,tpCowardRadiusV.val])
  750. statList.extend([tpBuddyRadius.val,tpBuddyRadiusV.val,tpHealth.val,tpHealthV.val,tpAttack.val,tpAttackV.val])
  751. statList.extend([tpDefense.val,tpDefenseV.val,tpIntellect.val,tpIntellectV.val,tpFieldofView.val,tpFieldofViewV.val])
  752. statList.extend([tpMaxTurn.val,tpMaxTurnV.val,tpActorRadius.val])
  753. scrollMessage(ActorQueries.setType(statList,originalType))
  754. Draw.Draw()
  755. elif evt == 72: #Generate locomotion
  756. animreturn=Locomotion.locomoteselected()
  757. scrollMessage(animreturn)
  758. Draw.Draw()
  759. elif evt == 73: # Set Level of Detail
  760. animreturn=BuildNLA.setLoDforselected()
  761. scrollMessage(animreturn)
  762. Draw.Draw()
  763. elif evt == 75: # Build NLA
  764. animreturn=BuildNLA.buildnlaforselected()
  765. scrollMessage(animreturn)
  766. Draw.Draw()
  767. elif evt == 71: #Retrieve and Display Effector
  768. effObject = Blender.Object.GetSelected()
  769. SQLEffector = ActorQueries.getEffector(effObject[0])
  770. if SQLEffector==-1:
  771. scrollMessage('Please select a registered Effector.')
  772. else:
  773. EffectorName = SQLEffector[0]
  774. efAffects.val = AffectsList.index(SQLEffector[1])+1
  775. efAffectsValue.val = SQLEffector[2]
  776. efAttributeMenu.val = AttributeList.index(SQLEffector[3])+1
  777. efOperatorMenu.val = OperatorList.index(SQLEffector[4])+1
  778. efValue.val = SQLEffector[5]
  779. efAction.val = SQLEffector[6]
  780. efActive.val = SQLEffector[7]
  781. efDuration.val = DurationList.index(SQLEffector[8])+1
  782. Draw.Draw()
  783. elif evt == 70: #Create or Set stats for Effectors
  784. effObject = Blender.Object.GetSelected()
  785. SQLEffector = ActorQueries.getEffector(effObject[0])
  786. if SQLEffector==-1: # Register a new effector
  787. SQLReturn=ActorQueries.createEffector(effObject[0].getName(),AffectsList[efAffects.val-1],efAffectsValue.val,AttributeList[efAttributeMenu.val-1],OperatorList[efOperatorMenu.val-1],efValue.val,efAction.val,efActive.val,DurationList[efDuration.val-1])
  788. else: #Effector already exists - reset it
  789. print(AttributeList[efAttributeMenu.val-1],OperatorList[efOperatorMenu.val-1],AffectsList[efAffects.val-1])
  790. SQLReturn=ActorQueries.setEffector(effObject[0].getName(),AffectsList[efAffects.val-1],efAffectsValue.val,AttributeList[efAttributeMenu.val-1],OperatorList[efOperatorMenu.val-1],efValue.val,efAction.val,efActive.val,DurationList[efDuration.val-1])
  791. scrollMessage(SQLReturn)
  792. Draw.Draw()
  793. elif evt == 21: #Create and display new Type
  794. newType = ActorQueries.newType()
  795. if newType != -1:
  796. scrollMessage('New type Created.')
  797. statList = ActorQueries.getType(newType)
  798. tpTypeID.val = statList[0]
  799. originalType = tpTypeID.val
  800. tpTypeName.val = statList[1]
  801. tpSpeed.val = statList[2]
  802. tpSpeedV.val = statList[3]
  803. tpAttackRadius.val = statList[4]
  804. tpAttackRadiusV.val = statList[5]
  805. tpChargeRadius.val = statList[6]
  806. tpChargeRadiusV.val = statList[7]
  807. tpCowardRadius.val = statList[8]
  808. tpCowardRadiusV.val = statList[9]
  809. tpBuddyRadius.val = statList[10]
  810. tpBuddyRadiusV.val = statList[11]
  811. tpHealth.val = statList[12]
  812. tpHealthV.val = statList[13]
  813. tpAttack.val = statList[14]
  814. tpAttackV.val = statList[15]
  815. tpDefense.val = statList[16]
  816. tpDefenseV.val = statList[17]
  817. tpIntellect.val = statList[18]
  818. tpIntellectV.val = statList[19]
  819. tpFieldofView.val = statList[20]
  820. tpFieldofViewV.val = statList[21]
  821. tpMaxTurn.val = statList[22]
  822. tpMaxTurnV.val = statList[23]
  823. tpActorRadius.val = statList[24]
  824. Draw.Draw()
  825. else:
  826. return
  827.  
  828. def scrollMessage(newMessage):
  829. if newMessage:
  830. msgWindow01.val = msgWindow02.val
  831. msgWindow02.val = msgWindow03.val
  832. msgWindow03.val = msgWindow04.val
  833. msgWindow04.val = msgWindow05.val
  834. msgWindow05.val = newMessage
  835. Draw.Draw()
  836.  
  837. txtnames=[txt2.name for txt2 in Blender.Text.Get()]
  838. try:
  839. itxt=txtnames.index("MySQLInfo")
  840. print("MySQLInfo file found...testing.")
  841. try:
  842. cnctInfoOb=Blender.Text.Get('MySQLInfo')
  843. connectInfo=cnctInfoOb.asLines()
  844. dbConn = MySQLdb.connect(connectInfo[0], connectInfo[1], connectInfo[2])
  845. except:
  846. host.val=connectInfo[0]
  847. user.val=connectInfo[1]
  848. password.val=connectInfo[2]
  849. Blender.Text.unlink(cnctInfoOb)
  850. Draw.Register(drawMySQL, MySQLevent, MySQLbevent)
  851. Blender.Redraw()
  852. else: #connection successful
  853. #newtxt=Blender.Text.New("MySQLInfo")
  854. #newtxt.write(host.val+"\n"+user.val+"\n"+password.val+"\n")
  855. message.val = 'Connection Succeeded!'
  856. main()
  857. except ValueError:
  858. #BlenderPeople has never been successfully run...
  859. #ask for connection info and test the connection
  860. print("MySQLInfo does not exist.")
  861. Draw.Register(drawMySQL, MySQLevent, MySQLbevent)
  862. Blender.Redraw()
Add Comment
Please, Sign In to add comment