| 1 | # bMotion - Mood handling |
|---|
| 2 | # |
|---|
| 3 | # $Id$ |
|---|
| 4 | # |
|---|
| 5 | |
|---|
| 6 | ############################################################################### |
|---|
| 7 | # bMotion - an 'AI' TCL script for eggdrops |
|---|
| 8 | # Copyright (C) James Michael Seward 2000-2002 |
|---|
| 9 | # |
|---|
| 10 | # This program is free software; you can redistribute it and/or modify |
|---|
| 11 | # it under the terms of the GNU General Public License as published by |
|---|
| 12 | # the Free Software Foundation; either version 2 of the License, or |
|---|
| 13 | # (at your option) any later version. |
|---|
| 14 | # |
|---|
| 15 | # This program is distributed in the hope that it will be useful, but |
|---|
| 16 | # WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 18 | # General Public License for more details. |
|---|
| 19 | # |
|---|
| 20 | # You should have received a copy of the GNU General Public License |
|---|
| 21 | # along with this program; if not, write to the Free Software |
|---|
| 22 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 23 | ############################################################################### |
|---|
| 24 | |
|---|
| 25 | #Init variables |
|---|
| 26 | set mood(happy) 0 |
|---|
| 27 | set mood(horny) 0 |
|---|
| 28 | set mood(lonely) 0 |
|---|
| 29 | set mood(electricity) 2 |
|---|
| 30 | set mood(stoned) 0 |
|---|
| 31 | |
|---|
| 32 | set moodtarget(happy) 0 |
|---|
| 33 | set moodtarget(horny) 0 |
|---|
| 34 | set moodtarget(lonely) 5 |
|---|
| 35 | set moodtarget(electricity) 2 |
|---|
| 36 | set moodtarget(stoned) 0 |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | ## MOOD ROUTINES _________________________________________________________________________________ |
|---|
| 40 | proc bMotionGetHappy {} { |
|---|
| 41 | global mood |
|---|
| 42 | incr mood(happy) 1 |
|---|
| 43 | checkmood "" "" |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | proc bMotionGetSad {} { |
|---|
| 47 | global mood |
|---|
| 48 | incr mood(happy) -1 |
|---|
| 49 | checkmood "" "" |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | proc bMotionGetHorny {} { |
|---|
| 53 | global mood |
|---|
| 54 | incr mood(horny) 1 |
|---|
| 55 | checkmood "" "" |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | proc bMotionGetUnHorny {} { |
|---|
| 59 | global mood |
|---|
| 60 | incr mood(horny) -1 |
|---|
| 61 | checkmood "" "" |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | proc bMotionGetLonely {} { |
|---|
| 65 | global mood |
|---|
| 66 | incr mood(lonely) 1 |
|---|
| 67 | checkmood "" "" |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | proc bMotionGetUnLonely {} { |
|---|
| 71 | global mood |
|---|
| 72 | incr mood(lonely) -1 |
|---|
| 73 | checkmood "" "" |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | ## Checkmood: checks the moods are within limits |
|---|
| 77 | proc checkmood {nick channel} { |
|---|
| 78 | global mood |
|---|
| 79 | foreach r {happy horny lonely electricity stoned} { |
|---|
| 80 | if {$r < -30} { |
|---|
| 81 | set mood($r) -30 |
|---|
| 82 | bMotion_putloglev d * "bMotion: Mood($r) went OOB, resetting to -30" |
|---|
| 83 | } |
|---|
| 84 | if {$mood($r) > 30} { |
|---|
| 85 | bMotion_putloglev d * "bMotion: Mood($r) went OOB, resetting to 30" |
|---|
| 86 | set mood($r) 30 |
|---|
| 87 | } |
|---|
| 88 | } |
|---|
| 89 | if {$nick == ""} {return 0} |
|---|
| 90 | |
|---|
| 91 | if {($mood(happy) > 10) && ($mood(lonely) > 5) && ($mood(horny) > 5)} { |
|---|
| 92 | mee $channel "replicates some tissues" |
|---|
| 93 | mee $channel "locks [getPronoun] in the bathroom" |
|---|
| 94 | set mood(horny) [expr $mood(horny) - 10] |
|---|
| 95 | set mood(lonely) [expr $mood(lonely) -3] |
|---|
| 96 | } |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | |
|---|
| 100 | ## Driftmood: Drifts all moods towards 0 |
|---|
| 101 | proc driftmood {} { |
|---|
| 102 | global bMotionCache |
|---|
| 103 | set bMotionCache(lastHows) "" |
|---|
| 104 | set driftSummary "" |
|---|
| 105 | global mood mooddrifttimer moodtarget |
|---|
| 106 | foreach r {happy horny lonely electricity stoned} { |
|---|
| 107 | set drift 0 |
|---|
| 108 | set driftString "" |
|---|
| 109 | if {$mood($r) > $moodtarget($r)} { |
|---|
| 110 | set drift -1 |
|---|
| 111 | set driftString "$moodtarget($r)<$mood($r)" |
|---|
| 112 | } |
|---|
| 113 | if {$mood($r) < $moodtarget($r)} { |
|---|
| 114 | set drift 2 |
|---|
| 115 | set driftString "$mood($r)>$moodtarget($r)" |
|---|
| 116 | } |
|---|
| 117 | if {$drift != 0} { |
|---|
| 118 | set mood($r) [expr $mood($r) + $drift] |
|---|
| 119 | set driftSummary "$driftSummary $r ($driftString) " |
|---|
| 120 | } |
|---|
| 121 | } |
|---|
| 122 | if {$driftSummary != ""} { |
|---|
| 123 | bMotion_putloglev d * "bMotion: driftMood $driftSummary" |
|---|
| 124 | } |
|---|
| 125 | checkmood "" "" |
|---|
| 126 | set mooddrifttimer 1 |
|---|
| 127 | |
|---|
| 128 | #now also drift all channels towards 0 |
|---|
| 129 | global bMotionInfo |
|---|
| 130 | foreach chan $bMotionInfo(randomChannels) { |
|---|
| 131 | set chanMood $bMotionCache($chan,mood) |
|---|
| 132 | if {$chanMood > 0} { |
|---|
| 133 | incr chanMood -1 |
|---|
| 134 | } |
|---|
| 135 | if {$chanMood < 0} { |
|---|
| 136 | incr chanMood |
|---|
| 137 | } |
|---|
| 138 | set bMotionCache($chan,mood) $chanMood |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | timer 10 driftmood |
|---|
| 142 | return 0 |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | |
|---|
| 146 | ## moodTimerStart: Used to start the mood drift timer when the script initialises |
|---|
| 147 | ## and other timers now, too |
|---|
| 148 | proc moodTimerStart {} { |
|---|
| 149 | global mooddrifttimer |
|---|
| 150 | if {![info exists mooddrifttimer]} { |
|---|
| 151 | timer 10 driftmood |
|---|
| 152 | utimer 5 loldec |
|---|
| 153 | # utimer 90 smileyhandler |
|---|
| 154 | timer [expr [rand 30] + 3] doRandomStuff |
|---|
| 155 | set mooddrifttimer 1 |
|---|
| 156 | } |
|---|
| 157 | } |
|---|
| 158 | |
|---|
| 159 | |
|---|
| 160 | ## moodHander: DCC .mood |
|---|
| 161 | proc moodhandler {handle idx arg} { |
|---|
| 162 | global mood |
|---|
| 163 | putidx $idx "My current mood is $mood(happy) $mood(horny) $mood(lonely) $mood(electricity) $mood(stoned): happy horny lonely electricity stoned" |
|---|
| 164 | if {$arg != ""} { |
|---|
| 165 | if {$arg == "drift"} { |
|---|
| 166 | driftmood |
|---|
| 167 | return 0 |
|---|
| 168 | } |
|---|
| 169 | set moodtype [lindex $arg 0] |
|---|
| 170 | set moodsetting [lindex $arg 1] |
|---|
| 171 | set mood($moodtype) $moodsetting |
|---|
| 172 | putlog "bMotion: Mood($moodtype) changed to $moodsetting by $handle" |
|---|
| 173 | } |
|---|
| 174 | checkmood "" "" |
|---|
| 175 | } |
|---|
| 176 | |
|---|
| 177 | |
|---|
| 178 | ## pubm_moodHandler: !mood |
|---|
| 179 | proc pubm_moodhandler {nick host handle channel text} { |
|---|
| 180 | global mood botnick |
|---|
| 181 | set text [string trim $text] |
|---|
| 182 | if [regexp -nocase "^${botnick}$" $text] { |
|---|
| 183 | set ming "Mood: " |
|---|
| 184 | foreach r {happy horny lonely electricity stoned} { |
|---|
| 185 | append ming " $r=$mood($r) " |
|---|
| 186 | } |
|---|
| 187 | global bMotionCache |
|---|
| 188 | append ming " chanmood=[makeSmiley $bMotionCache($channel,mood)]" |
|---|
| 189 | bMotionDoAction $channel "" $ming |
|---|
| 190 | return 0 |
|---|
| 191 | } |
|---|
| 192 | |
|---|
| 193 | if [regexp -nocase "^$botnick (.+)" $text args] { |
|---|
| 194 | if {[matchattr $handle m]} { |
|---|
| 195 | if {$args == "drift"} { |
|---|
| 196 | driftmood |
|---|
| 197 | return 0 |
|---|
| 198 | } |
|---|
| 199 | set moodtype [lindex $args 1] |
|---|
| 200 | set moodsetting [lindex $args 2] |
|---|
| 201 | if {[catch {expr $moodsetting}]} { |
|---|
| 202 | putserv "PRIVMSG $nick :Fewl, that's not right." |
|---|
| 203 | return 0 |
|---|
| 204 | } |
|---|
| 205 | set mood($moodtype) $moodsetting |
|---|
| 206 | putlog "bMotion: Mood($moodtype) changed to $moodsetting by $handle" |
|---|
| 207 | mee $channel "undergoes mood swing" |
|---|
| 208 | return 0 |
|---|
| 209 | } else { |
|---|
| 210 | bMotionDoAction $channel "" "No." |
|---|
| 211 | putlog "bMotion: $nick tried mood $args on $channel and failed." |
|---|
| 212 | return 0 |
|---|
| 213 | } |
|---|
| 214 | } |
|---|
| 215 | checkmood "" "" |
|---|
| 216 | } |
|---|
| 217 | |
|---|
| 218 | ## pubm_moodHandler: !mood |
|---|
| 219 | proc pubm_moodhandler {nick host handle channel text} { |
|---|
| 220 | if {![matchattr $handle n]} { |
|---|
| 221 | bMotionDoAction $channel "" "That command is no longer available." |
|---|
| 222 | return 0 |
|---|
| 223 | } |
|---|
| 224 | |
|---|
| 225 | |
|---|
| 226 | global mood botnick |
|---|
| 227 | set text [string trim $text] |
|---|
| 228 | if [regexp -nocase "^${botnick}$" $text] { |
|---|
| 229 | set ming "Mood: " |
|---|
| 230 | foreach r {happy horny lonely electricity stoned} { |
|---|
| 231 | append ming " $r=$mood($r) " |
|---|
| 232 | } |
|---|
| 233 | global bMotionCache |
|---|
| 234 | append ming " chanmood=[makeSmiley $bMotionCache($channel,mood)]" |
|---|
| 235 | bMotionDoAction $channel "" $ming |
|---|
| 236 | return 0 |
|---|
| 237 | } |
|---|
| 238 | |
|---|
| 239 | if [regexp -nocase "^$botnick (.+)" $text args] { |
|---|
| 240 | if {[matchattr $handle m]} { |
|---|
| 241 | if {$args == "drift"} { |
|---|
| 242 | driftmood |
|---|
| 243 | return 0 |
|---|
| 244 | } |
|---|
| 245 | set moodtype [lindex $args 1] |
|---|
| 246 | set moodsetting [lindex $args 2] |
|---|
| 247 | if {[catch {expr $moodsetting}]} { |
|---|
| 248 | putserv "PRIVMSG $nick :Fewl, that's not right." |
|---|
| 249 | return 0 |
|---|
| 250 | } |
|---|
| 251 | set mood($moodtype) $moodsetting |
|---|
| 252 | putlog "bMotion: Mood($moodtype) changed to $moodsetting by $handle" |
|---|
| 253 | mee $channel "undergoes mood swing" |
|---|
| 254 | return 0 |
|---|
| 255 | } else { |
|---|
| 256 | bMotionDoAction $channel "" "No." |
|---|
| 257 | putlog "bMotion: $nick tried mood $args on $channel and failed." |
|---|
| 258 | return 0 |
|---|
| 259 | } |
|---|
| 260 | } |
|---|
| 261 | checkmood "" "" |
|---|
| 262 | } |
|---|
| 263 | |
|---|
| 264 | #add some default moods |
|---|
| 265 | |
|---|
| 266 | set mood(happy) 0 |
|---|
| 267 | set moodtarget(happy) 0 |
|---|
| 268 | bMotion_mood_add "happy" -30 30 0 1 2 |
|---|
| 269 | |
|---|
| 270 | set mood(horny) 0 |
|---|
| 271 | set moodtarget(horny) 0 |
|---|
| 272 | bMotion_mood_add "horny" -30 30 0 1 2 |
|---|
| 273 | |
|---|
| 274 | set mood(lonely) 0 |
|---|
| 275 | set moodtarget(lonely) 5 |
|---|
| 276 | bMotion_mood_add "lonely" -30 30 5 1 2 |
|---|
| 277 | |
|---|
| 278 | |
|---|
| 279 | set mood(electricity) 2 |
|---|
| 280 | set moodtarget(electricity) 2 |
|---|
| 281 | bMotion_mood_add "electricity" 0 2 2 1 2 |
|---|
| 282 | |
|---|
| 283 | set mood(stoned) 0 |
|---|
| 284 | set moodtarget(stoned) 0 |
|---|
| 285 | bMotion_mood_add "stoned" 0 30 0 1 2 |
|---|
| 286 | |
|---|
| 287 | bMotion_putloglev d * "bMotion: mood module loaded" |
|---|