added LogicGate

This commit is contained in:
Dave Schuyler 2003-09-10 03:30:18 +00:00
parent b1d04596d1
commit 919c39294b
2 changed files with 90 additions and 6 deletions

View File

@ -8,9 +8,7 @@ import DistributedGagBarrelAI
#import DistributedStomperPairAI
import DistributedSwitchAI
import DistributedStomperAI
import AndLoEntityAI
import OrLoEntityAI
#import XorLoEntity
import LogicGateAI
def cDE(AIclass, air, levelDoId, entId, zoneId):
@ -36,9 +34,7 @@ EntityType2Ctor = {
'stomper': Functor(cDE, DistributedStomperAI.DistributedStomperAI),
'switch': DistributedSwitchAI.DistributedSwitchAI,
'andLogicObject': AndLoEntityAI.AndLoEntityAI,
'orLogicObject': OrLoEntityAI.OrLoEntityAI,
'xorLogicObject': nothing, #XorLoEntity.XorLoEntity,
'logicGate': LogicGateAI.LogicGateAI,
}
def createEntity(entType, air, levelDoId, entId, zoneId):

88
direct/src/level/LogicGateAI.py Executable file
View File

@ -0,0 +1,88 @@
"""LogicGateAI.py: contains the OrLoEntity class"""
import PandaObject
import DirectNotifyGlobal
import Entity
def andTest(self, a, b):
assert(self.debugPrint("andTest(a=%s, b=%s)"%(a, b)))
if b:
messenger.send(self.getName(), [a])
def orTest(self, a, b):
assert(self.debugPrint("orTest(a=%s, b=%s)"%(a, b)))
if not b:
messenger.send(self.getName(), [a])
# else: ...we already sent the messege when b was set.
def xorTest(self, a, b):
assert(self.debugPrint("xorTest(a=%s, b=%s)"%(a, b)))
messenger.send(self.getName(), [(not (a and b)) and (a or b)])
class LogicGateAI(Entity.Entity, PandaObject.PandaObject):
if __debug__:
notify = DirectNotifyGlobal.directNotify.newCategory(
'LogicGateAI')
logicTests={
"and": andTest,
"or": orTest,
"xor": xorTest,
}
def __init__(self, air, levelDoId, entId, zoneId=None):
"""entId: """
assert(self.debugPrint(
"LogicGateAI(air=%s, levelDoId=%s, entId=%s, zoneId=%s)"
%("the air", levelDoId, entId, zoneId)))
self.input1 = None
self.input2 = None
self.levelDoId = levelDoId
level = air.doId2do[self.levelDoId]
Entity.Entity.__init__(self, level, entId)
self.initializeEntity()
self.setLogicType(self.logicType)
self.setInput_input1_bool(self.input_input1_bool)
self.setInput_input2_bool(self.input_input2_bool)
def setLogicType(self, logicType):
assert(self.debugPrint("setLogicType(logicType=%s)"%(logicType,)))
self.logicType=logicType
assert self.logicTests[logicType]
self.logicTest=self.logicTests[logicType]
def setIsInput1(self, isTrue):
assert(self.debugPrint("setIsInput1(isTrue=%s)"%(isTrue,)))
if 1 or (not isTrue) != (not self.input1):
# ...the logical state of self.input1 has changed.
self.isInput1=isTrue
self.logicTest(self, isTrue, self.isInput2)
def setIsInput2(self, isTrue):
assert(self.debugPrint("setIsInput1(isTrue=%s)"%(isTrue,)))
if 1 or (not isTrue) != (not self.input2):
# ...the logical state of self.input2 has changed.
self.isInput2=isTrue
self.logicTest(self, isTrue, self.isInput1)
def setInput_input1_bool(self, event):
assert(self.debugPrint("setInput_input1_bool(event=%s)"%(event,)))
if self.input1:
self.ignore(self.input1)
self.input1 = "switch-%s"%(event,)
if self.input1:
self.accept(self.input1, self.setIsInput1)
def setInput_input2_bool(self, event):
assert(self.debugPrint("setInput_input2_bool(event=%s)"%(event,)))
if self.input2:
self.ignore(self.input2)
self.input2 = "switch-%s"%(event,)
if self.input2:
self.accept(self.input2, self.setIsInput2)
def getName(self):
#return "orLoEntity-%s"%(self.entId,)
return "switch-%s"%(self.entId,)